OpenFace编译遇到的各种问题

9 篇文章 0 订阅

又重新配了一次OpenFace的环境,各种问题,费了不少功夫
各个依赖项参考原作者github上的环境配置指南:https://github.com/TadasBaltrusaitis/OpenFace/wiki/Unix-Installation
然后各种bug和解决方法记录在下面,我编译的这个包不是目前最新版本的那个包,新版的有一些地方更新了,我们项目对这个包进行了一定程度的扩展。大家遇到的问题不一定一样,希望能提供一些启发。
2020.11.30


问题

1.调用Python.h 头文件报错

提示说找不到,我们拓展了一部分代码,加入了另外一些功能,用Python写的,所以需要考虑c++调用python的问题,可以参考另一篇CSDN博客,点这里
解决:用locate定位Python.h的位置,然后把绝对路径弄上去。
我之前试过调用没出现这个问题,迷惑,不知道怎么又出现这个问题,望有大佬路过,提点一下

#include <Python.h>

修改后解决:

#include </home/will/anaconda3/envs/openface/include/python3.6m/Python.h>

2.调用openblas_config.h 头文件报错

在编译landmarkDEtector时,需要用到openblas提示找不到,也是路径问题,感觉这些可能是我Linux系统设置有问题,有没有路过的大神,指点一下,不然一直要用绝对路径,挺麻烦的,不利于移植
解决:
找到openface文件夹下的lib/local/LandmarkDetector/stdafx.h头文件,打开,先用locate找到openblas_config.h的位置,然后修改:

#include <openblas_config.h>

改为:

#include </usr/include/openblas/openblas_config.h>

3.调用libtiff报错,未定义4.0 …

在编译Utilities时报错,关于libtiff库的问题,

报错如下:

 /usr/lib/libopencv_highgui.so.2.4: undefined reference to TIFFIsTiled@LIBTIFF_4.0' 
 /usr/lib/libopencv_highgui.so.2.4: undefined reference toTIFFOpen@LIBTIFF_4.0' 
 /usr/lib/libopencv_highgui.so.2.4: undefined reference to TIFFReadEncodedStrip@LIBTIFF_4.0'   
 /usr/lib/libopencv_highgui.so.2.4: undefined reference toTIFFSetField@LIBTIFF_4.0' 
 /usr/lib/libopencv_highgui.so.2.4: undefined reference to TIFFWriteScanline@LIBTIFF_4.0' 
 /usr/lib/libopencv_highgui.so.2.4: undefined reference toTIFFGetField@LIBTIFF_4.0' 
 /usr/lib/libopencv_highgui.so.2.4: undefined reference to TIFFScanlineSize@LIBTIFF_4.0' 
 /usr/lib/libopencv_highgui.so.2.4: undefined reference toTIFFSetWarningHandler@LIBTIFF_4.0' 
 /usr/lib/libopencv_highgui.so.2.4: undefined reference to TIFFSetErrorHandler@LIBTIFF_4.0' 
 /usr/lib/libopencv_highgui.so.2.4: undefined reference toTIFFReadEncodedTile@LIBTIFF_4.0' 
 /usr/lib/libopencv_highgui.so.2.4: undefined reference to TIFFReadRGBATile@LIBTIFF_4.0' 
 /usr/lib/libopencv_highgui.so.2.4: undefined reference toTIFFClose@LIBTIFF_4.0' 
 /usr/lib/libopencv_highgui.so.2.4: undefined reference to TIFFRGBAImageOK@LIBTIFF_4.0' 
 /usr/lib/libopencv_highgui.so.2.4: undefined reference toTIFFReadRGBAStrip@LIBTIFF_4.0'

解决方法:
先定位这个libopencv_highgui.so库对应的链接位置:

ldd libopencv_highgui.so.2.4 | grep tiff

返回:

libtiff.so.5 => /usr/lib/x86_64-linux-gnu/libtiff.so.5

再把对应的路径地址添加到CMakeLists.txt中,即可,如下:

target_link_libraries(Utilities PUBLIC /usr/lib/x86_64-linux-gnu/libtiff.so.5 ${Boost_LIBRARIES} ${TBB_LIBRARIES})

修改完后,最好把build文件夹清空,然后重新cmake和make

rm -rf *
cmake -D CMAKE_CXX_COMPILER=g++-8 -D CMAKE_C_COMPILER=gcc-8 -D CMAKE_BUILD_TYPE=RELEASE ..
make

4.调用libgfortran报错

同样是卡在Utilities的问题,另一个库libgfortran出问题

[  4%] Built target LeastSquare
[ 35%] Built target LandmarkDetector
[ 52%] Built target FaceAnalyser
[ 56%] Built target GazeAnalyser
[ 75%] Built target Utilities
[ 77%] Linking CXX executable ../../bin/FaceLandmarkImg
/opt/OpenBLAS/lib/libopenblas.a(dgesvd.o): In function `dgesvd_':
dgesvd.f:(.text+0x364): undefined reference to `_gfortran_concat_string'
dgesvd.f:(.text+0xc2b): undefined reference to `_gfortran_concat_string'
/opt/OpenBLAS/lib/libopenblas.a(dormbr.o): In function `dormbr_':
dormbr.f:(.text+0x396): undefined reference to `_gfortran_concat_string'
dormbr.f:(.text+0x562): undefined reference to `_gfortran_concat_string'
dormbr.f:(.text+0x5c1): undefined reference to `_gfortran_concat_string'
/opt/OpenBLAS/lib/libopenblas.a(dormbr.o):dormbr.f:(.text+0x609): more undefined references to `_gfortran_concat_string' follow
collect2: error: ld returned 1 exit status
exe/FaceLandmarkImg/CMakeFiles/FaceLandmarkImg.dir/build.make:133: recipe for target 'bin/FaceLandmarkImg' failed
make[2]: *** [bin/FaceLandmarkImg] Error 1
CMakeFiles/Makefile2:422: recipe for target 'exe/FaceLandmarkImg/CMakeFiles/FaceLandmarkImg.dir/all' failed
make[1]: *** [exe/FaceLandmarkImg/CMakeFiles/FaceLandmarkImg.dir/all] Error 2
Makefile:148: recipe for target 'all' failed
make: *** [all] Error 2

解决方法:
先用locate找到libgfortran.a和libquadmath.a两个库的位置,然后添加他们的路径到CMakeLists.txt上去

target_link_libraries(Utilities PUBLIC dlib::dlib /usr/lib/gcc/x86_64-linux-gnu/5/libgfortran.a 
/usr/lib/gcc/x86_64-linux-gnu/5/libquadmath.a) #20201124

修改完后,最好把build文件夹清空,然后重新cmake和make

rm -rf *
cmake -D CMAKE_CXX_COMPILER=g++-8 -D CMAKE_C_COMPILER=gcc-8 -D CMAKE_BUILD_TYPE=RELEASE ..
make

5.遇到dylib库找到问题

这都是因为项目组里的人在macOS写的程序一部分Python程序,想通过c++调用,需要导入python的库,编译的时候发现提示找不到文件~/anaconda3//lib/libpython3.6m.dylib,这都是因为在macOS和Linux生成的libpython库的格式不一样,在CMakeLists.txt中改成~/anaconda3//lib/libpython3.6m.so即可

新get的知识,就是动态库在不同系统上的保存格式是不一样的,我跑的是一个在MacOS创建的项目,所以有些动态库在Linux上是找不到的,以后也要记住了

Windows系统的动态库是DLL文件,Linux系统是so文件,macOS系统的动态库则使用dylib文件作为动态库。

Other

命令行:
OpenFace/build中:
1)处理单张图片:

./bin/FaceLandmarkImg -f "../samples/sample3.jpg" -out_dir "/home/will/Videos/Gaze/new2"

-f:对应图片的路径
-out_dir:保存的路径
2)处理多张图片:

./bin/FaceLandmarkImg -fdir "/home/will/Videos/Gaze" -out_dir "/home/will/Videos/Gaze/new2"

-fdir:图片存在的文件夹路径
-out_dir:保存的路径
3)处理单/多个视频:

./bin/FaceLandmarkVid -f "/home/will/Videos/IMG_3755.MOV"

-f:对应视频的路径
在这里可以一次输入多个视频,继续添加-f即可:

./bin/FaceLandmarkVid -f "/home/will/Videos/IMG_3755.MOV" -f "/home/will/Videos/IMG_3756.MOV"

4)多人脸视频

./bin/FaceLandmarkVidMulti -f ../samples/multi_face.avi

-f:对应视频的路径

5)Webcam实时检测

./bin/FaceLandmarkVid -device 0

-device:选择使用的摄像头,默认是0号,即webcam,外设的话,依次递增
但是没有发现保存的参数,看了下作者的文档,好像也没有,可能需要自己改改了这部分。

Reference:
动态库:https://zhuanlan.zhihu.com/p/24875905

  • 1
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值