How to install pyFaceTracker on linux (Fedora 19)
pyFaceTracker is a Python wrapper for the OpenCV FaceTracker library. It can be downloaded at (https://pypi.python.org/pypi/pyFaceTracker/0.1.1) and the documentation for it is (http://pythonhosted.org/pyFaceTracker/).
The installation details are pretty straightforward for pyFaceTracker.
To install pyfacetracker you will need the following prerequisites:
python (tested on version 2.73)
OpenCV library (tested on version 2.49 but should work on any version using the C++ interface)
C++ compiler (tested on MSVC 2008)
To run the examples you will need also:
Download the source files of pycompsense. Then, execute:
$ python setup.py install
You can test the installation by running the examples under the folder examples/
You can use YUM to install opencv and all its dependencies (http://docs.opencv.org/doc/tutorials/introduction/linux_install/linux_install.html). However the pyFaceTracker wrapper setup script is designed to be run on a windows machine. It fails if you try to run it on linux. So lets try to update the setup.py script to get it working correctly.
Here’s what the final updated script looks like. The updated sections are highlighted. I’ll go through each of the changed sections afterwards and explain how you can find the values that your own system expects.
Get the updated for linux setup.py here.
from setuptools import setup
from setuptools.extension import Extension
import numpy as np
import os
NAME = 'pyFaceTracker'
PACKAGE_NAME = 'facetracker'
VERSION = '0.1.1'
DESCRIPTION = 'A python wrapper for the FaceTracker library by Jason Mora Saragih'
LONG_DESCRIPTION = """
pyfacetracker is a thin wrapper around FaceTracker. It enables using
FaceTracker while enjoyging the comfort of the Python scripting language.
FaceTracker is a library for deformable face tracking written in C++ using
OpenCV 2, authored by Jason Saragih and maintained by Kyle McDonald.
"""
AUTHOR = 'Amit Aides'
EMAIL = '[email protected]'
URL = 'https://bitbucket.org/amitibo/pyfacetracker'
KEYWORDS = ["Face Tracking", "Image Processing", "Video Processing"]
LICENSE = 'See separate LICENSE file'
CLASSIFIERS = [
'License :: Other/Proprietary License',
'Development Status :: 3 - Alpha',
'Topic :: Scientific/Engineering'
]
OPENCV_BASE = '/usr/include/opencv2'
OPENCV_LIB_DIRS=['/usr/lib64']
OPENCV_VERSION = '.so.2.4.6'
FACETRACKER_BASE = 'external/FaceTracker'
OPENCV_INCLUDE_DIRS = [
OPENCV_BASE + p for p in (
'/core',
'/imgproc',
'/video',
'/features2d',
'/flann',
'/calib3d',
'/objdetect',
'/legacy'
)
]
OPENCV_LIBS=[
l % OPENCV_VERSION for l in (
'libopencv_core%s',
'libopencv_imgproc%s',
'libopencv_calib3d%s',
'libopencv_video%s',
'libopencv_features2d%s',
'libopencv_ml%s',
'libopencv_highgui%s',
'libopencv_objdetect%s',
'libopencv_contrib%s',
'libopencv_legacy%s'
)
]
def main():
setup(
name=NAME,
version=VERSION,
description=DESCRIPTION,
long_description=LONG_DESCRIPTION,
author=AUTHOR,
author_email=EMAIL,
url=URL,
keywords=KEYWORDS,
classifiers=CLASSIFIERS,
license=LICENSE,
packages=[PACKAGE_NAME],
ext_modules = [
Extension(
PACKAGE_NAME + '.' + "_facetracker",
[os.path.join(FACETRACKER_BASE, f) for f in
(
"src/lib/PDM.cc",
"src/lib/PAW.cc",
"src/lib/Patch.cc",
"src/lib/IO.cc",
"src/lib/FDet.cc",
"src/lib/FCheck.cc",
"src/lib/CLM.cc",
"src/lib/Tracker.cc"
)
] + ["src/_pyFaceTracker.cpp"],
include_dirs=[os.path.join(FACETRACKER_BASE, 'include')] + OPENCV_INCLUDE_DIRS + [np.get_include()],
libraries=OPENCV_LIBS,
library_dirs=OPENCV_LIB_DIRS,
#extra_compile_args=['/EHsc']
)
]
)
if __name__ == '__main__':
main()
First we want to update the OPENCV_BASE variable to point correctly.
To find the location of our opencv files (this tutorial assumes you have successfully installed opencv) run the following command.
Note that we actually want to point to the opencv2 library base directory “/usr/include/opencv2″.
Next we need to update the directory where some opencv libraries are located. Go back to the list generated by the find command and look for the directory that contains all the library files similar to “libopencv_core” or “libopencv_ml” (don’t worry about version number). In my case it was “/usr/lib64″.
The OPENCV_VERSION variable is mainly just used to tack the version on to all the library filenames. Refer to the list generated by find to get the correct value.
Fix the FACETRACKER_BASE by using the forward slash instead of a backslash.
OPENCV_INCLUDE_DIRS point to module directories that reside within the opencv2 base directory (/usr/include/opencv2).
For OPENCV_LIBS note that you need to update these filenames as they are prefixed with “lib” in linux.
Note: If you get an error like “/bin/ld: cannot find -llibopencv_core.so.2.4.6″ that crashes the build, take the following steps to make sure the ld command is looking in the right place for your libraries.
Run the ld command in verbose mode to see where it is looking for your library file.
ld -llibopencv_core.so.2.4.6 --verbose
You will get output that includes something like this:
attempt to open /usr/x86_64-redhat-linux/lib64/liblibopencv_core.so.2.4.6.so failed
attempt to open /usr/x86_64-redhat-linux/lib64/liblibopencv_core.so.2.4.6.a failed
attempt to open /usr/local/lib64/liblibopencv_core.so.2.4.6.so failed
attempt to open /usr/local/lib64/liblibopencv_core.so.2.4.6.a failed
attempt to open /lib64/liblibopencv_core.so.2.4.6.so failed
attempt to open /lib64/liblibopencv_core.so.2.4.6.a failed
attempt to open /usr/lib64/liblibopencv_core.so.2.4.6.so failed
attempt to open /usr/lib64/liblibopencv_core.so.2.4.6.a failed
attempt to open /usr/x86_64-redhat-linux/lib/liblibopencv_core.so.2.4.6.so failed
attempt to open /usr/x86_64-redhat-linux/lib/liblibopencv_core.so.2.4.6.a failed
attempt to open /usr/lib64/liblibopencv_core.so.2.4.6.so failed
attempt to open /usr/lib64/liblibopencv_core.so.2.4.6.a failed
attempt to open /usr/local/lib/liblibopencv_core.so.2.4.6.so failed
attempt to open /usr/local/lib/liblibopencv_core.so.2.4.6.a failed
attempt to open /lib/liblibopencv_core.so.2.4.6.so failed
attempt to open /lib/liblibopencv_core.so.2.4.6.a failed
attempt to open /usr/lib/liblibopencv_core.so.2.4.6.so failed
attempt to open /usr/lib/liblibopencv_core.so.2.4.6.a failed
Notice that none of those paths actually match up with our library’s path which is actually located at
/usr/lib64/libopencv_core.so.2.4.6 (remember you can use the find command we used above to find this).
So what we will do, is just grab the most similar looking “ld attempt” path and link it symbolically to point towards our actual file (I bolded the one I picked in the output above).
ln -s /usr/lib64/libopencv_core.so.2.4.6 /usr/lib64/liblibopencv_core.so.2.4.6.so
Note that you will have to do this with each library that ld fails to find (perhaps all 10 libraries but hopefully not).
Lastly comment out this line “extra_compile_args=['/EHsc']” as this flag is particular to windows compiler.
Go ahead and run the build
Make sure you update the example scripts!
All of the example scripts use backslashes since Amit Aides the wrapper author wrote it for windows. Make sure you update all the example files with forward slashes to work in linux.
Thanks to Amit Aides for building this python wrapper for FaceTracker. Please don’t hesitate to shoot me an email if you are having any difficulty.
Lastly, here is the example linux compatible face_image.py:
from __future__ import division import numpy as np import facetracker import matplotlib.pyplot as plt from mpl_toolkits.mplot3d import Axes3D #import Image import cv2 import argparse def main(img_path): # # Load image # img = img = cv2.imread(img_path,0) gray = img = cv2.imread(img_path,0) img = np.asanyarray(img) gray = np.asarray(gray) # # Load face model # conns = facetracker.LoadCon('../external/FaceTracker/model/face.con') trigs = facetracker.LoadTri('../external/FaceTracker/model/face.tri') tracker = facetracker.FaceTracker('../external/FaceTracker/model/face.tracker') # # Search for faces in the image # tracker.setWindowSizes((11, 9, 7)) if tracker.update(gray): img = tracker.draw(img, conns, trigs) obj3D = tracker.get3DShape() fig3d = plt.figure() ax = fig3d.add_subplot(111, projection='3d') ax.scatter(obj3D[:66, 0], obj3D[66:132, 0], obj3D[132:, 0]) for i in range(66): ax.text(obj3D[i], obj3D[i+66], obj3D[i+132], str(i)) ax.view_init(-90, -90) else: print 'Failed tracking face in image' plt.figure() plt.imshow(img) plt.show() if __name__ == '__main__': parser = argparse.ArgumentParser(description='Run pyfacetrack on an image') parser.add_argument('path', help='Path to image', default=None) args = parser.parse_args() main(args.path)