diff --git a/.gitignore b/.gitignore index cc62e43..eba1dad 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ *.d -*.o \ No newline at end of file +*.o +.DS_Store \ No newline at end of file diff --git a/Makefile b/Makefile index 230be8d..60e6170 100644 --- a/Makefile +++ b/Makefile @@ -1,5 +1,5 @@ # Paths -OPENCV_PATH=/usr/local +OPENCV_PATH=/usr/local/opt/opencv3 # Programs CC= @@ -7,11 +7,11 @@ CXX=g++ # Flags ARCH_FLAGS= -CFLAGS=-Wextra -Wall -pedantic-errors $(ARCH_FLAGS) -O3 -Wno-long-long +CFLAGS=-Wextra -Wall $(ARCH_FLAGS) -O3 -Wno-long-long LDFLAGS=$(ARCH_FLAGS) DEFINES= INCLUDES=-I$(OPENCV_PATH)/include -Iinclude/ -LIBRARIES=-L$(OPENCV_PATH)/lib -lopencv_core -lopencv_highgui -lopencv_imgproc -lopencv_objdetect +LIBRARIES=-L$(OPENCV_PATH)/lib -lopencv_core -lopencv_videoio -lopencv_highgui -lopencv_imgproc -lopencv_objdetect # Files which require compiling SOURCE_FILES=\ diff --git a/include/FaceTracker/IO.h b/include/FaceTracker/IO.h index d9b5715..7771d8e 100644 --- a/include/FaceTracker/IO.h +++ b/include/FaceTracker/IO.h @@ -39,7 +39,7 @@ /////////////////////////////////////////////////////////////////////////////// #ifndef __IO_h_ #define __IO_h_ -#include +#include #include namespace FACETRACKER { diff --git a/license.md b/license.md index bf758ab..99ca18a 100644 --- a/license.md +++ b/license.md @@ -1,14 +1,7 @@ -Summary: FaceTracker is available for non-commercial use only. For commercial use, [request a quote](http://facetracker.net/quote/).The complete license follows. +Copyright 2020, Jason Mora Saragih ---- +Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: -Copyright (C) 2010, Jason Mora Saragih, all rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: +The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. -* The software is provided under the terms of this license strictly for academic, non-commercial, not-for-profit purposes. -* Redistributions of source code must retain the above copyright notice, this list of conditions (license) and the following disclaimer. -* Redistributions in binary form must reproduce the above copyright notice, this list of conditions (license) and the following disclaimer in the documentation and/or other materials provided with the distribution. -* The name of the author may not be used to endorse or promote products derived from this software without specific prior written permission. -* As this software depends on other libraries, the user must adhere to and keep in place any licensing terms of those libraries. -* Any publications arising from the use of this software, including but not limited to academic journal and conference publications, technical reports and manuals, must cite the following work: `J. M. Saragih, S. Lucey, and J. F. Cohn. Face Alignment through Subspace Constrained Mean-Shifts. International Conference of Computer Vision (ICCV), September, 2009.` - -THIS SOFTWARE IS PROVIDED BY THE AUTHOR "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. \ No newline at end of file +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. \ No newline at end of file diff --git a/readme.md b/readme.md index 80fccb1..350f888 100644 --- a/readme.md +++ b/readme.md @@ -1,34 +1,56 @@ # FaceTracker +**This repository is no longer maintained, due to challenges of upgrading to OpenCV 4.** + FaceTracker is a library for deformable face tracking written in C++ using OpenCV 2, authored by [Jason Saragih](http://jsaragih.org/) and maintained by [Kyle McDonald](http://kylemcdonald.net/). -It is available free for non-commercial use, and may be redistributed under these conditions. Please see `license.md` for complete details. For commercial use, [request a quote](http://facetracker.net/quote/). +Any publications arising from the use of this software, including but not limited to academic journal and conference publications, technical reports and manuals, should cite the following work: `J. M. Saragih, S. Lucey, and J. F. Cohn. Face Alignment through Subspace Constrained Mean-Shifts. International Conference of Computer Vision (ICCV), September, 2009.` + +## FAQ + +1. **"I successfully compiled the code, so why is my app is crashing?"** Make sure that your model files are in the right location. If you see the error `Assertion failed: s.is_open()` when running your app, that means you forgot to put the model files in the right directory. +2. **"Is there an example of using FaceTracker on a mobile device?"** There is no official example. But there is an example of using ofxFaceTracker on iOS [here](https://github.com/kylemcdonald/ofxFaceTracker-iOS) and a native Android example [here](https://github.com/ajdroid/facetrackerapp). +3. **"Why is the tracking is slow, and why is there high CPU usage?"** The face detection step (finding the general location of the face) can be slow. If this is causing an issue, you might want to put the tracking in a separate thread. If the detection is very slow you might try using a face detector that is native to your platform, and initializing FaceTracker with that rectangle. +4. **Can I use this for my commercial project/product?** Yes. FaceTracker was re-licensed under the MIT license on April 8, 2020. Previously it was available under a custom non-commercial use license, with a separate license for commercial use available for purchase. Wrappers are available for: +* Android: [facetrackerapp](https://github.com/ajdroid/facetrackerapp) * [openFrameworks](http://www.openframeworks.cc/): [ofxFaceTracker](https://github.com/kylemcdonald/ofxFaceTracker) * [Cinder](http://libcinder.org/): [ciFaceTracker](https://github.com/Hebali/ciFaceTracker) * Python: [pyfacetracker](https://bitbucket.org/amitibo/pyfacetracker) ## Installation -These instructions are for compiling the code on OS X only. Compilation on other Unix-type architectures should be similar. +These instructions are for compiling the code on OS X and Ubuntu, but it should be possible to compile on other platforms. + +First, install OpenCV3 (if you're using OpenCV2, use the [opencv2](https://github.com/kylemcdonald/FaceTracker/tree/opencv2) branch of this repo). On OSX you can use [homebrew](http://brew.sh/): + +``` +$ brew tap homebrew/science +$ brew install opencv3 +``` + +And on Ubuntu use: -1. Download the latest version of OpenCV-2.0 with `git clone git://code.opencv.org/opencv.git` (more instructions [here](http://code.opencv.org/projects/opencv/wiki/Working_with_OpenCV_git_repository)) -2. Follow the OpenCv [installation instructions](http://opencv.willowgarage.com/wiki/Mac_OS_X_OpenCV_Port) and compile and install OpenCV to some arbitrary local directory (usually `/usr/local/`). -3. Clone the FaceTracker code with `git clone git://github.com/kylemcdonald/FaceTracker.git`. This will number of subdirectories within the root directory: +``` +$ sudo apt-get install libcv-dev libopencv-dev +``` + +Alternatively, you can download [OpenCV from the GitHub](https://github.com/opencv/opencv) and compile it manually. + +After installing OpenCV, clone this repository with `git clone git://github.com/kylemcdonald/FaceTracker.git`. This repository contains a few subdirectories within the root directory: - src (contains all source code) - model (contains a pre-trained tracking model) - bin (will contain the executable after building) -4. In the `Makefile` located in the root directory of the FaceTracker code, change the `OPECV_PATH` variable to the directory where OpenCV was installed (by defualt `/usr/local`). Optionally, you can also add `-fopenmp` to the `CFLAGS` and `-lgomp` to `LIBRARIES` to compile with [OpenMP](http://openmp.org/) support. -5. Build the system with `make`. -6. The executable `face_tracker` can be found in the `bin` subdirectory. -To build on Ubuntu Linux you need: +Next, make sure that your copy of OpenCV is located in `/usr/local` (this should be the case if you used `apt-get`). If it isn't located there, modify the `OPENCV_PATH` in the `Makefile`. If you installed with Homebrew, it should be set to `/usr/local/opt/opencv3`. -``` -sudo apt-get install libcv-dev libopencv-dev -``` +Optionally, you can also add `-fopenmp` to the `CFLAGS` and `-lgomp` to the `LIBRARIES` variable to compile with [OpenMP](http://openmp.org/) support. + +From the root `FaceTracker` directory, build the library and example by running `make`. + +To test the demo, `cd bin` and `./face_tracker`. Because many webcams are 1280x720, try running `./face_tracker -s .25` to rescale the image before processing for a smoother framerate. ## `face_tracker` Usage diff --git a/src/exe/face_tracker.cc b/src/exe/face_tracker.cc index 992a1c9..57258cc 100644 --- a/src/exe/face_tracker.cc +++ b/src/exe/face_tracker.cc @@ -174,7 +174,7 @@ int main(int argc, const char** argv) //initialize camera and display window cv::Mat frame,gray,im; double fps=0; char sss[256]; std::string text; - CvCapture* camera = cvCreateCameraCapture(CV_CAP_ANY); if(!camera)return -1; + cv::VideoCapture camera(CV_CAP_ANY); if(!camera.isOpened()) return -1; int64 t1,t0 = cvGetTickCount(); int fnum=0; cvNamedWindow("Face Tracker",1); std::cout << "Hot keys: " << std::endl @@ -185,7 +185,7 @@ int main(int argc, const char** argv) bool failed = true; while(1){ //grab image, resize and flip - IplImage* I = cvQueryFrame(camera); if(!I)continue; frame = I; + camera.read(frame); if(scale == 1)im = frame; else cv::resize(frame,im,cv::Size(scale*frame.cols,scale*frame.rows)); cv::flip(im,im,1); cv::cvtColor(im,gray,CV_BGR2GRAY); diff --git a/src/lib/Patch.cc b/src/lib/Patch.cc index 728eef1..a9f286e 100644 --- a/src/lib/Patch.cc +++ b/src/lib/Patch.cc @@ -38,7 +38,7 @@ // THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. /////////////////////////////////////////////////////////////////////////////// #include -#define SGN(x) (x<0) ? 0:1 +#define SGN(x) ((x) < 0 ? 0 : 1) using namespace FACETRACKER; using namespace std; //===========================================================================