前言:
dlib是
1. dlib编译与安装
类似与opencv 现在安装只需要sudo apt-get install libdlib-dev, 会安装到/usr/lib下,但是安装过程中出现错误,libdlib.a没有安装成功,推荐使用源码安装。卸载使用sudo apt-get remove libdlib-dev,但是”/usr/lib/cmake/dlib/dlib.cmake”不会卸载干净。
从源码安装dlib,下载项目,解压
在CMakeLists.txt中添加PIC(position independent code)编译选项,详见2
cd dlib-master/dlib
mkdir build&&cd build
cmake ..
sudo make install
默认安装到 /usr/local/include 和 /usr/local/lib下
gazr的编译
项目地址在
https://github.com/severin-lemaignan/gazr
提供了ros接口,和demo的编译,可以自行选择
option(DEBUG_OUTPUT "Enable debug visualizations" OFF)
option(WITH_TOOLS "Compile sample tools" ON)
option(WITH_ROS "Build ROS nodes" OFF)
然后设置dlib的路径,在find_package(dlib REQUIRED)
之前添加
set(CMAKE_PREFIX_PATH /usr/local/lib/cmake/dlib/dlib.cmake)
遇到的问题
:/usr/bin/ld: /usr/local/lib/libdlib.a(base64_kernel_1.cpp.o): relocation R_X86_64_32S against `_ZTVN4dlib6base64E’ can not be used when making a shared object; recompile with -fPIC
Do what the compiler tells you to do, i.e. recompile with -fPIC. To learn what does this flag do and why you need it in this case, see Code Generation Options of the GCC manual.
In brief, the term position independent code (PIC) refers to the generated machine code which is memory address agnostic, i.e. does not make any assumptions about where it was loaded into RAM. Only position independent code is supposed to be included into shared objects (SO) as they should have an ability to dynamically change their location in RAM.
Finally, you can read about it on Wikipedia too.
简而言之,PIC使生成的机器码在运行过程中所在RAM中的位置无关,只有PIC的代码可以被包含进动态链接库,后者在运行的时候内存中位置是会发生变化的。
解决方法在编译dlib的时候在CMakeLists.txt中
target_include_directories(dlib
INTERFACE $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/..>
INTERFACE $<INSTALL_INTERFACE:include>
PUBLIC ${dlib_needed_includes}
)
target_link_libraries(dlib PRIVATE ${dlib_needed_libraries})
// 添加下面这行
set_target_properties(dlib PROPERTIES POSITION_INDEPENDENT_CODE ON)
编译
mkdir build&&cd build
cmake ..
make..
运行摄像头的demo
./gazr_estimate_head_direction --model ../share/shape_predictor_68_face_landmarks.dat --show
todo: 笔记本上landmark检测的速度在200×200的图上500ms,实现有问题。