Ubuntu14.04 Seetaface安装和测试
@(工作相关)
本博文借鉴了SeetaFaceEngine安装和测试的文章,但是跟着该博文走下来,还是有些问题,在此记录一下,也算是对引用博文的补充和完善,希望能帮助到有需要的朋友;
一.介绍
必须安装好opencv
SeetaFace人脸识别引擎包括了搭建一套全自动人脸识别系统所需的三个核心模块,
即:人脸检测模块SeetaFace Detection、面部特征点定位模块SeetaFace Alignment以及人脸特征提取与比对模块 SeetaFace Identification。
主要功能:
1.人脸检测模块(SeetaFace Detection): 采用了一种结合传统人造特征与多层感知机(MLP)的级联结构,在FDDB上达到了84.4%的召回率(100个误检时),并可在单个i7 CPU上实时处理VGA分辨率的图像。
2.面部特征点定位模块(SeetaFace Alignment): 通过级联多个深度模型(栈式自编码网络)来回归5个关键特征点(两眼中心、鼻尖和两个嘴角)的位置,在AFLW数据库上达到state-of-the-art的精度,定位速度在单个i7 CPU上超过200fps。
3.人脸识别模块(SeetaFace Identification): 采用一个9层的卷积神经网络(CNN)来提取人脸特征,在LFW数据库上达到97.1%的精度(注:采用SeetaFace人脸检测和SeetaFace面部特征点定位作为前端进行全自动识别的情况下),特征提取速度为每图120ms(在单个i7 CPU上)。
二.前提
ubuntu14.04
opencv3.1.0
三.下载解压和安装cmake
安装cmake,版本大于3.1.0即可
https://cmake.org/download/
cmake --version #如果版本低于3.1,需要升级。14.04的是2.8
apt-get autoremove cmake #卸载低版本cmake
cd 解压的cmake文件夹
./bootstrap
make
sudo make install
cmake -version #查看版本是否更新成功
四. seetaface安装和测试
1. 下载seetaface
https://github.com/seetaface/SeetaFaceEngine
2. 编译测试FaceDetection模块
1. 编译
cd FaceDetection
mkdir build #在FaceDetection目录中
cd build
cmake ..
make -j2
cd ..
#若无问题,进入到测试
./build/facedet_test imagefilePath ./model/seeta_fd_frontal_V1.0.bin #imagefilePath是人脸图片
测试结果:
Detections takes 0.0887428 seconds
OpenMP is used.
SSE is used.
Image size (wxh): 500x375
error:
1. 出现问题,没有找到facedet_test,原因是cmake ..
以后,make
了
3. 编译测试FaceAlignment模块
1. 编译
cd FaceAlignment
mkdir build
cd build
cmake ..
cp ../../FaceDetection/build/libseeta_facedet_lib.so .
cp ../../FaceDetection/include/face_detection.h .
vim face_alignment_test.cpp #更改程序下寻找库的路径
更改路径为图中所示:
2. 运行
结果会保存在路径/FaceAlignment/build/result.jpg:
./fa_test
error:
1. Segmentation fault (core dumped)
出现这个错误的原因是,上上图中的路径部分不正确,程序找不到jpg图片或者bin文件,请按照上面的路径图更改;
4.编译和测试FaceIdentification模块
1. 添加头文件和模型
- 将
libseeta_facedet_lib.so
(/FaceDetection/build),libseeta_fa_lib.so
(FaceAlignment/build), seeta_fd_frontal_v1.0.bin
(/FaceDetection/model),seeta_fa_v1.1.bin
(FaceAlignment/model),添加到FaceIndentification/build中- 将
face_alignment.h
(FaceAlignment/include),face_detection.h
(/FaceDetection/include)添加到FaceIndentification/include中
2. 修改文件
- 打开FaceIdentification/CMakeLists.txt添加一行代码:
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -msse -msse2 -msse3")
如下图:
- 打开FaceIdentification/src/test/CMakeLists.txt将文件替换成如下内容
aux_source_directory (. SRC_LIST)
link_directories(${PROJECT_BINARY_DIR})
message(${SRC_LIST})
# add external libraries
find_package(OpenCV REQUIRED)
include_directories(${seeta_facedet_lib_INCLUDE_DIRS} ${seeta_fa_lib_INCLUDE_DIRS})
list(APPEND seeta_fi_lib_required_libs ${OpenCV_LIBS} seeta_facedet_lib seeta_fa_lib)
enable_testing ()
foreach (f ${SRC_LIST})
string(REGEX REPLACE "[.]cpp" ".bin" BIN ${f})
add_executable(${BIN} ${f})
#target_link_libraries(${BIN} viplnet ${OpenCV_LIBS} seeta_facede_lib seeta_fa_lib)
target_link_libraries(${BIN} viplnet ${seeta_fi_lib_required_libs})
endforeach ()
- 在 FaceIdentification/src/test/test_face_recognizer.cpp文件中添加如下内容头文件
#include <opencv2/opencv.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <opencv2/imgproc/imgproc.hpp>
- 在 FaceIdentification/src/test/test_face_verification.cpp文件中添加如下内容头文件
#include <opencv2/opencv.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <opencv2/imgproc/imgproc.hpp>
- 解压 FaceIdentification/model/seeta_fr_v1.0.part1.rar
sudo apt-get install unrar
unrar seeta_fr_v1.0.part1.rar
3. 编译
cd FaceIdentification
mkdir build
cd build
cmake ..
4. 运行
- 需要指定模型目录,不然会报
Segmentation fault (core dumped)
错误
请修改build/src/test/test_face_verification.cpp
修改如下部分:
- 确保终端在
/FaceIdentification
目录下:
./build/src/test/test_face_recognizer.bin #3个单元测试函数
./build/src/test/test_face_verification.bin #比较两个图像相似度
运行结果:
error:
make
时#error "SSE instruction set not enabled"
原因是程序中用到了sse指令集,但是cmake中没有开启此选项,请在/FaceIdefication/CMakeList.txt
中,添加set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -msse -msse2 -msse3")
总结:
- 至此,seetaface编译完成,并可以运行所有测试部分,作者编写test程序的时候,对于载入model失败,没有找到的情况未进行处理,导致报错
Segmentation fault (core dumped)
,没有提示信息,非常让人困惑; - 对于
Segmentation fault (core dumped)
错误,一般是在运行test程序时出现的,出错的原因是model文件(如seeta_fa_v1.1.bin
/seeta_fd_frontal_v1.0.bin
文件)未能加载成功,打开出错的测试程序,根据实际情况指定路径也可以保证测试程序运行成功;