diff --git a/CMakeLists.txt b/CMakeLists.txt index 9d42df8..3d53bc6 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -5,6 +5,10 @@ set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin/) set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/cmake/modules/") +set(CMAKE_CONFIG_DIR etc/OpenFace) +set(CONFIG_DIR "${CMAKE_INSTALL_PREFIX}/${CMAKE_CONFIG_DIR}") +add_definitions(-DCONFIG_DIR="${CONFIG_DIR}") + find_package( OpenCV REQUIRED ) MESSAGE("OpenCV information:") @@ -34,6 +38,8 @@ foreach(file ${files}) else(MSVC) file(COPY ${file} DESTINATION ${CMAKE_BINARY_DIR}/bin/model) endif(MSVC) + + install(FILES ${file} DESTINATION ${CMAKE_CONFIG_DIR}/model) endforeach() # Move the hierarchical LandmarkDetector models @@ -45,6 +51,8 @@ foreach(file ${files}) else(MSVC) file(COPY ${file} DESTINATION ${CMAKE_BINARY_DIR}/bin/model) endif(MSVC) + + install(DIRECTORY ${file} DESTINATION ${CMAKE_CONFIG_DIR}/model) endforeach() file(GLOB files "lib/local/LandmarkDetector/model/detection_validation/*.txt") @@ -55,6 +63,8 @@ foreach(file ${files}) else(MSVC) file(COPY ${file} DESTINATION ${CMAKE_BINARY_DIR}/bin/model/detection_validation) endif(MSVC) + + install(FILES ${file} DESTINATION ${CMAKE_CONFIG_DIR}/model/detection_validation) endforeach() file(GLOB files "lib/local/LandmarkDetector/model/patch_experts/*.txt") @@ -65,6 +75,8 @@ foreach(file ${files}) else(MSVC) file(COPY ${file} DESTINATION ${CMAKE_BINARY_DIR}/bin/model/patch_experts) endif(MSVC) + + install(FILES ${file} DESTINATION ${CMAKE_CONFIG_DIR}/model/patch_experts) endforeach() file(GLOB files "lib/local/LandmarkDetector/model/pdms/*.txt") @@ -75,6 +87,8 @@ foreach(file ${files}) else(MSVC) file(COPY ${file} DESTINATION ${CMAKE_BINARY_DIR}/bin/model/pdms) endif(MSVC) + + install(FILES ${file} DESTINATION ${CMAKE_CONFIG_DIR}/model/pdms) endforeach() # Move OpenCV classifiers @@ -86,6 +100,8 @@ foreach(file ${files}) else(MSVC) file(COPY ${file} DESTINATION ${CMAKE_BINARY_DIR}/bin/classifiers) endif(MSVC) + + install(FILES ${file} DESTINATION ${CMAKE_CONFIG_DIR}/classifiers) endforeach() # Move AU prediction modules @@ -97,6 +113,8 @@ foreach(file ${files}) else(MSVC) file(COPY ${file} DESTINATION ${CMAKE_BINARY_DIR}/bin/AU_predictors) endif(MSVC) + + install(FILES ${file} DESTINATION ${CMAKE_CONFIG_DIR}/AU_predictors) endforeach() # Move AU prediction modules @@ -108,6 +126,8 @@ foreach(file ${files}) else(MSVC) file(COPY ${file} DESTINATION ${CMAKE_BINARY_DIR}/bin/AU_predictors) endif(MSVC) + + install(DIRECTORY ${file} DESTINATION ${CMAKE_CONFIG_DIR}/AU_predictors) endforeach() # Move AU prediction modules @@ -119,6 +139,8 @@ foreach(file ${files}) else(MSVC) file(COPY ${file} DESTINATION ${CMAKE_BINARY_DIR}/bin/AU_predictors) endif(MSVC) + + install(DIRECTORY ${file} DESTINATION ${CMAKE_CONFIG_DIR}/AU_predictors) endforeach() if (${CMAKE_CXX_COMPILER_ID} STREQUAL "GNU") diff --git a/exe/FaceLandmarkImg/FaceLandmarkImg.cpp b/exe/FaceLandmarkImg/FaceLandmarkImg.cpp index 718d3ec..bf9f716 100644 --- a/exe/FaceLandmarkImg/FaceLandmarkImg.cpp +++ b/exe/FaceLandmarkImg/FaceLandmarkImg.cpp @@ -78,6 +78,10 @@ #include #include +#ifndef CONFIG_DIR +#define CONFIG_DIR "~" +#endif + using namespace std; vector get_arguments(int argc, char **argv) @@ -317,6 +321,10 @@ int main (int argc, char **argv) //Convert arguments to more convenient vector form vector arguments = get_arguments(argc, argv); + // Search paths + boost::filesystem::path config_path = boost::filesystem::path(CONFIG_DIR); + boost::filesystem::path parent_path = boost::filesystem::path(arguments[0]).parent_path(); + // Some initial parameters that can be overriden from command line vector files, depth_files, output_images, output_landmark_locations, output_pose_locations; @@ -356,38 +364,44 @@ int main (int argc, char **argv) // Loading the AU prediction models string au_loc = "AU_predictors/AU_all_static.txt"; - if (!boost::filesystem::exists(boost::filesystem::path(au_loc))) + boost::filesystem::path au_loc_path = boost::filesystem::path(au_loc); + if (boost::filesystem::exists(au_loc_path)) { - boost::filesystem::path loc = boost::filesystem::path(arguments[0]).parent_path() / au_loc; - - if (boost::filesystem::exists(loc)) - { - au_loc = loc.string(); - } - else - { - cout << "Can't find AU prediction files, exiting" << endl; - return 1; - } + au_loc = au_loc_path.string(); + } + else if (boost::filesystem::exists(parent_path/au_loc_path)) + { + au_loc = (parent_path/au_loc_path).string(); + } + else if (boost::filesystem::exists(config_path/au_loc_path)) + { + au_loc = (config_path/au_loc_path).string(); + } + else + { + cout << "Can't find AU prediction files, exiting" << endl; + return 1; } // Used for image masking for AUs string tri_loc; - if (boost::filesystem::exists(boost::filesystem::path("model/tris_68_full.txt"))) + boost::filesystem::path tri_loc_path = boost::filesystem::path("model/tris_68_full.txt"); + if (boost::filesystem::exists(tri_loc_path)) { - std::ifstream triangulation_file("model/tris_68_full.txt"); - tri_loc = "model/tris_68_full.txt"; + tri_loc = tri_loc_path.string(); + } + else if (boost::filesystem::exists(parent_path/tri_loc_path)) + { + tri_loc = (parent_path/tri_loc_path).string(); + } + else if (boost::filesystem::exists(config_path/tri_loc_path)) + { + tri_loc = (config_path/tri_loc_path).string(); } else { - boost::filesystem::path loc = boost::filesystem::path(arguments[0]).parent_path() / "model/tris_68_full.txt"; - tri_loc = loc.string(); - - if (!exists(loc)) - { - cout << "Can't find triangulation files, exiting" << endl; - return 1; - } + cout << "Can't find triangulation files, exiting" << endl; + return 1; } FaceAnalysis::FaceAnalyser face_analyser(vector(), 0.7, 112, 112, au_loc, tri_loc); diff --git a/exe/FeatureExtraction/CMakeLists.txt b/exe/FeatureExtraction/CMakeLists.txt index 3c56149..5d6d72d 100644 --- a/exe/FeatureExtraction/CMakeLists.txt +++ b/exe/FeatureExtraction/CMakeLists.txt @@ -14,3 +14,5 @@ target_link_libraries(FeatureExtraction FaceAnalyser) target_link_libraries(FeatureExtraction dlib) target_link_libraries(FeatureExtraction ${OpenCV_LIBS} ${Boost_LIBRARIES} ${TBB_LIBRARIES}) + +install (TARGETS FeatureExtraction DESTINATION bin) diff --git a/exe/FeatureExtraction/FeatureExtraction.cpp b/exe/FeatureExtraction/FeatureExtraction.cpp index c72d611..1e8fbf9 100644 --- a/exe/FeatureExtraction/FeatureExtraction.cpp +++ b/exe/FeatureExtraction/FeatureExtraction.cpp @@ -81,6 +81,9 @@ #include #include +#ifndef CONFIG_DIR +#define CONFIG_DIR "~" +#endif #define INFO_STREAM( stream ) \ std::cout << stream << std::endl @@ -242,6 +245,10 @@ int main (int argc, char **argv) vector arguments = get_arguments(argc, argv); + // Search paths + boost::filesystem::path config_path = boost::filesystem::path(CONFIG_DIR); + boost::filesystem::path parent_path = boost::filesystem::path(arguments[0]).parent_path(); + // Some initial parameters that can be overriden from command line vector input_files, depth_directories, output_files, tracked_videos_output; @@ -322,23 +329,25 @@ int main (int argc, char **argv) output_2D_landmarks, output_3D_landmarks, output_model_params, output_pose, output_AUs, output_gaze, arguments); // Used for image masking - string tri_loc; - if(boost::filesystem::exists(path("model/tris_68_full.txt"))) + boost::filesystem::path tri_loc_path = boost::filesystem::path("model/tris_68_full.txt"); + if (boost::filesystem::exists(tri_loc_path)) { - tri_loc = "model/tris_68_full.txt"; + tri_loc = tri_loc_path.string(); + } + else if (boost::filesystem::exists(parent_path/tri_loc_path)) + { + tri_loc = (parent_path/tri_loc_path).string(); + } + else if (boost::filesystem::exists(config_path/tri_loc_path)) + { + tri_loc = (config_path/tri_loc_path).string(); } else { - path loc = path(arguments[0]).parent_path() / "model/tris_68_full.txt"; - tri_loc = loc.string(); - - if(!exists(loc)) - { - cout << "Can't find triangulation files, exiting" << endl; - return 1; - } - } + cout << "Can't find triangulation files, exiting" << endl; + return 1; + } // Will warp to scaled mean shape cv::Mat_ similarity_normalised_shape = face_model.pdm.mean_shape * sim_scale; @@ -362,24 +371,24 @@ int main (int argc, char **argv) au_loc_local = "AU_predictors/AU_all_static.txt"; } - if(boost::filesystem::exists(path(au_loc_local))) + boost::filesystem::path au_loc_path = boost::filesystem::path(au_loc_local); + if (boost::filesystem::exists(au_loc_path)) { - au_loc = au_loc_local; + au_loc = au_loc_path.string(); + } + else if (boost::filesystem::exists(parent_path/au_loc_path)) + { + au_loc = (parent_path/au_loc_path).string(); + } + else if (boost::filesystem::exists(config_path/au_loc_path)) + { + au_loc = (config_path/au_loc_path).string(); } else { - path loc = path(arguments[0]).parent_path() / au_loc_local; - - if(exists(loc)) - { - au_loc = loc.string(); - } - else - { - cout << "Can't find AU prediction files, exiting" << endl; - return 1; - } - } + cout << "Can't find AU prediction files, exiting" << endl; + return 1; + } // Creating a face analyser that will be used for AU extraction FaceAnalysis::FaceAnalyser face_analyser(vector(), 0.7, 112, 112, au_loc, tri_loc); diff --git a/lib/local/FaceAnalyser/CMakeLists.txt b/lib/local/FaceAnalyser/CMakeLists.txt index ce33450..1652e9a 100644 --- a/lib/local/FaceAnalyser/CMakeLists.txt +++ b/lib/local/FaceAnalyser/CMakeLists.txt @@ -29,5 +29,5 @@ include_directories(../LandmarkDetector/include) add_library( FaceAnalyser ${SOURCE} ${HEADERS}) -install (TARGETS FaceAnalyser DESTINATION bin) -install (FILES ${HEADERS} DESTINATION include) +install (TARGETS FaceAnalyser DESTINATION lib) +install (FILES ${HEADERS} DESTINATION include/OpenFace) diff --git a/lib/local/LandmarkDetector/CMakeLists.txt b/lib/local/LandmarkDetector/CMakeLists.txt index a5e1a50..9d5055c 100644 --- a/lib/local/LandmarkDetector/CMakeLists.txt +++ b/lib/local/LandmarkDetector/CMakeLists.txt @@ -35,7 +35,7 @@ SET(HEADERS include_directories(./include) include_directories(${LandmarkDetector_SOURCE_DIR}/include) -add_library( LandmarkDetector ${SOURCE} ${HEADERS}) +add_library( LandmarkDetector ${SOURCE} ${HEADERS} ) -install (TARGETS LandmarkDetector DESTINATION bin) -install (FILES ${HEADERS} DESTINATION include) +install (TARGETS LandmarkDetector DESTINATION lib) +install (FILES ${HEADERS} DESTINATION include/OpenFace) diff --git a/lib/local/LandmarkDetector/src/LandmarkDetectorParameters.cpp b/lib/local/LandmarkDetector/src/LandmarkDetectorParameters.cpp index c0e74a3..90ac398 100644 --- a/lib/local/LandmarkDetector/src/LandmarkDetectorParameters.cpp +++ b/lib/local/LandmarkDetector/src/LandmarkDetectorParameters.cpp @@ -67,6 +67,11 @@ // System includes #include #include +#include + +#ifndef CONFIG_DIR +#define CONFIG_DIR "~" +#endif using namespace std; @@ -200,15 +205,25 @@ FaceModelParameters::FaceModelParameters(vector &arguments) } // Make sure model_location is valid - if (!boost::filesystem::exists(boost::filesystem::path(model_location))) + // First check working directory, then the executable's directory, then the config path set by the build process. + boost::filesystem::path config_path = boost::filesystem::path(CONFIG_DIR); + boost::filesystem::path model_path = boost::filesystem::path(model_location); + if (boost::filesystem::exists(model_path)) { - model_location = (root / model_location).string(); - if (!boost::filesystem::exists(boost::filesystem::path(model_location))) - { - std::cout << "Could not find the landmark detection model to load" << std::endl; - } + model_location = model_path.string(); + } + else if (boost::filesystem::exists(root/model_path)) + { + model_location = (root/model_path).string(); + } + else if (boost::filesystem::exists(config_path/model_path)) + { + model_location = (config_path/model_path).string(); + } + else + { + std::cout << "Could not find the landmark detection model to load" << std::endl; } - } void FaceModelParameters::init()