Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Python wrapper for FeatureExtraction #767

Open
wants to merge 27 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
0f2c34c
class OpenfaceVideo and threaded data extraction
frankiezafe Aug 28, 2019
bf3a27d
retrieval of landmarks 3d out of the recorder
frankiezafe Aug 28, 2019
0a7f2d8
compilation of library + python bindings for OpenfaceVideo
frankiezafe Aug 28, 2019
4aabd11
parsing of head pose + frame dump method
frankiezafe Aug 28, 2019
73d7e54
adding flag -fPIC to compile library
frankiezafe Aug 28, 2019
5e7e595
debugging of all methods to enable python binding
frankiezafe Aug 28, 2019
f0f6e03
link to ReVA repo in readme
frankiezafe Aug 28, 2019
c06a425
minor
frankiezafe Aug 28, 2019
f68eb87
adding set_device method in OpenfaceVideo class
frankiezafe Aug 28, 2019
d99fa9e
cmake flags for python 3
frankiezafe Aug 28, 2019
1720f6f
preparation of shared library compilation
frankiezafe Aug 28, 2019
20641a1
modification to cmake to compile a shared library (requires manual ed…
frankiezafe Aug 28, 2019
9325a04
bug fixes in installation scripts
frankiezafe Aug 28, 2019
2f94446
error fix on files removal
frankiezafe Aug 28, 2019
072ea67
fix cmake to ensure compatibility with python 3
frankiezafe Aug 28, 2019
56e48be
upgrading cmake to version 3.15 for native python3 support
frankiezafe Aug 28, 2019
6499462
missing python dev libs + move find python3 to main cmake
frankiezafe Aug 28, 2019
63e50c7
switching to boost 1.17.0 for python3 support
frankiezafe Aug 28, 2019
419ecc2
switching to boost 1.17.0 for python3 support
frankiezafe Aug 28, 2019
dbebf12
clear script
frankiezafe Aug 28, 2019
0c298c4
correct compilation of boost with python3 support
frankiezafe Aug 28, 2019
0c6a18a
fix on c++ class and functional python script
frankiezafe Aug 29, 2019
5d22d21
python script ref
frankiezafe Aug 29, 2019
4a8892d
huge sleep at the end of the script removed
frankiezafe Aug 29, 2019
0ef7a5e
stopping thread is now efficient
frankiezafe Aug 29, 2019
10aecde
info retrieval via callback (much more efficient)
frankiezafe Sep 1, 2019
04c1bc0
clean up
frankiezafe Sep 1, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -105,3 +105,12 @@ lib/local/CppInerop/Debug/

# IDE-generated folders
.idea

4.1.0.zip
dlib-19.13/*
opencv-3.4.0/*
opencv-4.1.0/*
dlib-19.13.tar.bz2
cmake_tmp/*
boost_1_71_0/*
processed/
45 changes: 41 additions & 4 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
cmake_minimum_required (VERSION 3.8)
cmake_minimum_required (VERSION 3.12)
set(CMAKE_CXX_STANDARD 17)

project(OpenFace VERSION 2.0.2)
Expand Down Expand Up @@ -39,7 +39,40 @@ else()
MESSAGE(FATAL_ERROR "OpenCV not found in the system.")
endif()

find_package( Boost 1.5.9 COMPONENTS filesystem system)
find_package(Python3 COMPONENTS Interpreter Development REQUIRED)
if(${Python3_FOUND})
MESSAGE("Python3 information:")
MESSAGE(" Python3_VERSION: ${Python3_VERSION}")
MESSAGE(" Python3_INCLUDE_DIRS: ${Python3_INCLUDE_DIRS}")
MESSAGE(" Python3_LIBRARIES: ${Python3_LIBRARIES}")
MESSAGE(" Python3_LIBRARY_DIRS: ${Python3_LIBRARY_DIRS}")
else()
MESSAGE("Python3 not found in the system.")
endif()

#set(Python_ADDITIONAL_VERSIONS 3.5)
#find_package(PythonLibs 3 REQUIRED)
#if(${PythonLibs_FOUND})
# MESSAGE("PythonLibs information:")
# MESSAGE(" PythonLibs_VERSION: ${PythonLibs_VERSION}")
# MESSAGE(" PythonLibs_INCLUDE_DIRS: ${PythonLibs_INCLUDE_DIRS}")
# MESSAGE(" PythonLibs_LIBRARIES: ${PythonLibs_LIBRARIES}")
# MESSAGE(" PythonLibs_LIBRARY_DIRS: ${PythonLibs_LIBRARY_DIRS}")
#else()
# MESSAGE("PythonLibs not found in the system.")
#endif()
#find_package(PythonInterp 3 REQUIRED)
#if(${PythonInterp_FOUND})
# MESSAGE("PythonInterp information:")
# MESSAGE(" PythonInterp_VERSION: ${PythonInterp_VERSION}")
# MESSAGE(" PythonInterp_INCLUDE_DIRS: ${PythonInterp_INCLUDE_DIRS}")
# MESSAGE(" PythonInterp_LIBRARIES: ${PythonInterp_LIBRARIES}")
# MESSAGE(" PythonInterp_LIBRARY_DIRS: ${PythonInterp_LIBRARY_DIRS}")
#else()
# MESSAGE("PythonInterp not found in the system.")
#endif()

find_package( Boost 1.71.0 COMPONENTS filesystem system thread python REQUIRED)
if(${Boost_FOUND})
MESSAGE("Boost information:")
MESSAGE(" Boost_VERSION: ${Boost_VERSION}")
Expand All @@ -50,7 +83,6 @@ else()
MESSAGE("Boost not found in the system.")
endif()


# Move LandmarkDetector model
file(GLOB files "lib/local/LandmarkDetector/model/*.txt")
foreach(file ${files})
Expand Down Expand Up @@ -149,7 +181,6 @@ find_package(dlib 19.13)
if(${dlib_FOUND})
message("dlib information:")
message(" dlib version: ${dlib_VERSION}")

if (NOT TARGET dlib)
add_library(dlib INTERFACE IMPORTED GLOBAL)
endif()
Expand Down Expand Up @@ -240,8 +271,14 @@ if(CMAKE_CURRENT_SOURCE_DIR STREQUAL "${CMAKE_SOURCE_DIR}")
DESTINATION ${CONFIG_DEST_DIR})
endif()

#get_cmake_property(_variableNames VARIABLES)
#foreach (_variableName ${_variableNames})
# message(STATUS "${_variableName}=${${_variableName}}")
#endforeach()

# executables
add_subdirectory(exe/FaceLandmarkImg)
add_subdirectory(exe/FaceLandmarkVid)
add_subdirectory(exe/FaceLandmarkVidMulti)
add_subdirectory(exe/FeatureExtraction)
add_subdirectory(exe/FeatureExtractionPython)
24 changes: 22 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,27 @@
# OpenFace 2.2.0: a facial behavior analysis toolkit

[![Build Status](https://travis-ci.org/TadasBaltrusaitis/OpenFace.svg?branch=master)](https://travis-ci.org/TadasBaltrusaitis/OpenFace)
[![Build status](https://ci.appveyor.com/api/projects/status/8msiklxfbhlnsmxp/branch/master?svg=true)](https://ci.appveyor.com/project/TadasBaltrusaitis/openface/branch/master)
*Modified version of [original repository](https://github.com/TadasBaltrusaitis/OpenFace) to allow usage of webcam feature extraction from python, developped and tested on Linux Mint 18.2 Cinnamon 64bits.*

part of the [ReVA-toolkit](https://github.com/numediart/ReVA-toolkit)

If it is your first install, just run `install.sh`.

If you need to debug or change configuration, use the scripts below:

- `bash download_models.sh` : download and install models
- `bash prepare.sh` : download all dependencies and install system libs
- `bash compile_deps.sh` : compile boost, opencv & dlib
- `bash compile_openface.sh` : compile openface

For a hard reset of the folder, use `bash clear.sh` to remove boost, opencv, dlib and build folders.

Demo: got to **python_scripts** and launch:

```bash
python3 PyOpenfaceVideo_tester.py
```

## Description

Over the past few years, there has been an increased interest in automatic facial behavior analysis
and understanding. We present OpenFace – a tool intended for computer vision and machine learning
Expand Down
21 changes: 21 additions & 0 deletions clear.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#!/bin/bash

# Exit script if any command fails
set -e
set -o pipefail

if [ $# -ne 0 ]
then
echo "Usage: recompile.sh"
exit 1
fi

rm -rf boost_1_71_0.tar.bz2*
rm -rf 4.1.0.zip*
rm -rf dlib-19.13.tar.bz2*

sudo rm -rf cmake_tmp
sudo rm -rf boost_1_71_0
sudo rm -rf dlib-19.13
sudo rm -rf opencv-4.1.0
sudo rm -rf build
49 changes: 49 additions & 0 deletions compile_deps.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
#!/bin/bash

# Exit script if any command fails
set -e
set -o pipefail

if [ $# -ne 0 ]
then
echo "Usage: compile_deps.sh"
exit 1
fi

# boost 1.71.0 Dependency (https://github.com/zpoint/Boost-Python-Examples)
echo "Installing boost 1.71.0..."
cd boost_1_71_0
echo "using mpi ;
using gcc : : g++ ;
using python : 3.5 : /usr/bin/python3 : /usr/include/python3.5m : /usr/local/lib ;" > ~/user-config.jam
./bootstrap.sh --with-python=/usr/bin/python3 --with-python-version=3.5 --with-python-root=/usr/local/lib/python3.5 --prefix=/usr/local
sudo ./b2 install -a --with=all
sudo ldconfig
cd ..
echo "boost 1.71.0 installed."

# OpenCV Dependency
cd opencv-4.1.0
mkdir -p build
cd build
echo "Installing OpenCV..."
cmake -D CMAKE_BUILD_TYPE=RELEASE -D CMAKE_INSTALL_PREFIX=/usr/local -D WITH_TBB=ON -D WITH_CUDA=OFF -D BUILD_SHARED_LIBS=ON ..
make -j7
sudo make install
cd ../..
sudo ln -s /usr/lib/x86_64-linux-gnu/libboost_python-py35.so /usr/lib/x86_64-linux-gnu/libboost_python3.so
echo "OpenCV installed."

# dlib dependecy
echo "Downloading dlib"
cd dlib-19.13
rm -rf build
mkdir -p build
cd build
echo "Installing dlib"
cmake -D CMAKE_BUILD_TYPE=RELEASE -D DLIB_IN_PROJECT_BUILD=ON -D DLIB_USE_CUDA=OFF -D BUILD_SHARED_LIBS=ON ..
make -j4
sudo make install
sudo ldconfig
cd ../..
echo "dlib installed"
23 changes: 23 additions & 0 deletions compile_openface.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#!/bin/bash

# Exit script if any command fails
set -e
set -o pipefail

if [ $# -ne 0 ]
then
echo "Usage: compile_openface.sh"
exit 1
fi

# OpenFace installation
echo "Installing OpenFace..."
mkdir -p build
cd build
cmake -D CMAKE_CXX_COMPILER=g++-8 -D CMAKE_C_COMPILER=gcc-8 -D CMAKE_BUILD_TYPE=RELEASE ..
make
# copying models in FeatureExtractionPython folder
cp -r bin/model/ exe/FeatureExtractionPython/model/
mkdir -p exe/FeatureExtractionPython/classifiers/
cp ../lib/3rdParty/OpenCV/classifiers/haarcascade_frontalface_alt.xml exe/FeatureExtractionPython/classifiers/
echo "OpenFace successfully installed."
Empty file modified download_models.sh
100644 → 100755
Empty file.
26 changes: 26 additions & 0 deletions exe/FeatureExtractionPython/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# Local libraries
include_directories(${Python3_INCLUDE_DIRS})
link_directories(${Python3_LIBRARIES})
include_directories(${LandmarkDetector_SOURCE_DIR}/include)

# EXEC
#add_executable(OpenfaceVideo FeatureExtractionPython.cpp)
#target_link_libraries(OpenfaceVideo LandmarkDetector)
#target_link_libraries(OpenfaceVideo FaceAnalyser)
#target_link_libraries(OpenfaceVideo GazeAnalyser)
#target_link_libraries(OpenfaceVideo Utilities)
#target_link_libraries(OpenfaceVideo ${Boost_LIBRARIES})
#target_link_libraries(OpenfaceVideo ${Python3_LIBRARIES})
#install (TARGETS OpenfaceVideo DESTINATION bin)

# LIBRARY
add_library(PyOpenfaceVideo SHARED FeatureExtractionPython.cpp)
# set_property(TARGET PyOpenfaceVideo PROPERTY POSITION_INDEPENDENT_CODE ON)
target_link_libraries(PyOpenfaceVideo LandmarkDetector)
target_link_libraries(PyOpenfaceVideo FaceAnalyser)
target_link_libraries(PyOpenfaceVideo GazeAnalyser)
target_link_libraries(PyOpenfaceVideo Utilities)
target_link_libraries(PyOpenfaceVideo ${Boost_LIBRARIES})
target_link_libraries(PyOpenfaceVideo ${Python3_LIBRARIES})
set_target_properties(PyOpenfaceVideo PROPERTIES PREFIX "")
install (TARGETS PyOpenfaceVideo DESTINATION bin)
Loading