diff --git a/.gitignore b/.gitignore index 4686482..1c65011 100644 --- a/.gitignore +++ b/.gitignore @@ -16,4 +16,5 @@ build/* config.log config.status .DS_Store -*~ \ No newline at end of file +*~ +/_build* diff --git a/CMakeLists.txt b/CMakeLists.txt index 9d66373..0d96ae0 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -5,25 +5,29 @@ cmake_minimum_required(VERSION 2.8) #set(CMAKE_VERBOSE_MAKEFILE true) -# Default values for options -if(NOT DEFINED OpenCV_PREFIX) - set(OpenCV_PREFIX ${CMAKE_INSTALL_PREFIX}) -endif() - # Configurable options OPTION(WITH_GUI "Build the GUI" OFF) + # Third party libraries -find_package(OpenCV REQUIRED core highgui imgproc objdetect - PATHS ${OpenCV_PREFIX}/lib/cmake/ - ${OpenCV_PREFIX}/share/OpenCV/ - NO_DEFAULT_PATH) # For some reason CMake uses its defaults before the above paths. +find_package(OpenCV REQUIRED core highgui imgproc objdetect) IF(APPLE) -find_library(FOUNDATION Foundation) -SET(EXTRA_LIBS ${FOUNDATION}) + find_library(FOUNDATION Foundation) + SET(EXTRA_LIBS ${FOUNDATION}) ENDIF() +IF(UNIX AND NOT APPLE) + FIND_PROGRAM(HAVE_GNUSTEP NAMES gnustep-config) + IF(HAVE_GNUSTEP) + SET(WITH_GUI "Build the GUI" ON) + MESSAGE(STATUS "Found GnuStep") + ELSE(HAVE_GNUSTEP) + MESSAGE(STATUS "Cannot find GnuStep") + ENDIF(HAVE_GNUSTEP) +ENDIF(UNIX AND NOT APPLE) + + # Third party programs if(NOT DEFINED FFMPEG) find_program(FFMPEG ffmpeg) @@ -46,23 +50,28 @@ endif() SET(CMAKE_BUILD_TYPE Release CACHE STRING "") # - flags -SET(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS} -g -O0 -Wall -Wextra -DDEBUG") -SET(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS} -O0 -g -Wall -Wextra -DDEBUG") +if(NOT WIN32) + SET(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS} -g -O0 -Wall -Wextra -DDEBUG") + SET(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS} -O0 -g -Wall -Wextra -DDEBUG") -SET(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS} -O3 -Wall -Wextra") -SET(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS} -Wall -O3 -Wextra") + SET(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS} -O3 -Wall -Wextra") + SET(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS} -Wall -O3 -Wextra") +endif() SET(LIBS ${OpenCV_LIBS} ${EXTRA_LIBS}) +INCLUDE_DIRECTORIES(${OpenCV_INCLUDE_DIRS}) # Build paths SET(CMAKE_LIBRARY_OUTPUT_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/lib") -#SET(CMAKE_ARCHIVE_OUTPUT_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/lib") +SET(CMAKE_ARCHIVE_OUTPUT_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/lib") SET(CMAKE_RUNTIME_OUTPUT_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/bin") # Include directories INCLUDE_DIRECTORIES("src/") INCLUDE_DIRECTORIES("src/avatar/") INCLUDE_DIRECTORIES("${CMAKE_CURRENT_BINARY_DIR}/src/") +INCLUDE_DIRECTORIES(OpenCV_INCLUDE_DIRS) + # Subdirectories with CMakeLists.txt ADD_SUBDIRECTORY(src/utils) @@ -79,6 +88,9 @@ ADD_SUBDIRECTORY(src/display-tracking) ADD_SUBDIRECTORY(src/create-avatar-model) ADD_SUBDIRECTORY(src/display-3d-points) +# install(EXPORT CSIRO DESTINATION ${CMAKE_INSTALL_PREFIX}) +install(FILES src/CSIROConfig.cmake DESTINATION "${CMAKE_INSTALL_PREFIX}") + IF(WITH_GUI) SET(CPACK_PACKAGE_NAME "clm") SET(CPACK_PACKAGE_VENDOR "CI2CV-CSIRO ci2cv.net") @@ -91,7 +103,9 @@ IF(WITH_GUI) SET(CPACK_BINARY_PACKAGEMAKER OFF) SET(CPACK_SOURCE_TGZ OFF) ADD_SUBDIRECTORY(src/qt-gui) + MESSAGE(STATUS "Will build the GUI") +else() + MESSAGE(STATUS "Missing GUI components - will NOT build the GUI") endif() #cpack stuff goes here - diff --git a/INSTALL.md b/INSTALL.md new file mode 100644 index 0000000..93e2ea3 --- /dev/null +++ b/INSTALL.md @@ -0,0 +1,39 @@ +Make sure you have Bash, Cmake, Git, FFmpeg and OpenCV installed. + +If you're on Ubuntu, this should be enough: + +```sh + # this installs a prebuilt opencv with python bindings along with some other tools + sudo apt-get install -y \ + git \ + pkg-config \ + build-essential \ + cmake \ + libopencv-dev \ + python-opencv \ + ffmpeg +``` + +Otherwise check: + +* http://milq.github.io/install-opencv-ubuntu-debian/ +* http://docs.opencv.org/2.4/doc/tutorials/introduction/linux_install/linux_install.html +* http://askubuntu.com/questions/432542/is-ffmpeg-missing-from-the-official-repositories-in-14-04 +* https://help.ubuntu.com/community/OpenCV + +After you have all the dependencies, the build is simple: + +```sh +# assuming you installed from libopencv-dev in ubuntu/debian +# if not, look for the directory that contains OpenCVConfig.cmake +path_to_opencv=$(dpkg --listfiles libopencv-dev | grep --max-count=1 'OpenCVConfig.cmake$') + +git clone https://github.com/MatrixAI/face-analysis-sdk +pushd face-analysis-sdk + mkdir -p build + pushd build + cmake -DOpenCV_DIR="$path_to_opencv" -DFFMPEG=$(which ffmpeg) -DBASH=$(which bash) .. + make + popd +popd +``` diff --git a/README b/README deleted file mode 100644 index 44c1004..0000000 --- a/README +++ /dev/null @@ -1,20 +0,0 @@ -Welcome to the CSIRO Face Analysis SDK. Documentation for the SDK can -be found in doc/documentation.html. - -All code in this SDK is provided according to the license found in -LICENSE. - -If you use the CSIRO Face Analysis SDK in any publications, we ask -that you reference our works. - -The face tracking component is based on the publication: -J. Saragih, S. Lucey and J. Cohn, "Deformable Model Fitting by -Regularized Landmark Mean-Shift", IJCV 2011. - -The expression transfer component is based on the publication: -J. Saragih, S. Lucey and J. Cohn, "Real-time Avatar Animation from a -Single Image", AFGR Workshop 2011. - -If you use the SDK, we ask that you reference the following paper: -M. Cox, J. Nuevo, J. Saragih and S. Lucey, "CSIRO Face Analysis SDK", -AFGR 2013. \ No newline at end of file diff --git a/README.md b/README.md new file mode 100644 index 0000000..6a78a61 --- /dev/null +++ b/README.md @@ -0,0 +1,32 @@ +Welcome to the CSIRO Face Analysis SDK. Documentation for the SDK can +be found in doc/documentation.html. + +All code in this SDK is provided according to the license found in +LICENSE. + +If you use the CSIRO Face Analysis SDK in any publications, we ask +that you reference our works. + +The face tracking component is based on the publication: +J. Saragih, S. Lucey and J. Cohn, "Deformable Model Fitting by +Regularized Landmark Mean-Shift", IJCV 2011. + +The expression transfer component is based on the publication: +J. Saragih, S. Lucey and J. Cohn, "Real-time Avatar Animation from a +Single Image", AFGR Workshop 2011. + +If you use the SDK, we ask that you reference the following paper: +M. Cox, J. Nuevo, J. Saragih and S. Lucey, "CSIRO Face Analysis SDK", +AFGR 2013. + +--- + +Here are the updates in the original code included in this fork of the project: + +- The dependency of Qt in the qt-gui project was upgraded from Qt4 to Qt5. +- Some OpenCV missing includes were added (perhaps they are due to changes in version used). +- The type casts were made explicit to remove related warning messages. +- Some static array allocations were replaced with the operator `new[]`. +- The Windows/POSIX-specific function calls were enclosed in `#ifdefs` based on the operating system defined at compilation time, and the the best corresponding functions were used for Windows (for instance: `PathRemoveFileSpec` and `PathStripPath` respectively replaced `dirname` and `basename` in Windows). +- The class `ForkRunner` was completely replaced in Windows by the implementation proposed by Ben Howell [here](http://www.benhowell.net/guide/2015/03/16/porting-face-analysis-sdk-to-windows/). Although, [there is no direct equivalent of `fork` (used by the original class) on Windows](http://stackoverflow.com/a/9148072/2896619) and [`CreateProcess` does not have the same behaviour](http://stackoverflow.com/q/985281/2896619) (further tests required). +- The libraries `utilities`, `clmTracker` and `avatarAnim`, that were originally created as shared libraries, were transformed into static libraries only for the Windows configuration. This was just simpler to do at this time, because the use of the `__declspec(dllexport)` directive (to export the functions/classes to be usable through a DLL) was causing problems related to third part objects not being equally exported (for instance, in some classes/functions, the compiler was producing messages like: "warning C4251: class 'cv::Mat' needs to have dll-interface to be used by clients of class "). diff --git a/src/CSIROConfig.cmake b/src/CSIROConfig.cmake new file mode 100644 index 0000000..35ca7e0 --- /dev/null +++ b/src/CSIROConfig.cmake @@ -0,0 +1,2 @@ +set(CSIRO_INCLUDE_DIRS "${CMAKE_CURRENT_LIST_DIR}/include") +include("${CMAKE_CURRENT_LIST_DIR}/CSIRO.cmake") \ No newline at end of file diff --git a/src/avatar/CMakeLists.txt b/src/avatar/CMakeLists.txt index 6bccad1..2960314 100644 --- a/src/avatar/CMakeLists.txt +++ b/src/avatar/CMakeLists.txt @@ -8,5 +8,15 @@ CONFIGURE_FILE("Config.h.in" "Config.h") SET(AVATAR_FILES "Avatar.cpp" "myAvatar.cpp") -ADD_LIBRARY(avatarAnim SHARED ${AVATAR_FILES}) -TARGET_LINK_LIBRARIES(avatarAnim ${LIBS} utilities clmTracker) \ No newline at end of file +if(WIN32) + set(LIBTYPE STATIC) +else() + set(LIBTYPE SHARED) +endif() + +ADD_LIBRARY(avatarAnim ${LIBTYPE} ${AVATAR_FILES}) +set_target_properties(avatarAnim PROPERTIES DEBUG_POSTFIX "d") +TARGET_LINK_LIBRARIES(avatarAnim ${LIBS} utilities clmTracker) + +install(TARGETS avatarAnim EXPORT CSIRO DESTINATION lib) +install(FILES Avatar.hpp IO.hpp DESTINATION include/avatar) \ No newline at end of file diff --git a/src/avatar/myAvatar.cpp b/src/avatar/myAvatar.cpp index 194f763..39dcdb7 100644 --- a/src/avatar/myAvatar.cpp +++ b/src/avatar/myAvatar.cpp @@ -17,11 +17,12 @@ // Copyright CSIRO 2013 -#include "utils/points.hpp" -#include "utils/helpers.hpp" +#include +#include #include #include -#include +#include "utils/points.hpp" +#include "utils/helpers.hpp" #define it at #define db at using namespace AVATAR; @@ -342,8 +343,8 @@ myAvatar::Animate(cv::Mat &draw, dx0_ = dx; dy0_ = dy; this->GetWidthHeight(_shapes[_idx],_lpupil[_idx].idx,wl,hl); this->GetWidthHeight(_shapes[_idx],_rpupil[_idx].idx,wr,hr); - lp.x = _lpupil[_idx].px + dx*wl; lp.y = _lpupil[_idx].py + dy*hl; - rp.x = _rpupil[_idx].px + dx*wr; rp.y = _rpupil[_idx].py + dy*hr; + lp.x = (int) (_lpupil[_idx].px + dx*wl); lp.y = (int) (_lpupil[_idx].py + dy*hl); + rp.x = (int) (_rpupil[_idx].px + dx*wr); rp.y = (int) (_rpupil[_idx].py + dy*hr); this->WarpBackPupils(lp,rp,_shapes[_idx],_shape); _gpdm.CalcParams(shape,gplocal_,gpglobl_); lrad = _lpupil[_idx].rad*gpglobl_.db(0,0); @@ -468,8 +469,8 @@ void myAvatar::WarpTexture(cv::Mat &src_pts,cv::Mat &dst_pts, if(ymin > src_pts.db(n+i,0))ymin = src_pts.db(n+i,0); if(ymax < src_pts.db(n+i,0))ymax = src_pts.db(n+i,0); } - cv::Rect R(floor(xmin),floor(ymin), - ceil(xmax-xmin),ceil(ymax-ymin)); + cv::Rect R((int)floor(xmin), (int)floor(ymin), + (int)ceil(xmax-xmin), (int)ceil(ymax-ymin)); if(R.width*R.height > 1){ cv::Mat M(R.height,3*R.width,CV_8U); for(int i = 0; i < 3; i++){ @@ -669,7 +670,7 @@ myAvatar::GetPupil(cv::Mat &im, if((rect.width <= 0) || (rect.height <= 0)){ cv::Point p(0,0); for(int i = 0; i < idx.rows; i++){ - p.x += pt.db(i,0); p.y += pt.db(i+idx.rows,0); + p.x += (int) (pt.db(i,0)); p.y += (int) (pt.db(i+idx.rows,0)); } p.x /= idx.rows; p.y /= idx.rows; return p; } @@ -677,7 +678,7 @@ myAvatar::GetPupil(cv::Mat &im, (rect.y < 0) || (rect.y + rect.height >= im.rows)){ cv::Point p; p.x = 0; p.y = 0; for(int i = 0; i < idx.rows; i++){ - p.x += pt.db(i,0); p.y += pt.db(i+idx.rows,0); + p.x += (int) (pt.db(i,0)); p.y += (int) (pt.db(i+idx.rows,0)); } p.x /= idx.rows; p.y /= idx.rows; return p; } @@ -694,10 +695,10 @@ myAvatar::GetPupil(cv::Mat &im, if(sum == 0){ p.x = 0; p.y = 0; for(int i = 0; i < idx.rows; i++){ - p.x += pt.db(i,0); p.y += pt.db(i+idx.rows,0); + p.x += (int) (pt.db(i,0)); p.y += (int) (pt.db(i+idx.rows,0)); } p.x /= idx.rows; p.y /= idx.rows; - }else{p.x = vx/sum; p.y = vy/sum;} + }else{p.x = (int) (vx/sum); p.y = (int) (vy/sum);} return p; } //============================================================================== @@ -714,7 +715,7 @@ myAvatar::GetBoundingBox(cv::Mat &pt) if(ymin > pt.db(i+n,0))ymin = pt.db(i+n,0); if(ymax < pt.db(i+n,0))ymax = pt.db(i+n,0); } - cv::Rect r(xmin,ymin,xmax-xmin,ymax-ymin); return r; + cv::Rect r((int)xmin, (int)ymin, (int)(xmax-xmin), (int)(ymax-ymin)); return r; } //============================================================================== void @@ -743,9 +744,9 @@ myAvatar::DrawPupil(double px, double vx = (pupil[0].cols-1)/2 + (x-px)*((pupil[0].cols-1)/2)/rad; double vy = (pupil[0].rows-1)/2 + (y-py)*((pupil[0].rows-1)/2)/rad; for(int i = 0; i < 3; i++){ - img[i].at(y,x) = FACETRACKER::bilinInterp(pupil[i],vx,vy); + img[i].at(y,x) = (uchar) FACETRACKER::bilinInterp(pupil[i],vx,vy); } - }else{for(int i = 0; i < 3; i++)img[i].at(y,x) = b.val[i];} + }else{for(int i = 0; i < 3; i++)img[i].at(y,x) = (uchar) b.val[i];} } } } @@ -768,7 +769,7 @@ myAvatar::WarpBackLeftPupil(cv::Point &p, cv::solve(X,Y,Z,cv::DECOMP_SVD); double a = Z.db(0,0),b = Z.db(1,0),x = Z.db(2,0),y = Z.db(3,0); double vx = a*p.x + b*p.y + x,vy = a*p.y - b*p.x + y; - cv::Point P(vx,vy); return P; + cv::Point P((int)vx, (int)vy); return P; } //============================================================================= cv::Point @@ -787,7 +788,7 @@ myAvatar::WarpBackRightPupil(cv::Point &p, cv::solve(X,Y,Z,cv::DECOMP_SVD); double a = Z.db(0,0),b = Z.db(1,0),x = Z.db(2,0),y = Z.db(3,0); double vx = a*p.x + b*p.y + x,vy = a*p.y - b*p.x + y; - cv::Point P(vx,vy); return P; + cv::Point P((int)vx, (int)vy); return P; } //============================================================================= void @@ -1054,8 +1055,8 @@ void myAvatar::AddAvatar(cv::Mat &image, cv::Mat &points, cv::Mat &eyes) rrpupil.scelera = cv::Scalar(150,150,150); cv::Mat limg = cv::Mat::zeros(101,101,CV_8UC3); cv::Mat rimg = cv::Mat::zeros(101,101,CV_8UC3); - cv::circle(limg,cv::Point((limg.rows-1)/2,(limg.rows-1)/2), - (limg.rows-1)*0.3,CV_RGB(50,50,50),(limg.rows-1)/4); + cv::circle(limg,cv::Point((int)((limg.rows-1)/2), (int)((limg.rows-1)/2)), + (int)((limg.rows-1)*0.3),CV_RGB(50,50,50), (int)((limg.rows-1)/4)); cv::circle(rimg,cv::Point((rimg.rows-1)/2,(rimg.rows-1)/2), (rimg.rows-1)/4,CV_RGB(50,50,50),(limg.rows-1)/4); llpupil.image.resize(3); cv::split(limg,llpupil.image); @@ -1172,7 +1173,7 @@ void myAvatar::GetEyes(cv::Mat &pt,cv::Mat &im, for(int x = 0; x < size; x++){ double v = sqrt((y-(size-1)/2)*(y-(size-1)/2) + (x-(size-1)/2)*(x-(size-1)/2)); - int vi = floor((double(d)-1.0)*v/((size-1)/2)); + int vi = (int) floor((double(d)-1.0)*v/((size-1)/2)); if(v < (size-1)/2){ double xl = cxl + (x - (size-1)/2)*lrad/((size-1)/2); double yl = cyl + (y - (size-1)/2)*lrad/((size-1)/2); @@ -1183,14 +1184,14 @@ void myAvatar::GetEyes(cv::Mat &pt,cv::Mat &im, lrgb[i].at(y,x) = (uchar)FACETRACKER::bilinInterp(rgb[i],xl,yl); }else{ - for(int i = 0; i < 3; i++)lrgb[i].at(y,x) = Tl.db(vi+d*i,0); + for(int i = 0; i < 3; i++)lrgb[i].at(y,x) = (uchar) Tl.db(vi+d*i,0); } if(FACETRACKER::isWithinTri(xr,yr,tri,rpt)>=0){ for(int i = 0; i < 3; i++) rrgb[i].at(y,x) = (uchar)FACETRACKER::bilinInterp(rgb[i],xr,yr); }else{ - for(int i = 0; i < 3; i++)rrgb[i].at(y,x) = Tr.db(vi+d*i,0); + for(int i = 0; i < 3; i++)rrgb[i].at(y,x) = (uchar) Tr.db(vi+d*i,0); } } } @@ -1256,12 +1257,12 @@ myAvatarParams::Load(const char* fname, bool binary) ifstream file(fname); assert(file.is_open()); int t; file >> t; assert(t == AVATAR::IO::MYAVATARPARAMS); - file >> t; animate_rigid = bool(t); - file >> t; animate_exprs = bool(t); - file >> t; animate_textr = bool(t); - file >> t; animate_eyes = bool(t); - file >> t; avatar_shape = bool(t); - file >> t; oral_cavity = bool(t); + file >> t; animate_rigid = (t != 0); + file >> t; animate_exprs = (t != 0); + file >> t; animate_textr = (t != 0); + file >> t; animate_eyes = (t != 0); + file >> t; avatar_shape = (t != 0); + file >> t; oral_cavity = (t != 0); file >> alpha; file.close(); type = AVATAR::IO::MYAVATARPARAMS; } @@ -1271,12 +1272,12 @@ myAvatarParams::Load(const char* fname, bool binary) s.read(reinterpret_cast(&t), sizeof(t)); assert(t == AVATAR::IOBinary::MYAVATARPARAMS); - s.read(reinterpret_cast(&t), sizeof(t)); animate_rigid = (bool)t; - s.read(reinterpret_cast(&t), sizeof(t)); animate_exprs = (bool)t; - s.read(reinterpret_cast(&t), sizeof(t)); animate_textr = (bool)t; - s.read(reinterpret_cast(&t), sizeof(t)); animate_eyes = (bool)t; - s.read(reinterpret_cast(&t), sizeof(t)); avatar_shape = (bool)t; - s.read(reinterpret_cast(&t), sizeof(t)); oral_cavity = (bool)t; + s.read(reinterpret_cast(&t), sizeof(t)); animate_rigid = (t != 0); + s.read(reinterpret_cast(&t), sizeof(t)); animate_exprs = (t != 0); + s.read(reinterpret_cast(&t), sizeof(t)); animate_textr = (t != 0); + s.read(reinterpret_cast(&t), sizeof(t)); animate_eyes = (t != 0); + s.read(reinterpret_cast(&t), sizeof(t)); avatar_shape = (t != 0); + s.read(reinterpret_cast(&t), sizeof(t)); oral_cavity = (t != 0); s.read(reinterpret_cast(&alpha), sizeof(alpha)); type = AVATAR::IO::MYAVATARPARAMS; s.close(); diff --git a/src/change-pathnames/CMakeLists.txt b/src/change-pathnames/CMakeLists.txt index 75472c8..3e24c69 100644 --- a/src/change-pathnames/CMakeLists.txt +++ b/src/change-pathnames/CMakeLists.txt @@ -2,7 +2,9 @@ add_executable(change-pathnames main.cpp) - +set_target_properties(change-pathnames PROPERTIES DEBUG_POSTFIX "d") target_link_libraries(change-pathnames utilities - ${LIBS}) \ No newline at end of file + ${LIBS}) + +install(TARGETS change-pathnames DESTINATION bin) \ No newline at end of file diff --git a/src/create-avatar-model/CMakeLists.txt b/src/create-avatar-model/CMakeLists.txt index 15dda62..7161962 100644 --- a/src/create-avatar-model/CMakeLists.txt +++ b/src/create-avatar-model/CMakeLists.txt @@ -2,8 +2,10 @@ add_executable(create-avatar-model main.cpp) - +set_target_properties(create-avatar-model PROPERTIES DEBUG_POSTFIX "d") target_link_libraries(create-avatar-model utilities avatarAnim ${LIBS}) + +install(TARGETS create-avatar-model DESTINATION bin) \ No newline at end of file diff --git a/src/create-avatar-model/main.cpp b/src/create-avatar-model/main.cpp index 423caec..25c043d 100644 --- a/src/create-avatar-model/main.cpp +++ b/src/create-avatar-model/main.cpp @@ -4,6 +4,7 @@ #include "avatar/myAvatar.hpp" #include +#include void print_usage() diff --git a/src/display-3d-points/CMakeLists.txt b/src/display-3d-points/CMakeLists.txt index 6533e44..8b4efc4 100644 --- a/src/display-3d-points/CMakeLists.txt +++ b/src/display-3d-points/CMakeLists.txt @@ -1,7 +1,10 @@ # -*-cmake-*- add_executable(display-3d-points main.cpp) +set_target_properties(display-3d-points PROPERTIES DEBUG_POSTFIX "d") target_link_libraries(display-3d-points utilities clmTracker ${LIBS}) + +install(TARGETS display-3d-points DESTINATION bin) \ No newline at end of file diff --git a/src/display-3d-points/main.cpp b/src/display-3d-points/main.cpp index 792068f..40f2d43 100644 --- a/src/display-3d-points/main.cpp +++ b/src/display-3d-points/main.cpp @@ -4,6 +4,8 @@ #include "tracker/FaceTracker.hpp" #include +#include +#include void print_usage() diff --git a/src/display-avatar/CMakeLists.txt b/src/display-avatar/CMakeLists.txt index 30dfae5..617dcf6 100644 --- a/src/display-avatar/CMakeLists.txt +++ b/src/display-avatar/CMakeLists.txt @@ -2,8 +2,10 @@ add_executable(display-avatar main.cpp) - +set_target_properties(display-avatar PROPERTIES DEBUG_POSTFIX "d") target_link_libraries(display-avatar utilities avatarAnim ${LIBS}) + +install(TARGETS display-avatar DESTINATION bin) \ No newline at end of file diff --git a/src/display-tracking/CMakeLists.txt b/src/display-tracking/CMakeLists.txt index e92f5a8..afab597 100644 --- a/src/display-tracking/CMakeLists.txt +++ b/src/display-tracking/CMakeLists.txt @@ -2,7 +2,9 @@ add_executable(display-tracking main.cpp) - +set_target_properties(display-tracking PROPERTIES DEBUG_POSTFIX "d") target_link_libraries(display-tracking utilities ${LIBS}) + +install(TARGETS display-tracking DESTINATION bin) \ No newline at end of file diff --git a/src/display-tracking/main.cpp b/src/display-tracking/main.cpp index 9eed15d..5c72c4e 100644 --- a/src/display-tracking/main.cpp +++ b/src/display-tracking/main.cpp @@ -17,11 +17,12 @@ // Copyright CSIRO 2013 +#include +#include +#include #include "utils/helpers.hpp" #include "utils/command-line-arguments.hpp" #include "utils/points.hpp" -#include -#include void print_usage() @@ -98,7 +99,7 @@ run_program(int argc, char **argv) cv::imwrite(output_pathname->c_str(), img); } else { cv::imshow("Image", img); - cv::waitKey(1000*wait_time); + cv::waitKey((int) (1000*wait_time)); } return 0; diff --git a/src/expression-transfer/CMakeLists.txt b/src/expression-transfer/CMakeLists.txt index b968058..79ada2a 100644 --- a/src/expression-transfer/CMakeLists.txt +++ b/src/expression-transfer/CMakeLists.txt @@ -1,8 +1,10 @@ # -*-cmake-*- add_executable(expression-transfer main.cpp) - +set_target_properties(expression-transfer PROPERTIES DEBUG_POSTFIX "d") target_link_libraries(expression-transfer utilities avatarAnim ${LIBS}) + +install(TARGETS expression-transfer DESTINATION bin) \ No newline at end of file diff --git a/src/face-fit/CMakeLists.txt b/src/face-fit/CMakeLists.txt index f5d19e3..d452098 100644 --- a/src/face-fit/CMakeLists.txt +++ b/src/face-fit/CMakeLists.txt @@ -1,7 +1,10 @@ # -*-cmake-*- add_executable(face-fit main.cpp) +set_target_properties(face-fit PROPERTIES DEBUG_POSTFIX "d") target_link_libraries(face-fit utilities clmTracker ${LIBS}) + +install(TARGETS face-fit DESTINATION bin) \ No newline at end of file diff --git a/src/face-fit/main.cpp b/src/face-fit/main.cpp index b5b0deb..a29a4f0 100644 --- a/src/face-fit/main.cpp +++ b/src/face-fit/main.cpp @@ -22,6 +22,7 @@ #include "utils/points.hpp" #include "tracker/FaceTracker.hpp" #include +#include using namespace FACETRACKER; @@ -188,7 +189,7 @@ main(int argc, char **argv) { try { return run_program(argc, argv); - } catch (user_pressed_escape &e) { + } catch (user_pressed_escape) { std::cout << "Stopping prematurely." << std::endl; return 1; } catch (std::exception &e) { @@ -395,11 +396,11 @@ compute_pose_image(const Pose &pose, int height, int width) cv::Point centre(width/2, height/2); // pitch - cv::line(rv, centre, cv::Point(axes(0,0), axes(1,0)), cv::Scalar(255,0,0)); + cv::line(rv, centre, cv::Point((int)axes(0,0), (int)axes(1,0)), cv::Scalar(255,0,0)); // yaw - cv::line(rv, centre, cv::Point(axes(0,1), axes(1,1)), cv::Scalar(0,255,0)); + cv::line(rv, centre, cv::Point((int)axes(0,1), (int)axes(1,1)), cv::Scalar(0,255,0)); // roll - cv::line(rv, centre, cv::Point(axes(0,2), axes(1,2)), cv::Scalar(0,0,255)); + cv::line(rv, centre, cv::Point((int)axes(0,2), (int)axes(1,2)), cv::Scalar(0,0,255)); return rv; } @@ -448,7 +449,7 @@ display_data(const Configuration &cfg, if (cfg.wait_time == 0) std::cout << "Press any key to continue." << std::endl; - char ch = cv::waitKey(cfg.wait_time * 1000); + char ch = cv::waitKey((int) (cfg.wait_time * 1000)); if (ch == 27) // escape throw user_pressed_escape(); diff --git a/src/map-list/CMakeLists.txt b/src/map-list/CMakeLists.txt index 9f97f21..9cd8332 100644 --- a/src/map-list/CMakeLists.txt +++ b/src/map-list/CMakeLists.txt @@ -2,7 +2,9 @@ add_executable(map-list main.cpp) - +set_target_properties(map-list PROPERTIES DEBUG_POSTFIX "d") target_link_libraries(map-list utilities ${LIBS}) + +install(TARGETS map-list DESTINATION bin) diff --git a/src/map-list/main.cpp b/src/map-list/main.cpp index 234b66f..d5a09b8 100644 --- a/src/map-list/main.cpp +++ b/src/map-list/main.cpp @@ -23,8 +23,14 @@ #include #include #include + +#ifdef _WIN32 +#include +#include +#else #include #include +#endif void print_usage() @@ -65,6 +71,49 @@ class EchoRunner : public Runner std::ostream &stream; }; +#ifdef _WIN32 +class ForkRunner : public Runner +{ +public: + void perform(const std::string &command, const std::list &arguments) { + + STARTUPINFO si; + PROCESS_INFORMATION pi; + + ZeroMemory( &si, sizeof(si) ); + si.cb = sizeof(si); + ZeroMemory( &pi, sizeof(pi) ); + + if(!CreateProcess(NULL, "", NULL, NULL, FALSE, 0, NULL, NULL, &si, &pi)){ //child process + char **argv = new char*[arguments.size() + 2]; + argv[0] = (char *)command.c_str(); + argv[arguments.size() + 1] = 0; + + std::list::const_iterator it = arguments.begin(); + for (size_t i = 0; i < arguments.size(); i++) { + argv[i + 1] = (char *)it->c_str(); + it++; + } + + int rv = _execvp(command.c_str(), argv); + delete[] argv; + if (rv == -1) + throw make_runtime_error("Unable to create new process: %s.", strerror(errno)); + } + else { // parent process + throw make_runtime_error("CreateProcess failed (%d).\n", GetLastError() ); + return; + } + + // Wait until child process exits. + WaitForSingleObject( pi.hProcess, INFINITE ); + + // Close process and thread handles. + CloseHandle( pi.hProcess ); + CloseHandle( pi.hThread ); + } +}; +#else class ForkRunner : public Runner { public: @@ -103,6 +152,7 @@ class ForkRunner : public Runner } } }; +#endif int run_program(int argc, char **argv) diff --git a/src/qt-gui/CMakeLists.txt b/src/qt-gui/CMakeLists.txt index 8ddb0a4..2986905 100644 --- a/src/qt-gui/CMakeLists.txt +++ b/src/qt-gui/CMakeLists.txt @@ -1,7 +1,17 @@ # -*-cmake-*- -find_package(Qt4 REQUIRED) +cmake_policy (SET CMP0020 NEW) -INCLUDE( ${QT_USE_FILE} ) +set(CMAKE_INCLUDE_CURRENT_DIR ON) # Find includes in corresponding build directories +set(CMAKE_AUTOMOC ON) # Instruct CMake to run moc automatically when needed +set(CMAKE_AUTORCC ON) # Instruct CMake to run rcc automatically when needed +set(CMAKE_AUTOUIC ON) # Instruct CMake to run uic automatically when needed + +find_package(Qt5Widgets) +include_directories(${Qt5Widgets_INCLUDE_DIRS}) +# add_definitions(${Qt5Widgets_DEFINITIONS}) +set(CMAKE_CXX_FLAGS "${Qt5Widgets_EXECUTABLE_COMPILE_FLAGS}") + +#INCLUDE( ${QT_USE_FILE} ) #set(CMAKE_VERBOSE_MAKEFILE true) @@ -9,6 +19,7 @@ SET(BundleName "qt-gui") SET(guiFILES "application-states.cpp" "controllers.cpp" + "command-line-configuration.cpp" "configuration.cpp" "gui/avatar-selection.cpp" "gui/main-window.cpp" @@ -33,19 +44,47 @@ SET(MOC_HEADERS "gui/worker-thread.hpp") # "gui/item-positions-calculator.hpp") -QT4_WRAP_CPP(MOC_SRCS ${MOC_HEADERS}) +#QT5_WRAP_CPP(MOC_SRCS ${MOC_HEADERS}) INCLUDE_DIRECTORIES(".") -set_source_files_properties(osx-configuration.mm PROPERTIES COMPILE_FLAGS -ObjC++) +# Non-Apple users get the Foundation librariries from GnuStep +IF(UNIX AND NOT APPLE) + INCLUDE_DIRECTORIES(/usr/local/include/GNUstep /usr/include/GNUstep) + EXECUTE_PROCESS(COMMAND gnustep-config --objc-flags + OUTPUT_VARIABLE GnuStep_FLAGS + OUTPUT_STRIP_TRAILING_WHITESPACE) + EXECUTE_PROCESS(COMMAND gnustep-config --base-libs + OUTPUT_VARIABLE GnuStep_LINK_FLAGS + OUTPUT_STRIP_TRAILING_WHITESPACE) + STRING(REPLACE "\n" "" GnuStep_FLAGS ${GnuStep_FLAGS}) + STRING(REPLACE "\n" "" GnuStep_LINK_FLAGS ${GnuStep_LINK_FLAGS}) + + SET(GnuStep_LINK_FLAGS "-Wl,--no-as-needed ${GnuStep_LINK_FLAGS}") + set_source_files_properties(osx-configuration.mm PROPERTIES + COMPILE_FLAGS "${GnuStep_FLAGS}" + LINKER_FLAGS "${GnuStep_LINK_FLAGS}") +ELSE() + set_source_files_properties(osx-configuration.mm PROPERTIES COMPILE_FLAGS -ObjC++) +ENDIF() + +if(WIN32) + set(TARGET_TYPE WIN32) +elseif(APPLE) + set(TARGET_TYPE MACOSX_BUNDLE) +endif() -add_executable(demo-application +add_executable(demo-application ${TARGET_TYPE} main.cpp command-line-configuration.cpp ${guiFILES} ${MOC_SRCS} ${EXTRA_SRC}) -target_link_libraries(demo-application ${LIBS} ${QT_LIBRARIES} clmTracker avatarAnim utilities ${EXTRA_LIBS}) + +set_target_properties(demo-application PROPERTIES DEBUG_POSTFIX "d") +target_link_libraries(demo-application ${Qt5Widgets_LIBRARIES} ${LIBS} clmTracker avatarAnim utilities ${EXTRA_LIBS}) + +install(TARGETS demo-application DESTINATION bin) # Apple Specific Targets @@ -54,19 +93,26 @@ IF(APPLE) set_source_files_properties(${CMAKE_CURRENT_SOURCE_DIR}/Configuration.plist PROPERTIES MACOSX_PACKAGE_LOCATION Resources) SET(EXTRA_SRC "Configuration.plist") + SET(CONFIG_SRC "osx-configuration.mm") ENDIF() - -ADD_EXECUTABLE(${BundleName} MACOSX_BUNDLE +ADD_EXECUTABLE(${BundleName} ${TARGET_TYPE} main.cpp - osx-configuration.mm + ${CONFIG_SRC} ${guiFILES} ${MOC_SRCS} ${EXTRA_SRC} ) -TARGET_LINK_LIBRARIES(${BundleName} ${LIBS} ${QT_LIBRARIES} clmTracker avatarAnim ${EXTRA_LIBS}) +IF(UNIX AND NOT APPLE) + SET_TARGET_PROPERTIES(${BundleName} PROPERTIES + LINK_FLAGS "${GnuStep_LINK_FLAGS}") +ENDIF() + +set_target_properties(${BundleName} PROPERTIES DEBUG_POSTFIX "d") +TARGET_LINK_LIBRARIES(${BundleName} ${LIBS} ${Qt5Widgets_LIBRARIES} clmTracker avatarAnim ${EXTRA_LIBS}) +install(TARGETS ${BundleName} DESTINATION bin) # IF(APPLE) @@ -88,7 +134,7 @@ IF(APPLE) BUNDLE DESTINATION . COMPONENT Runtime RUNTIME DESTINATION bin COMPONENT Runtime ) - + FILE(GLOB trackerFiles "${CMAKE_CURRENT_SOURCE_DIR}/../tracker/resources/*") FILE(GLOB avatarFiles "${CMAKE_CURRENT_SOURCE_DIR}/../avatar/resources/*") diff --git a/src/qt-gui/application-states.hpp b/src/qt-gui/application-states.hpp index 2323ba1..a2b13ee 100644 --- a/src/qt-gui/application-states.hpp +++ b/src/qt-gui/application-states.hpp @@ -20,7 +20,7 @@ #ifndef _QT_GUI_APPLICATION_STATES_HPP_ #define _QT_GUI_APPLICATION_STATES_HPP_ -#include +#include namespace CI2CVGui { diff --git a/src/qt-gui/configuration.hpp b/src/qt-gui/configuration.hpp index e7cd566..23183da 100644 --- a/src/qt-gui/configuration.hpp +++ b/src/qt-gui/configuration.hpp @@ -20,7 +20,7 @@ #ifndef _CI2CV_GUI_CONFIGURATION_HPP_ #define _CI2CV_GUI_CONFIGURATION_HPP_ -#include +#include namespace CI2CVGui { diff --git a/src/qt-gui/controllers.hpp b/src/qt-gui/controllers.hpp index cb9c4ee..5c0a0b1 100644 --- a/src/qt-gui/controllers.hpp +++ b/src/qt-gui/controllers.hpp @@ -20,8 +20,8 @@ #ifndef _CI2CV_GUI_GUI_CONTROLLER_HPP_ #define _CI2CV_GUI_GUI_CONTROLLER_HPP_ -#include -#include +#include +#include #include namespace CI2CVGui diff --git a/src/qt-gui/gui/avatar-selection.cpp b/src/qt-gui/gui/avatar-selection.cpp index b4ddf54..67bc4bd 100644 --- a/src/qt-gui/gui/avatar-selection.cpp +++ b/src/qt-gui/gui/avatar-selection.cpp @@ -20,8 +20,8 @@ #include "gui/avatar-selection.hpp" #include "controllers.hpp" -#include -#include +#include +#include using namespace CI2CVGui; diff --git a/src/qt-gui/gui/avatar-selection.hpp b/src/qt-gui/gui/avatar-selection.hpp index 836c78a..27ee942 100644 --- a/src/qt-gui/gui/avatar-selection.hpp +++ b/src/qt-gui/gui/avatar-selection.hpp @@ -20,10 +20,10 @@ #ifndef _CI2CV_GUI_GUI_AVATAR_SELECTION_HPP_ #define _CI2CV_GUI_GUI_AVATAR_SELECTION_HPP_ -#include -#include -#include -#include +#include +#include +#include +#include #include "gui/graphics-scrollbar.hpp" diff --git a/src/qt-gui/gui/graphics-scrollbar.cpp b/src/qt-gui/gui/graphics-scrollbar.cpp index 36bb9d6..e3a4e2b 100644 --- a/src/qt-gui/gui/graphics-scrollbar.cpp +++ b/src/qt-gui/gui/graphics-scrollbar.cpp @@ -18,9 +18,9 @@ // Copyright CSIRO 2013 #include "gui/graphics-scrollbar.hpp" -#include -#include -#include +#include +#include +#include using namespace CI2CVGui; diff --git a/src/qt-gui/gui/graphics-scrollbar.hpp b/src/qt-gui/gui/graphics-scrollbar.hpp index 601f302..db19f99 100644 --- a/src/qt-gui/gui/graphics-scrollbar.hpp +++ b/src/qt-gui/gui/graphics-scrollbar.hpp @@ -20,11 +20,11 @@ #ifndef _CI2CV_GUI_GUI_GRAPHICS_SCROLLBAR_HPP_ #define _CI2CV_GUI_GUI_GRAPHICS_SCROLLBAR_HPP_ -#include -#include -#include -#include -#include +#include +#include +#include +#include +#include namespace CI2CVGui { class GraphicsScrollbar; diff --git a/src/qt-gui/gui/item-controllers.hpp b/src/qt-gui/gui/item-controllers.hpp index d103aee..f01c579 100644 --- a/src/qt-gui/gui/item-controllers.hpp +++ b/src/qt-gui/gui/item-controllers.hpp @@ -20,9 +20,9 @@ #ifndef _CI2CV_GUI_GUI_ITEM_POSITIONERS_HPP_ #define _CI2CV_GUI_GUI_ITEM_POSITIONERS_HPP_ -#include -#include -#include +#include +#include +#include #include diff --git a/src/qt-gui/gui/main-window.cpp b/src/qt-gui/gui/main-window.cpp index a1e4d64..c24687a 100644 --- a/src/qt-gui/gui/main-window.cpp +++ b/src/qt-gui/gui/main-window.cpp @@ -24,12 +24,12 @@ #include "gui/mesh-drawer.hpp" #include "configuration.hpp" -#include -#include -#include -#include -#include -#include +#include +#include +#include +#include +#include +#include using namespace CI2CVGui; diff --git a/src/qt-gui/gui/main-window.hpp b/src/qt-gui/gui/main-window.hpp index 99eea1f..5534191 100644 --- a/src/qt-gui/gui/main-window.hpp +++ b/src/qt-gui/gui/main-window.hpp @@ -20,13 +20,13 @@ #ifndef _CI2CV_GUI_GUI_MAIN_WINDOW_HPP_ #define _CI2CV_GUI_GUI_MAIN_WINDOW_HPP_ -#include -#include -#include -#include -#include -#include -#include +#include +#include +#include +#include +#include +#include +#include #include "gui/item-controllers.hpp" diff --git a/src/qt-gui/gui/mesh-drawer.cpp b/src/qt-gui/gui/mesh-drawer.cpp index 23b01a7..c215354 100644 --- a/src/qt-gui/gui/mesh-drawer.cpp +++ b/src/qt-gui/gui/mesh-drawer.cpp @@ -20,8 +20,8 @@ #include "gui/mesh-drawer.hpp" #include "controllers.hpp" -#include -#include +#include +#include using namespace CI2CVGui; diff --git a/src/qt-gui/gui/mesh-drawer.hpp b/src/qt-gui/gui/mesh-drawer.hpp index 2ca14af..e1ed089 100644 --- a/src/qt-gui/gui/mesh-drawer.hpp +++ b/src/qt-gui/gui/mesh-drawer.hpp @@ -20,10 +20,10 @@ #ifndef _CI2CV_GUI_GUI_MESH_DRAWER_HPP_ #define _CI2CV_GUI_GUI_MESH_DRAWER_HPP_ -#include -#include -#include -#include +#include +#include +#include +#include #include diff --git a/src/qt-gui/gui/windowed-gui-controller.hpp b/src/qt-gui/gui/windowed-gui-controller.hpp index 0f2b250..52f83b7 100644 --- a/src/qt-gui/gui/windowed-gui-controller.hpp +++ b/src/qt-gui/gui/windowed-gui-controller.hpp @@ -20,11 +20,11 @@ #ifndef _CI2CV_GUI_GUI_WINDOWED_GUI_CONTROLLER_HPP_ #define _CI2CV_GUI_GUI_WINDOWED_GUI_CONTROLLER_HPP_ -#include -#include -#include -#include -#include +#include +#include +#include +#include +#include #include "controllers.hpp" #include "gui/item-controllers.hpp" diff --git a/src/qt-gui/gui/worker-thread.cpp b/src/qt-gui/gui/worker-thread.cpp index 880565d..f420753 100644 --- a/src/qt-gui/gui/worker-thread.cpp +++ b/src/qt-gui/gui/worker-thread.cpp @@ -24,7 +24,7 @@ #include #include -#include "avatar/avatar.hpp" +#include "avatar/Avatar.hpp" #include "gui/avatar.hpp" #include "configuration.hpp" diff --git a/src/qt-gui/gui/worker-thread.hpp b/src/qt-gui/gui/worker-thread.hpp index 289991d..9a966ff 100644 --- a/src/qt-gui/gui/worker-thread.hpp +++ b/src/qt-gui/gui/worker-thread.hpp @@ -25,9 +25,11 @@ #include #include -#include -#include -#include +#include "opencv2/opencv.hpp" + +#include +#include +#include namespace CI2CVGui { class WorkerThreadCameraController : public CameraController diff --git a/src/qt-gui/main.cpp b/src/qt-gui/main.cpp index ab2c6eb..b42ed09 100644 --- a/src/qt-gui/main.cpp +++ b/src/qt-gui/main.cpp @@ -17,10 +17,10 @@ // Copyright CSIRO 2013 -#include -#include -#include -#include +#include +#include +#include +#include #include #include diff --git a/src/qt-gui/osx-configuration.mm b/src/qt-gui/osx-configuration.mm index 2e3e1f6..4d841f5 100644 --- a/src/qt-gui/osx-configuration.mm +++ b/src/qt-gui/osx-configuration.mm @@ -19,6 +19,7 @@ #include #include +#include #include #include #include diff --git a/src/qt-gui/qt-gui.pro b/src/qt-gui/qt-gui.pro index ef1e38f..d135bb8 100644 --- a/src/qt-gui/qt-gui.pro +++ b/src/qt-gui/qt-gui.pro @@ -9,6 +9,8 @@ LIBS += \ -lopencv_core -lopencv_highgui -lopencv_imgproc -lopencv_objdetect -lopencv_video -lobjc \ -framework Foundation +greaterThan(QT_MAJOR_VERSION, 4): QT += widgets + include(qt-gui.pro.local) { message("Loading in data from qt-gui.pro.local") } else { diff --git a/src/scripts/CMakeLists.txt b/src/scripts/CMakeLists.txt index 24cac0c..398e3a5 100644 --- a/src/scripts/CMakeLists.txt +++ b/src/scripts/CMakeLists.txt @@ -13,7 +13,7 @@ foreach(_script ${generated_scripts}) configure_file(${_script}.in ${_script}) add_custom_command( OUTPUT ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/${_script} - COMMAND /usr/bin/install -m 755 ${_script} ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/${_script} + COMMAND install -m 755 ${_script} ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/${_script} DEPENDS ${_script}.in) list(APPEND executable_scripts ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/${_script}) endforeach() diff --git a/src/test/CMakeLists.txt b/src/test/CMakeLists.txt index 885708b..a07fc2d 100644 --- a/src/test/CMakeLists.txt +++ b/src/test/CMakeLists.txt @@ -1,12 +1,19 @@ # -*-cmake-*- ADD_EXECUTABLE(test_avatar test_Avatar.cpp) +set_target_properties(test_avatar PROPERTIES DEBUG_POSTFIX "d") TARGET_LINK_LIBRARIES(test_avatar ${LIBS} clmTracker) TARGET_LINK_LIBRARIES(test_avatar avatarAnim) ADD_EXECUTABLE(speed_test speed_test.cpp command-line-options.cpp) +set_target_properties(speed_test PROPERTIES DEBUG_POSTFIX "d") TARGET_LINK_LIBRARIES(speed_test ${LIBS} clmTracker avatarAnim) ADD_EXECUTABLE(add_avatar add_avatar.cpp) +set_target_properties(add_avatar PROPERTIES DEBUG_POSTFIX "d") TARGET_LINK_LIBRARIES(add_avatar ${LIBS} avatarAnim) + +install(TARGETS test_avatar DESTINATION bin) +install(TARGETS speed_test DESTINATION bin) +install(TARGETS add_avatar DESTINATION bin) \ No newline at end of file diff --git a/src/test/command-line-options.cpp b/src/test/command-line-options.cpp index 7dca9f0..11675a7 100644 --- a/src/test/command-line-options.cpp +++ b/src/test/command-line-options.cpp @@ -20,6 +20,8 @@ #include "command-line-options.hpp" #include #include +#include +#include //Utilities template diff --git a/src/test/speed_test.cpp b/src/test/speed_test.cpp index 8631926..7b948e7 100644 --- a/src/test/speed_test.cpp +++ b/src/test/speed_test.cpp @@ -20,11 +20,13 @@ #include #include #include -#include +#include #include #include +#include #include +#include "opencv2/opencv.hpp" #define db at #define it at @@ -54,14 +56,14 @@ void draw_shape(cv::Mat &image,cv::Mat &shape,cv::Mat &con) { int i,n = shape.rows/2; cv::Point p1,p2; for(i = 0; i < con.cols; i++){ - p1 = cv::Point(shape.at(con.at(0,i),0), - shape.at(con.at(0,i)+n,0)); - p2 = cv::Point(shape.at(con.at(1,i),0), - shape.at(con.at(1,i)+n,0)); + p1 = cv::Point((int)shape.at(con.at(0,i),0), + (int)shape.at(con.at(0,i)+n,0)); + p2 = cv::Point((int)shape.at(con.at(1,i),0), + (int)shape.at(con.at(1,i)+n,0)); cv::line(image,p1,p2,CV_RGB(0,255,0),1); } for(i = 0; i < n; i++){ - p1 = cv::Point(shape.at(i,0),shape.at(i+n,0)); + p1 = cv::Point((int)shape.at(i,0), (int)shape.at(i+n,0)); cv::circle(image,p1,2,CV_RGB(255,0,0)); }return; } @@ -69,9 +71,9 @@ void draw_shape(cv::Mat &image,cv::Mat &shape,cv::Mat &con) void draw_health(cv::Mat &I,int health) { double v = double(health)/10.0; - int w = 0.1*double(I.cols),h = 0.05*double(I.rows); + int w = (int)(0.1*double(I.cols)),h = (int) (0.05*double(I.rows)); cv::rectangle(I,cv::Point(h/2,h/2),cv::Point(w+h/2,h+h/2),CV_RGB(0,0,0),3); - cv::Mat im = I(cv::Rect(h/2+3,h/2+3,v*(w-5),h-5)); im = CV_RGB(0,0,255); + cv::Mat im = I(cv::Rect((int)(h/2+3), (int)(h/2+3), (int)(v*(w-5)), (int)(h-5))); im = CV_RGB(0,0,255); char str[256]; sprintf(str,"%d%%",(int)(100*v+0.5)); cv::putText(I,str,cv::Point(w+h/2+w/20,h+h/2), CV_FONT_HERSHEY_SIMPLEX,h*0.045,CV_RGB(0,0,255),2); return; @@ -140,7 +142,7 @@ int main(int argc, char** argv) try { camera_index = options.argument("camera", 0); - } catch (std::exception &e) { + } catch (std::exception) { camera_index = -1; } @@ -168,7 +170,7 @@ int main(int argc, char** argv) FACETRACKER::FaceTrackerParams * p = FACETRACKER::LoadFaceTrackerParams(face_tracker_parameters_file.c_str()); FACETRACKER::myFaceTrackerParams* pp = dynamic_cast(p); - pp->shape_predict = eye_mouth_refine; + pp->shape_predict = (eye_mouth_refine != 0); char* fname = NULL; cv::Mat con = FACETRACKER::IO::LoadCon(face_connections_file.c_str()); @@ -348,8 +350,8 @@ int main(int argc, char** argv) else if(c == int('i')){ avatar->Initialise(im,tracker->_shape); init = true; } - input_frame_last_captured += 1.0/(1000.0*cv::getTickFrequency()); - output_frame_last_output += 1.0/(1000.0*cv::getTickFrequency()); + input_frame_last_captured += (int) (1.0/(1000.0*cv::getTickFrequency())); + output_frame_last_output += (int) (1.0/(1000.0*cv::getTickFrequency())); int64 total2 = cv::getTickCount(); total_time += total2-total1; diff --git a/src/test/test_Avatar.cpp b/src/test/test_Avatar.cpp index e228cfa..a456b12 100644 --- a/src/test/test_Avatar.cpp +++ b/src/test/test_Avatar.cpp @@ -26,6 +26,11 @@ #include #include #include + +#ifdef _WIN32 +#include +#endif + #define db at #define it at //============================================================================= @@ -33,14 +38,14 @@ void draw_shape(cv::Mat &image,cv::Mat &shape,cv::Mat &con) { int i,n = shape.rows/2; cv::Point p1,p2; for(i = 0; i < con.cols; i++){ - p1 = cv::Point(shape.at(con.at(0,i),0), - shape.at(con.at(0,i)+n,0)); - p2 = cv::Point(shape.at(con.at(1,i),0), - shape.at(con.at(1,i)+n,0)); + p1 = cv::Point((int)shape.at(con.at(0,i),0), + (int)shape.at(con.at(0,i)+n,0)); + p2 = cv::Point((int)shape.at(con.at(1,i),0), + (int)shape.at(con.at(1,i)+n,0)); cv::line(image,p1,p2,CV_RGB(0,255,0),1); } for(i = 0; i < n; i++){ - p1 = cv::Point(shape.at(i,0),shape.at(i+n,0)); + p1 = cv::Point((int)shape.at(i,0), (int)shape.at(i+n,0)); cv::circle(image,p1,2,CV_RGB(255,0,0)); }return; } @@ -48,10 +53,17 @@ void draw_shape(cv::Mat &image,cv::Mat &shape,cv::Mat &con) void draw_health(cv::Mat &I,int health) { double v = MAX(0,double(health)/10.0); - int w = 0.1*double(I.cols),h = 0.05*double(I.rows); + int w = (int) (0.1*double(I.cols)), h = (int) (0.05*double(I.rows)); cv::rectangle(I,cv::Point(h/2,h/2),cv::Point(w+h/2,h+h/2),CV_RGB(0,0,0),3); - cv::Mat im = I(cv::Rect(h/2+3,h/2+3,v*(w-5),h-5)); im = CV_RGB(0,0,255); - char str[256]; sprintf(str,"%d%%",(int)(100*v+0.5)); + cv::Mat im = I(cv::Rect((int)(h/2+3), (int)(h/2+3), (int)(v*(w-5)), (int)(h-5))); im = CV_RGB(0,0,255); + char str[256]; + +#ifdef _WIN32 + sprintf_s(str, 256, "%d%%", (int)(100 * v + 0.5)); +#else + sprintf(str,"%d%%",(int)(100*v+0.5)); +#endif + cv::putText(I,str,cv::Point(w+h/2+w/20,h+h/2), CV_FONT_HERSHEY_SIMPLEX,h*0.045,CV_RGB(0,0,255),2); return; } @@ -106,9 +118,18 @@ int main(int argc, char *argv[]) if(!strcmp(argv[1], "-o")){ saveData = true; char fname[128]; + +#ifdef _WIN32 + time_t rawtime; + struct tm timeinfo; + localtime_s(&timeinfo, &rawtime); + strftime(fname, 128, "output_%Y_%m_%d_%H_%M_%S.xml", &timeinfo); +#else time_t rawtime; time(&rawtime); struct tm * timeinfo = localtime(&rawtime); strftime(fname, 128, "output_%Y_%m_%d_%H_%M_%S.xml", timeinfo); +#endif + outputFile = fname; camera.open(0); @@ -187,7 +208,11 @@ int main(int argc, char *argv[]) if(saveData){ char fnum[26]; +#ifdef _WIN32 + sprintf_s(fnum, 256, "frame_%05d", frameCount); +#else sprintf(fnum, "frame_%05d", frameCount); +#endif fs << std::string(fnum) << "{"; if(health>=0){ //save the 2D points to file diff --git a/src/tracker/ATM.cpp b/src/tracker/ATM.cpp index 4cd88e5..72586d8 100644 --- a/src/tracker/ATM.cpp +++ b/src/tracker/ATM.cpp @@ -17,9 +17,11 @@ // Copyright CSIRO 2013 -#include -#include #include +#include +#include +#include +#include #define it at #define db at using namespace FACETRACKER; diff --git a/src/tracker/CLM.cpp b/src/tracker/CLM.cpp index 33c2189..7c67336 100644 --- a/src/tracker/CLM.cpp +++ b/src/tracker/CLM.cpp @@ -208,7 +208,7 @@ void CLM::Read(ifstream &s,bool readType) int n; s >> n; - _kWidth = 36.; + _kWidth = 36; _pdm.Read(s); _cent.resize(n); _visi.resize(n); @@ -255,7 +255,7 @@ void CLM::ReadBinary(ifstream &s,bool readType) } int n; - _kWidth = 36.; + _kWidth = 36; s.read(reinterpret_cast(&n), sizeof(n)); _pdm.ReadBinary(s); _cent.resize(n); diff --git a/src/tracker/CMakeLists.txt b/src/tracker/CMakeLists.txt index b1e0c47..03391dc 100644 --- a/src/tracker/CMakeLists.txt +++ b/src/tracker/CMakeLists.txt @@ -23,6 +23,15 @@ SET(TRACKER_FILES "ShapePredictor.cpp" "myFaceTracker.cpp") +if(WIN32) + set(LIBTYPE STATIC) +else() + set(LIBTYPE SHARED) +endif() -ADD_LIBRARY(clmTracker SHARED ${TRACKER_FILES}) -TARGET_LINK_LIBRARIES(clmTracker ${LIBS}) \ No newline at end of file +ADD_LIBRARY(clmTracker ${LIBTYPE} ${TRACKER_FILES}) +set_target_properties(clmTracker PROPERTIES DEBUG_POSTFIX "d") +TARGET_LINK_LIBRARIES(clmTracker ${LIBS}) + +install(TARGETS clmTracker EXPORT CSIRO DESTINATION lib) +install(FILES FaceTracker.hpp IO.hpp DESTINATION include/tracker) \ No newline at end of file diff --git a/src/tracker/Detector.cpp b/src/tracker/Detector.cpp index c5cf1c2..627a843 100644 --- a/src/tracker/Detector.cpp +++ b/src/tracker/Detector.cpp @@ -17,7 +17,11 @@ // Copyright CSIRO 2013 +#include + +#include #include +#include #include "Detector.hpp" #include "IO.hpp" @@ -105,7 +109,7 @@ Detector::getResponsesForRefShape(double scale) if(scale == 1.) return prob_; else{ - cv::Size sz (prob_.at(0).cols / scale, prob_.at(0).rows/scale); + cv::Size sz ((int) (prob_.at(0).cols / scale), (int) (prob_.at(0).rows/scale)); bool t = false; if(sz.width%2==0){ sz.width++; t = true;} @@ -171,7 +175,7 @@ Detector::getResponsesForRefShape(cv::Size wSize, cv::Mat r) cv::Size sz; for (size_t i=0; i0 || respRect.y>0){ - resp.at(i) = cv::Mat::zeros(wSize, m.type()); - m(probRect).copyTo(resp.at(i)(respRect)); + resp.at(i) = cv::Mat::zeros(wSize, m.type()); + cv::Mat tmp = resp.at(i)(respRect); + m(probRect).copyTo(tmp); } else resp.at(i) = m(probRect); diff --git a/src/tracker/FDet.cpp b/src/tracker/FDet.cpp index 7940430..f34566d 100644 --- a/src/tracker/FDet.cpp +++ b/src/tracker/FDet.cpp @@ -17,6 +17,8 @@ // Copyright CSIRO 2013 +#include +#include #include using namespace FACETRACKER; using namespace std; @@ -76,8 +78,8 @@ cv::Rect FDet::Detect(cv::Mat im) for(i = 0,maxv = 0; i < obj->total; i++){ CvRect* r = (CvRect*)cvGetSeqElem(obj,i); if(i == 0 || maxv < r->width*r->height){ - maxv = r->width*r->height; R.x = r->x*_img_scale; R.y = r->y*_img_scale; - R.width = r->width*_img_scale; R.height = r->height*_img_scale; + maxv = r->width*r->height; R.x = (int) (r->x*_img_scale); R.y = (int) (r->y*_img_scale); + R.width = (int) (r->width*_img_scale); R.height = (int) (r->height*_img_scale); } } cvRelease((void**)(&obj)); return R; @@ -384,10 +386,10 @@ cv::Rect SInit::ReDetect(cv::Mat &im) if(temp_.rows == 0)return cv::Rect(); int x,y; float v,vb=-2; int ww = im.cols,hh = im.rows; - int w = TSCALE*ww-temp_.cols+1,h = TSCALE*hh-temp_.rows+1; + int w = (int) (TSCALE*ww-temp_.cols+1),h = (int) (TSCALE*hh-temp_.rows+1); if((small_.rows != TSCALE*hh) || (small_.cols != TSCALE*ww)) - small_.create(TSCALE*hh,TSCALE*ww,CV_8U); - cv::resize(im,small_,cv::Size(TSCALE*ww,TSCALE*hh),0,0,CV_INTER_LINEAR); + small_.create((int)(TSCALE*hh),(int)(TSCALE*ww),CV_8U); + cv::resize(im,small_,cv::Size((int)(TSCALE*ww),(int)(TSCALE*hh)),0,0,CV_INTER_LINEAR); if((ncc_.rows != h) || (ncc_.cols != w))ncc_.create(h,w,CV_32F); IplImage im_o = small_,temp_o = temp_,ncc_o = ncc_; cvMatchTemplate(&im_o,&temp_o,&ncc_o,CV_TM_CCOEFF_NORMED); @@ -398,8 +400,8 @@ cv::Rect SInit::ReDetect(cv::Mat &im) v = *p++; if(v > vb){vb = v; R.x = x; R.y = y;} } } - R.x *= 1.0/TSCALE; R.y *= 1.0/TSCALE; - R.width *= 1.0/TSCALE; R.height *= 1.0/TSCALE; return R; + R.x = (int) (R.x * 1.0/TSCALE); R.y = (int) (R.y * 1.0/TSCALE); + R.width = (int) (R.width * 1.0/TSCALE); R.height = (int) (R.height * 1.0/TSCALE); return R; } //=========================================================================== cv::Rect SInit::Update(cv::Mat &im,cv::Mat &s,bool rsize) @@ -418,18 +420,18 @@ cv::Rect SInit::Update(cv::Mat &im,cv::Mat &s,bool rsize) return cv::Rect(0,0,0,0); else{ xmin *= TSCALE; ymin *= TSCALE; xmax *= TSCALE; ymax *= TSCALE; - cv::Rect R = cv::Rect(std::floor(xmin),std::floor(ymin), - std::ceil(xmax-xmin),std::ceil(ymax-ymin)); + cv::Rect R = cv::Rect((int)std::floor(xmin), (int)std::floor(ymin), + (int)std::ceil(xmax-xmin), (int)std::ceil(ymax-ymin)); int ww = im.cols,hh = im.rows; if(rsize){ if((small_.rows != TSCALE*hh) || (small_.cols != TSCALE*ww)) - small_.create(TSCALE*hh,TSCALE*ww,CV_8U); - cv::resize(im,small_,cv::Size(TSCALE*ww,TSCALE*hh),0,0,CV_INTER_LINEAR); + small_.create((int)(TSCALE*hh), (int)(TSCALE*ww),CV_8U); + cv::resize(im,small_,cv::Size((int)(TSCALE*ww), (int)(TSCALE*hh)),0,0,CV_INTER_LINEAR); } - cv::resize(im,small_,cv::Size(TSCALE*ww,TSCALE*hh),0,0,CV_INTER_LINEAR); + cv::resize(im,small_,cv::Size((int)(TSCALE*ww), (int)(TSCALE*hh)),0,0,CV_INTER_LINEAR); temp_ = small_(R).clone(); - R.x *= 1.0/TSCALE; R.y *= 1.0/TSCALE; - R.width *= 1.0/TSCALE; R.height *= 1.0/TSCALE; return R; + R.x = (int) (R.x * 1.0/TSCALE); R.y = (int) (R.y * 1.0/TSCALE); + R.width = (int) (R.width * 1.0/TSCALE); R.height = (int) (R.height * 1.0/TSCALE); return R; } } //=========================================================================== diff --git a/src/tracker/FaceTracker.cpp b/src/tracker/FaceTracker.cpp index 88cdec4..a8888d6 100644 --- a/src/tracker/FaceTracker.cpp +++ b/src/tracker/FaceTracker.cpp @@ -16,7 +16,7 @@ // most directory of the source code. // Copyright CSIRO 2013 - +#include #include #include #include diff --git a/src/tracker/FaceTracker.hpp b/src/tracker/FaceTracker.hpp index 7b50459..2add188 100644 --- a/src/tracker/FaceTracker.hpp +++ b/src/tracker/FaceTracker.hpp @@ -19,6 +19,12 @@ #ifndef _TRACKER_FaceTracker_h_ #define _TRACKER_FaceTracker_h_ + +#ifdef _WIN32 + #include +#endif + +#include #include namespace FACETRACKER { @@ -54,7 +60,11 @@ namespace FACETRACKER void write_fps(cv::Mat &im){ //image to draw FPS on top left corner char str[256]; +#ifdef _WIN32 + sprintf_s(str, 256, "Tracker: %d fps", (int) round(_fps)); std::string text = str; +#else sprintf(str,"Tracker: %d fps",(int)round(_fps)); std::string text = str; +#endif cv::putText(im,text,cv::Point(10,im.rows-20), CV_FONT_HERSHEY_SIMPLEX,0.5,CV_RGB(255,255,255)); return; } diff --git a/src/tracker/IO.cpp b/src/tracker/IO.cpp index d6d3519..0c6974d 100644 --- a/src/tracker/IO.cpp +++ b/src/tracker/IO.cpp @@ -19,6 +19,7 @@ #include #include +#include using namespace FACETRACKER; using namespace std; //=========================================================================== @@ -237,7 +238,7 @@ void IOBinary::ReadMat(std::ifstream &s, cv::Mat &M) s.read((char*)&c, sizeof(int)); s.read((char*)&t, sizeof(int)); M = cv::Mat(r,c,t); - s.read(reinterpret_cast(M.datastart), M.total()*M.elemSize()); + s.read((char*)(M.datastart), M.total()*M.elemSize()); if(!s.good()){ std::cout << "Error reading matrix" << std::endl; @@ -250,11 +251,11 @@ void IOBinary::WriteMat(std::ofstream &s, cv::Mat &M) { assert(M.isContinuous() && !M.isSubmatrix()); int t = M.type(); - s.write(reinterpret_cast(&M.rows), sizeof(int)); - s.write(reinterpret_cast(&M.cols), sizeof(int)); - s.write(reinterpret_cast(&t), sizeof(int)); + s.write(reinterpret_cast(&M.rows), sizeof(int)); + s.write(reinterpret_cast(&M.cols), sizeof(int)); + s.write(reinterpret_cast(&t), sizeof(int)); // s << M.rows << " " << M.cols << " " << M.type(); - s.write(reinterpret_cast(M.datastart), M.total()*M.elemSize()); + s.write((char*)(M.datastart), M.total()*M.elemSize()); // std::cout << "Mat written: "<< M.rows << "x"<< M.cols << ", type " << M.type() << std::endl; diff --git a/src/tracker/Patch.cpp b/src/tracker/Patch.cpp index f1cb068..c5b637e 100644 --- a/src/tracker/Patch.cpp +++ b/src/tracker/Patch.cpp @@ -17,6 +17,8 @@ // Copyright CSIRO 2013 +#include +#include #include #define SGN(x) ((x<0) ? 0:1) using namespace FACETRACKER; @@ -78,7 +80,7 @@ void LBP(cv::Mat &im,cv::Mat &lbp) v[4] = *p2++; v[0] = *p2++; v[5] = *p2; v[1] = *p1++; v[2] = *p1++; v[3] = *p1; v[6] = *p3++; v[7] = *p3++; v[8] = *p3; - *lp++ = + *lp++ = (float) SGN(v[0]-v[1])*2 + SGN(v[0]-v[2])*4 + SGN(v[0]-v[3])*8 + SGN(v[0]-v[4])*16 + SGN(v[0]-v[5])*32 + SGN(v[0]-v[6])*64 + diff --git a/src/tracker/RegistrationCheck.cpp b/src/tracker/RegistrationCheck.cpp index ef057c5..02bf6f9 100644 --- a/src/tracker/RegistrationCheck.cpp +++ b/src/tracker/RegistrationCheck.cpp @@ -17,6 +17,8 @@ // Copyright CSIRO 2013 +#include +#include #include using namespace FACETRACKER; using namespace std; diff --git a/src/tracker/ShapePredictor.cpp b/src/tracker/ShapePredictor.cpp index e65655d..f789b9d 100644 --- a/src/tracker/ShapePredictor.cpp +++ b/src/tracker/ShapePredictor.cpp @@ -16,7 +16,8 @@ // most directory of the source code. // Copyright CSIRO 2013 - +#include +#include #include #include #define db at @@ -31,9 +32,9 @@ ShapePredictor& ShapePredictor::operator= (ShapePredictor const&rhs) _rect = rhs._rect; _pdm = rhs._pdm; _warp = rhs._warp; - _C.resize(_K); _R.resize(_K); + _CC.resize(_K); _R.resize(_K); for(int i = 0; i < _K; i++){ - _C[i] = rhs._C[i].clone(); + _CC[i] = rhs._CC[i].clone(); _R[i] = rhs._R[i].clone(); } x_.create(_warp._nPix+1,1,CV_64F); @@ -66,9 +67,9 @@ void ShapePredictor::Save(const char* fname, bool binary) //============================================================================== void ShapePredictor::Read(ifstream &s) { - s >> _K; _C.resize(_K); _R.resize(_K); + s >> _K; _CC.resize(_K); _R.resize(_K); for(int i = 0; i < _K; i++){ - FACETRACKER::IO::ReadMat(s,_C[i]); + FACETRACKER::IO::ReadMat(s,_CC[i]); FACETRACKER::IO::ReadMat(s,_R[i]); } FACETRACKER::IO::ReadMat(s,_idx); @@ -91,9 +92,9 @@ void ShapePredictor::ReadBinary(ifstream &s, bool readType) } s.read(reinterpret_cast(&_K), sizeof(_K)); - _C.resize(_K); _R.resize(_K); + _CC.resize(_K); _R.resize(_K); for(int i = 0; i < _K; i++){ - FACETRACKER::IOBinary::ReadMat(s,_C[i]); + FACETRACKER::IOBinary::ReadMat(s,_CC[i]); FACETRACKER::IOBinary::ReadMat(s,_R[i]); } FACETRACKER::IOBinary::ReadMat(s,_idx); @@ -112,7 +113,7 @@ void ShapePredictor::Write(ofstream &s, bool binary) if(!binary){ s << _K << " "; for(int i = 0; i < _K; i++){ - FACETRACKER::IO::WriteMat(s,_C[i]); + FACETRACKER::IO::WriteMat(s,_CC[i]); FACETRACKER::IO::WriteMat(s,_R[i]); } FACETRACKER::IO::WriteMat(s,_idx); @@ -125,7 +126,7 @@ void ShapePredictor::Write(ofstream &s, bool binary) s.write(reinterpret_cast(&t), sizeof(t)); s.write(reinterpret_cast(&_K), sizeof(_K)); for(int i = 0; i < _K; i++){ - FACETRACKER::IOBinary::WriteMat(s,_C[i]); + FACETRACKER::IOBinary::WriteMat(s,_CC[i]); FACETRACKER::IOBinary::WriteMat(s,_R[i]); } FACETRACKER::IOBinary::WriteMat(s,_idx); @@ -162,11 +163,11 @@ int ShapePredictor::FindCluster(cv::Mat &shape) } double a1,b1,tx1,ty1,a2,b2,tx2,ty2,v,vmin = 0; int l = -1; cv::Mat S; for(int k = 0; k < _K; k++){ - FACETRACKER::CalcSimT(_C[k],z_,a1,b1,tx1,ty1); + FACETRACKER::CalcSimT(_CC[k],z_,a1,b1,tx1,ty1); FACETRACKER::invSimT(a1,b1,tx1,ty1,a2,b2,tx2,ty2); z_.copyTo(y_); FACETRACKER::SimT(y_,a2,b2,tx2,ty2); - v = cv::norm(y_,_C[k]); + v = cv::norm(y_,_CC[k]); if((v < vmin) || (l < 0)){vmin = v; l = k;} }return l; } diff --git a/src/tracker/ShapePredictor.hpp b/src/tracker/ShapePredictor.hpp index 0456ddd..7987a89 100644 --- a/src/tracker/ShapePredictor.hpp +++ b/src/tracker/ShapePredictor.hpp @@ -31,7 +31,7 @@ namespace FACETRACKER cv::Rect _rect; FACETRACKER::PDM2D _pdm; FACETRACKER::PAW _warp; - std::vector _C,_R; + std::vector _CC,_R; ShapePredictor(){;} ShapePredictor(const char* fname, bool binary = false){this->Load(fname, binary);} diff --git a/src/tracker/Warp.cpp b/src/tracker/Warp.cpp index 308a0c1..e62c975 100644 --- a/src/tracker/Warp.cpp +++ b/src/tracker/Warp.cpp @@ -17,6 +17,8 @@ // Copyright CSIRO 2013 +#include +#include #include #define it at #define db at @@ -58,6 +60,14 @@ double FACETRACKER::bilinInterp(cv::Mat& I,const double x,const double y) if(x < 0 || x >= I.cols || y < 0 || y >= I.rows)return 0; int x1 = (int)std::floor(x),y1 = (int)std::floor(y); int x2 = (int)std::ceil(x) ,y2 = (int)std::ceil(y); + + // This check avoids an assertion (in DEBUG) or crash (in RELEASE) if the ceiling + // in x2/y2 exceeds the size of the image + if (x2 >= I.cols) + x2 = I.cols - 1; + if (y2 >= I.rows) + y2 = I.rows - 1; + if(x1 == x2){ if(y1 == y2)return (double)I.at(y1,x1); else return (double(y2)-y)*I.at(y1,x1) + diff --git a/src/tracker/myFaceTracker.cpp b/src/tracker/myFaceTracker.cpp index 091581e..c7ea653 100644 --- a/src/tracker/myFaceTracker.cpp +++ b/src/tracker/myFaceTracker.cpp @@ -17,6 +17,8 @@ // Copyright CSIRO 2013 +#include +#include #include #define it at #define db at @@ -243,7 +245,7 @@ void myFaceTrackerParams::Load(const char* fname, bool binary) >> gamma >> init_type >> track_type - >> t; shape_predict = t; + >> t; shape_predict = (t != 0); file >> t; init_wSize.resize(t); for(int i = 0; i < int(init_wSize.size()); i++)file >> init_wSize[i]; file >> t; track_wSize.resize(t); @@ -463,7 +465,7 @@ myFaceTracker::NewFrame(cv::Mat &im, else{ if(_atm._scale == 1)smooth_ = gray_; else{ - cv::Size ksize((1.0/_atm._scale)*3+1,(1.0/_atm._scale)*3+1); + cv::Size ksize((int) ((1.0/_atm._scale)*3+1), (int) ((1.0/_atm._scale)*3+1)); cv::GaussianBlur(gray_,smooth_,ksize,0,0); } vector visi; @@ -543,7 +545,7 @@ myFaceTracker::NewFrame(cv::Mat &im, if (_atm._scale == 1) { smooth_ = gray_; } else { - cv::Size ksize((1.0/p->atm_scale)*3+1,(1.0/p->atm_scale)*3+1); + cv::Size ksize((int) ((1.0/p->atm_scale)*3+1), (int) ((1.0/p->atm_scale)*3+1)); cv::GaussianBlur(gray_,smooth_,ksize,0,0); } _atm.Init(p->center,pose,_shape,smooth_,p->atm_tri,p->atm_scale); diff --git a/src/utils/CMakeLists.txt b/src/utils/CMakeLists.txt index 3031a1f..722c4db 100644 --- a/src/utils/CMakeLists.txt +++ b/src/utils/CMakeLists.txt @@ -1,6 +1,23 @@ +if(WIN32) + set(LIBTYPE STATIC) + + # Shlwapi.lib is the lib required by PathRemoveFileSpec and PathStripPath + # used in helpers.cpp to replace dirname and basename in Windows + set(EXTRALIBS "Shlwapi.lib") +else() + set(LIBTYPE SHARED) + set(EXTRALIBS "") +endif() + add_library(utilities - SHARED + ${LIBTYPE} command-line-arguments.cpp helpers.cpp points.cpp) -target_link_libraries(utilities ${LIBS}) + +set_target_properties(utilities PROPERTIES DEBUG_POSTFIX "d") + +target_link_libraries(utilities ${LIBS} ${EXTRALIBS}) + +install(TARGETS utilities EXPORT CSIRO DESTINATION lib) +install(FILES points.hpp DESTINATION include/utils) \ No newline at end of file diff --git a/src/utils/helpers.cpp b/src/utils/helpers.cpp index feb1f39..2e16b14 100644 --- a/src/utils/helpers.cpp +++ b/src/utils/helpers.cpp @@ -19,11 +19,23 @@ #include "helpers.hpp" #include + +#ifdef _WIN32 +#define NOMINMAX +#include +#include "Shlwapi.h" +#else #include +#endif + #include #include #include #include +#include +#include +#include +#include bool nan_p(double value) @@ -276,19 +288,37 @@ pathname_name(const std::string &pathname) std::string pathname_directory(const std::string &pathname) { - char buffer[pathname.size() + 1]; - memset(buffer, 0, sizeof(buffer)); - std::copy(pathname.begin(), pathname.end(), buffer); - return std::string(dirname(buffer)); +#ifdef _WIN32 + char *buffer = new char[pathname.size() + 1]; + memset(buffer, 0, pathname.size() + 1); + PathRemoveFileSpec(buffer); + std::string ret = std::string(buffer); + delete[] buffer; + return ret; +#else + char buffer[pathname.size() + 1]; + memset(buffer, 0, sizeof(buffer)); + std::copy(pathname.begin(), pathname.end(), buffer); + return std::string(dirname(buffer)); +#endif } std::string pathname_sans_directory(const std::string &pathname) { +#ifdef _WIN32 + char *buffer = new char[pathname.size() + 1]; + memset(buffer, 0, pathname.size() + 1); + PathStripPath(buffer); + std::string ret = std::string(buffer); + delete[] buffer; + return ret; +#else char buffer[pathname.size() + 1]; memset(buffer, 0, sizeof(buffer)); std::copy(pathname.begin(), pathname.end(), buffer); return std::string(basename(buffer)); +#endif } std::string diff --git a/src/utils/helpers.hpp b/src/utils/helpers.hpp index 08f71f5..56b7f1a 100644 --- a/src/utils/helpers.hpp +++ b/src/utils/helpers.hpp @@ -24,6 +24,7 @@ #include #include #include +#include //fixes issue with va_args /** Evaluates predicate on all items within the range (begin,end) until predicate is false, otherwise returns true. */