一、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 © 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