最近在学习深度学习,刚好中科视拓开源了SeetaFace2.0的源码,于是从github下载下来,学习一下
源码的位置:
https://github.com/seetafaceengine/SeetaFace2
点击上面的源码链接进行下载,下载之后的压缩包为SeetaFace2-master.zip
解压之后,会在SeetaFace2-master目录下看到 README.md文档,根据文档指引完成初始编译
文档中说明,如果要编译example 需要准备好opencv环境,于是开始找到最新的opencv 源代码包
opencv 下载包,链接:https://opencv.org/releases/
我选择了最新的4.1.1版本,同时需要去下载opencv_contrib-4.1.1.zip,
下载地址:https://github.com/opencv/opencv_contrib/releases
下载好之后,把两个zip放在同级目录开始安装,这里我新建了一个目录,方便管理
mkdir opencv4.1
cd opencv4.1
mv ../../opencv-4.1.1.zip ../../opencv_contrib-4.1.1.zip .
unzip opencv-4.1.1.zip
unzip opencv_contrib-4.1.1.zip
mv opencv-4.1.1 opencv
mv opencv_crontrib-4.1.1 opencv_crontrib
进入opencv目录开始编译,这里添加了扩展模块opencv_crontrib的编译,命令如下:
cd opencv
mkdir build
cd build
cmake -D CMAKE_BUILD_TYPE=Release -D CMAKE_INSTALL_PREFIX=/usr/local -D OPENCV_EXTRA_MODULES_PATH=../../opencv_contrib/modules -D OPENCV_GENERATE_PKGCONFIG=YES -D WITH_1394=ON ..
完成之后,执行make 进行编译,我使用 make -j2 毕竟电脑性能一般,使用make -j8 会直接卡死(已尝试,性能好的可以尝试哈,会快一些)
完成之后执行 sudo make install
再执行 sudo ldconfig
然后添加环境变量PKG_CONFIG_PATH
到~/.bashrc
PKG_CONFIG_PATH="/usr/lib/x86_64-linux-gnu/pkgconfig"
export PKG_CONFIG_PATH=$PKG_CONFIG_PATH:/usr/local/lib/pkgconfig
保存之后,执行source .bashrc
通过编译一个例子程序来验证安装成功。
$ cd ..
$ cd opencv/samples/cpp/example_cmake
$ cmake .
$ make
这里出现错误了
错误如下:
Scanning dependencies of target opencv_example
[ 50%] Building CXX object CMakeFiles/opencv_example.dir/example.cpp.o
[100%] Linking CXX executable opencv_example
//usr/lib/libgdal.so.20: undefined reference to `sqlite3_column_origin_name'
//usr/lib/libgdal.so.20: undefined reference to `sqlite3_column_table_name'
collect2: error: ld returned 1 exit status
CMakeFiles/opencv_example.dir/build.make:135: recipe for target 'opencv_example' failed
make[2]: *** [opencv_example] Error 1
CMakeFiles/Makefile2:67: recipe for target 'CMakeFiles/opencv_example.dir/all' failed
make[1]: *** [CMakeFiles/opencv_example.dir/all] Error 2
Makefile:83: recipe for target 'all' failed
make: *** [all] Error 2
查找了各种帖子没有解决,最后觉得可能是opencv 版本不对或者冲突,于是查看opencv的版本
执行如下命令
pkg-config --modversion opencv
显示的是 3.2
问题就在这里了,我安装的是4.1.1 不是这个版本,于是先把就的卸载
sudo apt-get remove --prue libopencv-dev
然后修改opencv.pc为新版本的
sudo cp /usr/local/lib/pkgconfig/opencv4.pc /usr/lib/x86_64-linux-gnu/pkgconfig/opencv.pc
完成之后再查看opencv的版本
pkg-config --modversion opencv 显示的是4.1.1 ,OK
继续调试,发现错误没有解决,于是我把usr/lib/libgdal.so.20 这个文件 重命名usr/lib/libgdal.so.20-bk
编译提示,需要链接opecv的库文件,于是做如下操作
sudo ln -s /usr/local/lib/libopencv_core.so.4.1 /usr/lib/libgdal.so.20
android@U-NSGWD180025:/$ ll /usr/lib/libgdal.so.20
lrwxrwxrwx 1 root root 36 Sep 5 16:16 /usr/lib/libgdal.so.20 -> /usr/local/lib/libopencv_core.so.4.1
再进行测试,结果OK
android@U-NSGWD180025:/data/tools/opencv4.1.1/opencv/samples/cpp/example_cmake$ make
Scanning dependencies of target opencv_example
[ 50%] Building CXX object CMakeFiles/opencv_example.dir/example.cpp.o
[100%] Linking CXX executable opencv_example
[100%] Built target opencv_example
结果编译成功,产生了bin目录并生成了 对应的可执行文件
cd SeetaFace2-master
mkdir build
cd build
cmake .. -DCMAKE_INSTALL_PREFIX=`pwd`/install -DBUILD_EXAMPLE=ON # 如果有 OpenCV,则设置为 ON
cmake --build .
android@U-NSGWD180025:/data/workspace/MYNOTE/FaceRecognition/SeetaFace2-master/build$ cmake --build .
-- == BUILD_VERSION: v2.5.5
-- Found OpenCV: /usr/local (found version "4.1.1")
-- == Build detector: ON
-- == Build landmarker: ON
-- == Build recgnizer: ON
-- == Build example: ON
-- == Build shared library: ON
-- == PLATFORM: x86_64
-- Configuring done
-- Generating done
-- Build files have been written to: /data/workspace/MYNOTE/FaceRecognition/SeetaFace2-master/build
[ 36%] Built target SeetaNet
[ 52%] Built target SeetaFaceDetector
[ 68%] Built target SeetaFaceLandmarker
[ 89%] Built target SeetaFaceRecognizer
Scanning dependencies of target points81
[ 92%] Building CXX object example/points81/CMakeFiles/points81.dir/example.cpp.o
[ 94%] Linking CXX executable ../../bin/points81
[ 94%] Built target points81
Scanning dependencies of target search
[ 97%] Building CXX object example/search/CMakeFiles/search.dir/example.cpp.o
[100%] Linking CXX executable ../../bin/search
[100%] Built target search
android@U-NSGWD180025:/data/workspace/MYNOTE/FaceRecognition/SeetaFace2-master/build/bin$ ll
total 280
drwxr-xr-x 3 android android 4096 Sep 5 16:59 ./
drwxr-xr-x 11 android android 4096 Sep 5 17:50 ../
drwxr-xr-x 2 android android 4096 Sep 5 16:59 model/
lrwxrwxrwx 1 android android 15 Sep 5 16:25 points81 -> points81-v2.5.5*
-rwxr-xr-x 1 android android 92408 Sep 5 16:25 points81-v2.5.5*
lrwxrwxrwx 1 android android 13 Sep 5 16:25 search -> search-v2.5.5*
-rwxr-xr-x 1 android android 179008 Sep 5 16:25 search-v2.5.5*
android@U-NSGWD180025:/data/workspace/MYNOTE/FaceRecognition/SeetaFace2-master/build/bin$
接下来就下载模型进行测试,这部分也有给出的,可以下载使用,总之上面的错误困扰了我两天,记录下来~
为了更好地让开发者继续开发工作,官方已提供下载模型的渠道:
1. 人脸检测模块 FaceDetector 模型下载链接:
2. 面部特征 5 点定位模块 FaceLandmarker 模型下载链接:
3. 面部特征 81 点定位模块 FaceLandmarker 模型下载链接:
4. 人脸特征提取和比对模块 FaceRecognizer 模型下载链接: