linux(debian系列)配置seetaface6

seetaface6依赖于opencv,另外我们需要界面,所以也需要Qt(你也可以选择其他的)。

这里的目标是配置好环境,能够编译并运行seetaface6给的demo。

那个demo中用到了sqlite数据库,所以我们还需要安装sqlite。

总的来说就是以下步骤:

  1. 编译并安装OpenCV
  2. 编译并安装seetaface6
  3. 安装Qt
  4. 安装sqlite和sqlite开发包
  5. 编译运行seetaface_demo

一、安装OpenCV

这里用官网给的步骤即可,目前最新的是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
  • cmake文件在/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

二、编译安装seetaface6

1. 去github找到seetafce6,这个只是个是demo,我们先不管它

linux(debian系列)配置seetaface6_第1张图片

2. 根据提示,seetaface6源码在SeetaFace6Open

linux(debian系列)配置seetaface6_第2张图片

3. 根据提示下载

git clone --recursive https://github.com/SeetaFace6Open/index.git

linux(debian系列)配置seetaface6_第3张图片

4. 编译

然后会有一个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需要的。

5.配置路径/安装

你需要将编译出的文件配置到位,放到/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包

三、安装Qt5

由于demo用的是qt5,所以要安装qt5。
安装:略。
建议:完美解决QT在线安装太慢

四、配置sqlite

apt install sqlite3 libsqlite3-dev

这里sqlite3是命令行工具,-dev的是开发包,我们两个都需要。

五、编译运行seetaface6-demo

1.修改pro文件

删除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

2.下载模型

github上有模型的链接,下载、解压,并放到你的Qt构建目录下,重命名为models,

3.运行

点击绿三角运行。

建议:没摄像头的买个摄像头。

你可能感兴趣的:(cmake,linux,c++,linux,debian,运维)