一、Ubuntu端试玩dlib
源码下载:
wget http://dlib.net/files/dlib-19.18.tar.bz2
使用cmake进行编译。
1.1 编译gcc版本dlib
- unzip dlib-19.18.zip
- cd dlib-19.18/
- mkdir build
- cd build
- cmake ..
- make -j 8 release=1
编译成功
[100%] Linking CXX static library libdlib.a
[100%] Built target dlib
1.2 编译example
- cd examples
- mkdir build
- cd build
- cmake ..
- cmake --build . --config Release
后续编译只需要修改代码,然后直接make -j 8
但是感觉速度也不是很快,链接比较耗时间。
1.3 微软ResNet模型与特征提取模型下载
下载地址:
wget http://dlib.net/files/shape_predictor_5_face_landmarks.dat.bz2
wget http://dlib.net/files/shape_predictor_68_face_landmarks.dat.bz2
wget http://dlib.net/files/dlib_face_recognition_resnet_model_v1.dat.bz2
bz2后缀文件解压命令
bzip2 -d shape_predictor_5_face_landmarks.dat.bz2
参考 https://blog.csdn.net/changkaibo/article/details/80091816
1.4 简单实例试玩
dnn_face_recognition_ex 人脸检测还支持人脸对齐。
face_landmark_detection_ex
二、cmake交叉编译dlib
终端命令行进入build目录后,执行cmake-gui进行配置。
2.1 cmake-gui配置
设置好源码路径与交叉编译器路径后点击configure、generate。最后关闭cmake-gui,执行make -j 8即可编译。
出现错误:
Using CMake version: 3.5.1
Compiling dlib version: 19.18.0
CMake Error at dlib/cmake_utils/set_compiler_specific_options.cmake:50 (message):
C++11 is required to use dlib, but the version of GCC you are using is too
old and doesn't support C++11. You need GCC 4.8 or newer.
Call Stack (most recent call first):
dlib/CMakeLists.txt:30 (include)
原先的交叉编译器版本:
arm-hisiv100nptl-linux-gcc (Hisilicon_v100(gcc4.4-290+uclibc_0.9.32.1+eabi+linuxpthread)) 4.4.1 不支持c++11。
解决办法:
使用高版本编译器
arm-hisiv300-linux-gcc (Hisilicon_v300) 4.8.3 20131202 (prerelease)
Copyright (C) 2013 Free Software Foundation, Inc.
2.2 交叉编译dlib静态库出现错误
错误1:
/home/workspace/project/EC20/my_git_bak/TestRepo/cwr/face/demo/arm_cross_dlib/dlib-19.18/dlib/bigint/../serialize.h:1635:25: error: ‘to_string’ is not a member of ‘std’
std::to_string(objects_read+1) + "th object from the file " + filename +
^
make[2]: *** [dlib/CMakeFiles/dlib.dir/bigint/bigint_kernel_1.cpp.obj] Error 1
make[1]: *** [dlib/CMakeFiles/dlib.dir/all] Error 2
解决办法:
在dlib根目录CMakeLists.txt 添加add_compile_options(-D_GLIBCXX_USE_C99)
错误2:
/home/workspace/project/EC20/my_git_bak/TestRepo/cwr/face/demo/arm_cross_dlib/dlib-19.18/dlib/data_io/../geometry/rectangle.h:658:24: error: ‘round’ is not a member of ‘std’
long l = (long)std::round(rect.left()*scale);
解决办法:
由于海思编译器对c++11支持不是很友好,在dlib/geometry/rectangle.h中修改,重新声明个round。
namespace std
{
double round(double f);
float erfc(float f);
}
编译成功
2.3 交叉编译example出现的错误
在example目录下创建arm_build
进入arm_build 使用camke-gui来进行设置交叉编译器
cmake-gui配置内容,只设置好example源码路径和arm_build目录,设置好CMAKE_INSTALL_PREFIX路径,其他默认就好。
出现与编译libdlib.a静态库一样的错误。
[ 3%] Building CXX object dlib_build/CMakeFiles/dlib.dir/entropy_decoder/entropy_decoder_kernel_2.cpp.obj
In file included from /home/workspace/test/tmp/dlib-19.18/dlib/bigint/bigint_kernel_1.h:8:0,
from /home/workspace/test/tmp/dlib-19.18/dlib/bigint/bigint_kernel_1.cpp:5:
/home/workspace/test/tmp/dlib-19.18/dlib/bigint/../serialize.h: In member function ‘dlib::proxy_deserialize& dlib::proxy_deserialize::doit(T&&)’:
/home/workspace/test/tmp/dlib-19.18/dlib/bigint/../serialize.h:1635:25: error: ‘to_string’ is not a member of ‘std’
std::to_string(objects_read+1) + "th object from the file " + filename +
参考静态库编译错误的解决办法,只不过修改的CMakeLists.txt是在example目录下的.
出现新的问题:
[ 49%] Linking CXX executable threads_ex
dlib_build/libdlib.a(threads_kernel_2.cpp.obj): In function `dlib::threads_kernel_shared_helpers::thread_starter(void*)':
threads_kernel_2.cpp:(.text+0x14): undefined reference to `pthread_detach'
dlib_build/libdlib.a(threads_kernel_2.cpp.obj): In function `dlib::threads_kernel_shared_helpers::spawn_thread(void (*)(void*), void*)':
threads_kernel_2.cpp:(.text+0x58): undefined reference to `pthread_create'
collect2: error: ld returned 1 exit status
make[2]: *** [timer_ex] Error 1
make[1]: *** [CMakeFiles/timer_ex.dir/all] Error 2
make[1]: *** Waiting for unfinished jobs....
解决办法:
在arm_build的目录下修改CMakeCache.txt文件
在/CXX compiler与C compiler下添加-lpthread选项。
参考:
ubuntu14.04 + dlib19.2 - https://www.jianshu.com/p/653967b87031