seetaface6依赖于opencv,另外我们需要界面,所以也需要Qt(你也可以选择其他的)。
这里的目标是配置好环境,能够编译并运行seetaface6给的demo。
那个demo中用到了sqlite数据库,所以我们还需要安装sqlite。
总的来说就是以下步骤:
这里用官网给的步骤即可,目前最新的是opencv4.7,由于需要人脸识别,所以我们需要安装opencv_contrib模块。
https://docs.opencv.org/4.x/d7/d9f/tutorial_linux_install.html
# Install minimal prerequisites (Ubuntu 18.04 as reference)
sudo apt update && sudo apt install -y cmake g++ wget unzip
# Download and unpack sources
wget -O opencv.zip https://github.com/opencv/opencv/archive/4.x.zip
wget -O opencv_contrib.zip https://github.com/opencv/opencv_contrib/archive/4.x.zip
unzip opencv.zip
unzip opencv_contrib.zip
# Create build directory and switch into it
mkdir -p build && cd build
# Configure
cmake -DOPENCV_EXTRA_MODULES_PATH=../opencv_contrib-4.x/modules ../opencv-4.x
# Build
cmake --build .
注意,默认安装路径是/usr/local
。
/usr/local/include/opencv4
/usr/local/lib
/usr/local/cmake
。我们知道这三个就够了。可以用-D CMAKE_INSTALL_PREFIX=
来指定安装路径。
这里假定为默认路径/usr/local
。
如果你不想自己编译,可以用我打包好的:
https://github.com/sixsixQAQ/opencv4-dev
$dpkg --info opencv4-dev.deb
新格式的 Debian 软件包,格式版本 2.0。
大小 16311436 字节:主控包=380 字节。
265 字节, 9 行 control
Package: opencv4-dev
Version: 1.0
Architecture: amd64
Maintainer: [email protected]
Description: OpenCV4 development package with opencv-contrib module.
binary: /usr/local/bin
includes: /usr/local/include/opencv4
lib: /usr/local/lib
share: /usr/local/share
git clone --recursive https://github.com/SeetaFace6Open/index.git
然后会有一个index文件夹,我们需要挨个模块编译:按个进入它们的craft文件夹,运行build.linux.x64.sh
。
但是编译有顺序要求,否则有的会无法编译通过。
这里给个编译脚本:
#!/bin/bash
modules="OpenRoleZoo
SeetaAuthorize
TenniS
FaceBoxes
FaceRecognizer6
FaceTracker6
Landmarker
PoseEstimator6
QualityAssessor3
SeetaAgePredictor
SeetaEyeStateDetector
SeetaGenderPredictor
SeetaMaskDetector
FaceAntiSpoofingX6"
for dir in $modules
do
cd $dir/craft
bash build.linux.x64.sh
cd -
done
编译得到的东西在index/build,里面有头文件、链接库、.cmake文件,是我们开发和编译demo需要的。
你需要将编译出的文件配置到位,放到/usr/lib、/usr/incldue等位置(这样弊端是卸载不方便),或者在你的项目构建文件中填写头文件路径、链接库路径(弊端是比较繁琐,不方便迁移),否则会找不到文件。
我的做法是把它打包成.deb(推荐),方便安装和卸载:https://github.com/sixsixQAQ/seetaface6-dev
$dpkg --info seetaface6-dev.deb
新格式的 Debian 软件包,格式版本 2.0。
大小 5529512 字节:主控包=360 字节。
226 字节, 9 行 control
Package: seetaface6-dev
Version: 1.0
Architecture: amd64
Maintainer: [email protected]
Description: seetaface6 development package.
binary: /usr/bin
headers: /usr/include
lib: /usr/lib/seetaface6
cmake: /usr/lib/cmake
你也可以自己打包,很简单,教程参见:如何制作deb包
由于demo用的是qt5,所以要安装qt5。
安装:略。
建议:完美解决QT在线安装太慢
apt install sqlite3 libsqlite3-dev
这里sqlite3是命令行工具,-dev的是开发包,我们两个都需要。
删除seetaface6-demo中的.pro.user文件,然后用qt creator打开.pro文件,把Qt5勾上来重新配置项目。
这个demo用的qmake,我们需要修改那个.pro文件,这里只求在linux运行即可,所以我把windows的全删除了。
seetaface6-dev包中把seetaface6链接库安装到了/usr/lib/seetaface6
,修改一下头文件路径和链接库路径即可。
#-------------------------------------------------
#
# Project created by QtCreator 2020-03-16T14:40:38
#
#-------------------------------------------------
QT += core gui sql
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
TARGET = seetaface_demo
TEMPLATE = app
# The following define makes your compiler emit warnings if you use
# any feature of Qt which has been marked as deprecated (the exact warnings
# depend on your compiler). Please consult the documentation of the
# deprecated API in order to know how to port your code away from it.
DEFINES += QT_DEPRECATED_WARNINGS
# You can also make your code fail to compile if you use deprecated APIs.
# In order to do so, uncomment the following line.
# You can also select to disable deprecated APIs only up to a certain version of Qt.
#DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0
SOURCES += \
main.cpp \
mainwindow.cpp \
videocapturethread.cpp \
inputfilesprocessdialog.cpp \
resetmodelprocessdialog.cpp
HEADERS += \
mainwindow.h \
videocapturethread.h \
inputfilesprocessdialog.h \
resetmodelprocessdialog.h
forms += \
mainwindow.ui
#linux:
INCLUDEPATH += /usr/local/include/opencv4
#OpenCV的链接库安装路径,这里是/usr/local/lib
LIBS += -L/usr/local/lib -lopencv_core -lopencv_imgproc -lopencv_highgui -lopencv_videoio -lopencv_imgcodecs
#seetaface6链接库的路径,这里是/usr/lib/seetaface6
LIBS += -L/usr/lib/seetaface6 -lSeetaFaceDetector600 -lSeetaFaceLandmarker600 \
-lSeetaFaceAntiSpoofingX600 -lSeetaFaceTracking600 -lSeetaFaceRecognizer610 \
-lSeetaQualityAssessor300 -lSeetaPoseEstimation600 -lSeetaAuthorize -ltennis
RESOURCES += \
face_resource.qrc
github上有模型的链接,下载、解压,并放到你的Qt构建目录下,重命名为models,
点击绿三角运行。
建议:没摄像头的买个摄像头。