人脸识别5-Linux下交叉编译SeetaFace6
0、环境说明1、下载SeetaFace62、Linux下交叉编译2.0 编译顺序说明2.1 交叉编译OpenRoleZoo2.1.1 pot.h代码补丁2.1.2 编译过程
2.2 交叉编译SeetaAuthorize2.3 交叉编译TenniS2.4 交叉编译FaceAntiSpoofingX62.5 交叉编译FaceBoxes2.6 交叉编译FaceRecognizer62.7交叉编译FaceTracker62.8 交叉编译Landmarker2.9 交叉编译PoseEstimator62.10 交叉编译QualityAssessor32.10.1 LOCAL_ENV.cmake补丁2.10.2 编译过程
2.11 交叉编译SeetaAgePredictor2.12 交叉编译SeetaEyeStateDetector2.13 交叉编译SeetaGenderPredictor2.14 交叉编译SeetaMaskDetector
3 在Qt项目中使用opencv和SeetaFace6
0、环境说明
| 环境项 | 版本 |
|---|---|
| 操作系统 | Ubuntu22.04 |
| 交叉编译工具链 | /home/wongoing/Linux/itop/rk3588-linux/buildroot/output/rockchip_rk3588/host |
| 交叉编译器gcc | ${交叉编译工具链路径}/bin/aarch64-buildroot-linux-gnu-gcc |
| 交叉编译器g++ | ${交叉编译工具链路径}/bin/aarch64-buildroot-linux-gnu-g++ |
| cmake | 3.22.1 |
1、下载SeetaFace6
SeetaFace6官网:
https://github.com/SeetaFace6Openhttps://github.com/SeetaFace6Open/index
把下载的index-master.zip解压到~/Linux/qt_workspace/thirdpart/SeetaFace/SeetaFace6目录下,这个目录可以根据自己的实际设定。
下载 https://github.com/SeetaFace6Open 下的各模块源码,解压至~/Linux/qt_workspace/thirdpart/SeetaFace/SeetaFace6/index-master目录下,覆盖各模块文件夹。
2、Linux下交叉编译
2.0 编译顺序说明
OpenRoleZoo 为常用操作的集合SeetaAuthorize 为模型解析工程TenniS 为前向计算框架。需要重点说明的是,此次 TenniS 同时放出了 GPU 计算源码,可以编译出 GPU 版本进行使用。
上述三个模块为基础模块,各个 SDK 的编译均依赖上述模块,因此需要优先编译出 OpenRoleZoo, SeetaAuthorize 和 TenniS,然后再进行其他 SDK 模块的编译。具体需进入每个目录的craft下选择对应的脚本进行执行。
2.1 交叉编译OpenRoleZoo
2.1.1 pot.h代码补丁
解决以下问题
error C2039: “function”: 不是 “std” 的成员error C2061: 语法错误: 标识符“function”error C4430: 缺少类型说明符 – 假定为 interror C2143: 语法错误: 缺少“,”(在“&”的前面)error C3646: “m_allocator”: 未知重写说明符error C4430: 缺少类型说明符 – 假定为 interror C2665: “orz::Pot::Pot”: 没有重载函数可以转换所有参数类型
修改SeetaFace6index-masterOpenRoleZooincludeorzmempot.h,增加以下代码:
#include <functional> // 必须添加,用于 std::function
增加后的完整代码
//
// Created by Lby on 2017/8/12.
//
#ifndef ORZ_MEM_POT_H
#define ORZ_MEM_POT_H
#include <functional> // 必须添加,用于 std::function
#include <mutex>
#include <memory>
namespace orz {
class Pot {
public:
using allocator = std::function<std::shared_ptr<void>(size_t)>;
Pot();
Pot(const allocator &ator);
void *malloc(size_t _size);
void *relloc(size_t _size);
template<typename T>
T *calloc(size_t _count, bool copy = false) {
if (copy)
return reinterpret_cast<T *>(this->relloc(sizeof(T) * _count));
else
return reinterpret_cast<T *>(this->malloc(sizeof(T) * _count));
}
void *data() const;
size_t capacity() const;
size_t size() const;
void dispose();
private:
allocator m_allocator;
private:
size_t m_capacity;
size_t m_size;
std::shared_ptr<void> m_data;
};
}
#endif //ORZ_MEM_POT_H
2.1.2 编译过程
进入到~/Linux/qt_workspace/thirdpart/SeetaFace/SeetaFace6/index-master/OpenRoleZoo/craft目录下,复制脚本文件build.linux.x64.sh,命名为build.linux.rk3588.sh,内容如下:
#!/usr/bin/env bash
set -e
#TOOL_CHAIN=/home/wongoing/Linux/wg_rk3588_linux_sdk_v1.3.0/buildroot/output/rockchip_rk3588/host
TOOL_CHAIN=/home/wongoing/Linux/itop/rk3588-linux/buildroot/output/rockchip_rk3588/host
GCC_COMPILER=$TOOL_CHAIN/bin/aarch64-buildroot-linux-gnu
export LD_LIBRARY_PATH=${TOOL_CHAIN}/lib64:$LD_LIBRARY_PATH
export CC=${GCC_COMPILER}-gcc
export CXX=${GCC_COMPILER}-g++
export BUILD_DIR=build.linux.rk3588
export BUILD_TYPE=Release
export PLATFORM_TARGET=aarch64
export WITH_SSL=OFF
export INSTALL_DIR=$(cd "$(dirname "$0")"; pwd)/../../build
HOME=$(cd `dirname $0`; pwd)
echo $HOME
cd $HOME
mkdir -p "$BUILD_DIR"
cd "$BUILD_DIR"
cmake "$HOME/.."
-DCMAKE_BUILD_TYPE="$BUILD_TYPE"
-DPLATFORM="$PLATFORM_TARGET"
-DORZ_WITH_OPENSSL="$WITH_SSL"
-DCMAKE_INSTALL_PREFIX="$INSTALL_DIR"
make -j4
make install
cd -
注意:
以下为开头增加的内容:
set -e
#TOOL_CHAIN=/home/wongoing/Linux/wg_rk3588_linux_sdk_v1.3.0/buildroot/output/rockchip_rk3588/host
TOOL_CHAIN=/home/wongoing/Linux/itop/rk3588-linux/buildroot/output/rockchip_rk3588/host
GCC_COMPILER=$TOOL_CHAIN/bin/aarch64-buildroot-linux-gnu
export LD_LIBRARY_PATH=${TOOL_CHAIN}/lib64:$LD_LIBRARY_PATH
export CC=${GCC_COMPILER}-gcc
export CXX=${GCC_COMPILER}-g++
注意:
以下为修改的内容:
export BUILD_DIR=build.linux.x64
改为了
export BUILD_DIR=build.linux.rk3588
export PLATFORM_TARGET=x64
改为了
export PLATFORM_TARGET=aarch64
mkdir "$BUILD_DIR"
改为了
mkdir -p "$BUILD_DIR"
make -j16
改为了
make -j4
注意:
末尾增加的内容:
cd -
然后执行build.linux.rk3588.sh
2.2 交叉编译SeetaAuthorize
进入到~/Linux/qt_workspace/thirdpart/SeetaFace/SeetaFace6/index-master/SeetaAuthorize/craft目录下,复制脚本文件build.linux.x64.sh,命名为build.linux.rk3588.sh,内容如下:
#!/usr/bin/env bash
set -e
#TOOL_CHAIN=/home/wongoing/Linux/wg_rk3588_linux_sdk_v1.3.0/buildroot/output/rockchip_rk3588/host
TOOL_CHAIN=/home/wongoing/Linux/itop/rk3588-linux/buildroot/output/rockchip_rk3588/host
GCC_COMPILER=$TOOL_CHAIN/bin/aarch64-buildroot-linux-gnu
export LD_LIBRARY_PATH=${TOOL_CHAIN}/lib64:$LD_LIBRARY_PATH
export CC=${GCC_COMPILER}-gcc
export CXX=${GCC_COMPILER}-g++
export BUILD_DIR=build.linux.rk3588
export BUILD_TYPE=Release
export PLATFORM_TARGET=aarch64
export ORZ_HOME=$(cd "$(dirname "$0")"; pwd)/../../build
export INSTALL_DIR=$(cd "$(dirname "$0")"; pwd)/../../build
HOME=$(cd `dirname $0`; pwd)
cd $HOME
mkdir -p "$BUILD_DIR"
cd "$BUILD_DIR"
mkdir -p "$INSTALL_DIR"
cmake "$HOME/.."
-DCMAKE_BUILD_TYPE="$BUILD_TYPE"
-DPLATFORM="$PLATFORM_TARGET"
-DORZ_ROOT_DIR="$ORZ_HOME"
-DCMAKE_INSTALL_PREFIX="$INSTALL_DIR"
make -j4
make install
cd -
重点注意
mkdir "$INSTALL_DIR" 则改为 mkdir -p "$INSTALL_DIR"
2.3 交叉编译TenniS
进入到~/Linux/qt_workspace/thirdpart/SeetaFace/SeetaFace6/index-master/TenniS/craft目录下,复制脚本文件build.linux.x64.sh,命名为build.linux.rk3588.sh,内容如下:
#!/usr/bin/env bash
set -e
#TOOL_CHAIN=/home/wongoing/Linux/wg_rk3588_linux_sdk_v1.3.0/buildroot/output/rockchip_rk3588/host
TOOL_CHAIN=/home/wongoing/Linux/itop/rk3588-linux/buildroot/output/rockchip_rk3588/host
GCC_COMPILER=$TOOL_CHAIN/bin/aarch64-buildroot-linux-gnu
export LD_LIBRARY_PATH=${TOOL_CHAIN}/lib64:$LD_LIBRARY_PATH
export CC=${GCC_COMPILER}-gcc
export CXX=${GCC_COMPILER}-g++
export BUILD_DIR=build.linux.rk3588
export BUILD_TYPE=Release
export PLATFORM_TARGET=aarch64
export PLATFORM=x64
export INSTALL_DIR=$(cd "$(dirname "$0")"; pwd)/../../build
HOME=$(cd `dirname $0`; pwd)
cd $HOME
mkdir -p "$BUILD_DIR"
cd "$BUILD_DIR"
cmake "$HOME/.."
-DCMAKE_SYSTEM_NAME=Linux
-DCMAKE_BUILD_TYPE="$BUILD_TYPE"
-DCONFIGURATION="$BUILD_TYPE"
-DPLATFORM="$PLATFORM_TARGET"
-DCMAKE_INSTALL_PREFIX="$INSTALL_DIR"
-DTS_USE_OPENMP=OFF
-DTS_USE_SIMD=ON
-DTS_USE_NEON=ON
#-DTS_ON_HASWELL=OFF
#-DTS_DYNAMIC_INSTRUCTION=ON
make -j4
make install
cd -
重点注意:
-DTS_USE_OPENMP=ON
改为了
-DTS_USE_OPENMP=OFF
#-DTS_ON_HASWELL=OFF
#-DTS_DYNAMIC_INSTRUCTION=ON
替换为了
-DTS_USE_NEON=ON
2.4 交叉编译FaceAntiSpoofingX6
进入到~/Linux/qt_workspace/thirdpart/SeetaFace/SeetaFace6/index-master/FaceAntiSpoofingX6/craft目录下,复制脚本文件build.linux.x64.sh,命名为build.linux.rk3588.sh,内容如下:
#!/usr/bin/env bash
set -e
#TOOL_CHAIN=/home/wongoing/Linux/wg_rk3588_linux_sdk_v1.3.0/buildroot/output/rockchip_rk3588/host
TOOL_CHAIN=/home/wongoing/Linux/itop/rk3588-linux/buildroot/output/rockchip_rk3588/host
GCC_COMPILER=$TOOL_CHAIN/bin/aarch64-buildroot-linux-gnu
export LD_LIBRARY_PATH=${TOOL_CHAIN}/lib64:$LD_LIBRARY_PATH
export CC=${GCC_COMPILER}-gcc
export CXX=${GCC_COMPILER}-g++
export BUILD_DIR=build.linux.rk3588
export BUILD_TYPE=Release
export PLATFORM_TARGET=aarch64
export PLATFORM=aarch64
export ORZ_HOME=$(cd "$(dirname "$0")"; pwd)/../../build
export INSTALL_DIR=$(cd "$(dirname "$0")"; pwd)/../../build
HOME=$(cd `dirname $0`; pwd)
cd $HOME
mkdir -p "$BUILD_DIR"
cd "$BUILD_DIR"
cmake "$HOME/.."
-DCMAKE_BUILD_TYPE="$BUILD_TYPE"
-DCONFIGURATION="$BUILD_TYPE"
-DPLATFORM="$PLATFORM_TARGET"
-DORZ_ROOT_DIR="$ORZ_HOME"
-DCMAKE_INSTALL_PREFIX="$INSTALL_DIR"
-DCMAKE_MODULE_PATH=""
-DSEETA_AUTHORIZE=OFF
-DSEETA_MODEL_ENCRYPT=ON
make -j4
make install
cd -
2.5 交叉编译FaceBoxes
进入到~/Linux/qt_workspace/thirdpart/SeetaFace/SeetaFace6/index-master/FaceBoxes/craft目录下,复制脚本文件build.linux.x64.sh,命名为build.linux.rk3588.sh,内容如下:
#!/usr/bin/env bash
set -e
#TOOL_CHAIN=/home/wongoing/Linux/wg_rk3588_linux_sdk_v1.3.0/buildroot/output/rockchip_rk3588/host
TOOL_CHAIN=/home/wongoing/Linux/itop/rk3588-linux/buildroot/output/rockchip_rk3588/host
GCC_COMPILER=$TOOL_CHAIN/bin/aarch64-buildroot-linux-gnu
export LD_LIBRARY_PATH=${TOOL_CHAIN}/lib64:$LD_LIBRARY_PATH
export CC=${GCC_COMPILER}-gcc
export CXX=${GCC_COMPILER}-g++
export BUILD_DIR=build.linux.rk3588
export BUILD_TYPE=Release
export PLATFORM_TARGET=aarch64
export PLATFORM=aarch64
export ORZ_HOME=$(cd "$(dirname "$0")"; pwd)/../../build
export INSTALL_DIR=$(cd "$(dirname "$0")"; pwd)/../../build
HOME=$(cd `dirname $0`; pwd)
cd $HOME
mkdir -p "$BUILD_DIR"
cd "$BUILD_DIR"
cmake "$HOME/.."
-DCMAKE_BUILD_TYPE="$BUILD_TYPE"
-DCONFIGURATION="$BUILD_TYPE"
-DPLATFORM="$PLATFORM_TARGET"
-DORZ_ROOT_DIR="$ORZ_HOME"
-DCMAKE_INSTALL_PREFIX="$INSTALL_DIR"
-DCMAKE_MODULE_PATH=""
-DSEETA_AUTHORIZE=OFF
-DSEETA_MODEL_ENCRYPT=ON
make -j4
make install
cd -
2.6 交叉编译FaceRecognizer6
与FaceAntiSpoofingX6类似
2.7交叉编译FaceTracker6
与FaceAntiSpoofingX6类似
2.8 交叉编译Landmarker
与FaceAntiSpoofingX6类似
2.9 交叉编译PoseEstimator6
与FaceAntiSpoofingX6类似
2.10 交叉编译QualityAssessor3
2.10.1 LOCAL_ENV.cmake补丁
在 在QualityAssessor3/cmake/LOCAL_ENV.cmake文件中,添加else判断(这个判断在其他模块是有的)代码如下:
else()
set(ENV_RUNTIME_DIR ${ENV_RUNTIME_DIR}/${PLATFORM})
set(ENV_LIBRARY_DIR ${ENV_LIBRARY_DIR}/${PLATFORM})
set(ENV_ARCHIVE_DIR ${ENV_ARCHIVE_DIR}/${PLATFORM})
endif()
完整QualityAssessor3/cmake/LOCAL_ENV.cmake代码如下:
# set flags
set(ENV_RUNTIME_DIR "bin")
set(ENV_LIBRARY_DIR "lib")
set(ENV_ARCHIVE_DIR "lib")
set(ENV_HEADER_DIR "include")
set(ENV_SUFFIX "")
if (MSVC)
if ("${PLATFORM}" STREQUAL "")
elseif("${PLATFORM}" STREQUAL "auto")
else ()
set(ENV_RUNTIME_DIR ${ENV_RUNTIME_DIR}/${PLATFORM})
set(ENV_LIBRARY_DIR ${ENV_LIBRARY_DIR}/${PLATFORM})
set(ENV_ARCHIVE_DIR ${ENV_ARCHIVE_DIR}/${PLATFORM})
endif ()
elseif (MINGW)
if ("${PLATFORM}" STREQUAL "")
elseif("${PLATFORM}" STREQUAL "auto")
else ()
set(ENV_RUNTIME_DIR ${ENV_RUNTIME_DIR}/${PLATFORM})
set(ENV_LIBRARY_DIR ${ENV_LIBRARY_DIR}/${PLATFORM})
set(ENV_ARCHIVE_DIR ${ENV_ARCHIVE_DIR}/${PLATFORM})
endif ()
else()
if ("${PLATFORM}" STREQUAL "x86")
set(ENV_RUNTIME_DIR ${ENV_RUNTIME_DIR})
set(ENV_LIBRARY_DIR ${ENV_LIBRARY_DIR}32)
set(ENV_ARCHIVE_DIR ${ENV_ARCHIVE_DIR}32)
elseif ("${PLATFORM}" STREQUAL "x64")
set(ENV_RUNTIME_DIR ${ENV_RUNTIME_DIR})
set(ENV_LIBRARY_DIR ${ENV_LIBRARY_DIR}64)
set(ENV_ARCHIVE_DIR ${ENV_ARCHIVE_DIR}64)
else()
set(ENV_RUNTIME_DIR ${ENV_RUNTIME_DIR}/${PLATFORM})
set(ENV_LIBRARY_DIR ${ENV_LIBRARY_DIR}/${PLATFORM})
set(ENV_ARCHIVE_DIR ${ENV_ARCHIVE_DIR}/${PLATFORM})
endif()
endif()
if ("${CONFIGURATION}" STREQUAL "Debug")
set(ENV_SUFFIX "d")
endif ()
set(ENV_INCLUDE_DIR ${ENV_HEADER_DIR})
2.10.2 编译过程
与FaceAntiSpoofingX6类似
2.11 交叉编译SeetaAgePredictor
与FaceAntiSpoofingX6类似
2.12 交叉编译SeetaEyeStateDetector
与FaceAntiSpoofingX6类似
2.13 交叉编译SeetaGenderPredictor
与FaceAntiSpoofingX6类似
2.14 交叉编译SeetaMaskDetector
与FaceAntiSpoofingX6类似
3 在Qt项目中使用opencv和SeetaFace6
#windows adm64:
msvc {
#添加头文件
INCLUDEPATH += D:QtDepLibraryopencvopencv-4.5.5uildinstallinclude
INCLUDEPATH += D:QtDepLibraryopencvopencv-4.5.5uildinstallincludeopencv2
INCLUDEPATH += D:QtDepLibrarySeetaFaceSeetaFace6index-masteruildinclude
INCLUDEPATH += D:QtDepLibrarySeetaFaceSeetaFace6index-masteruildincludeseeta
#添加库
win32:CONFIG(debug, debug|release) {
LIBS += -LD:QtDepLibraryopencvopencv-4.5.5uildinstalllib -lopencv_world455d
LIBS += -LD:QtDepLibrarySeetaFaceSeetaFace6index-masteruildlibx64
LIBS += -lSeetaFaceDetector600d
LIBS += -lSeetaFaceLandmarker600d
LIBS += -lSeetaFaceAntiSpoofingX600d
LIBS += -lSeetaFaceTracking600d
LIBS += -lSeetaFaceRecognizer610d
LIBS += -lSeetaQualityAssessor300d
LIBS += -lSeetaPoseEstimation600d
} else {
LIBS += -LD:QtDepLibraryopencvopencv-4.5.5uildinstalllib -lopencv_world455
LIBS += -LD:QtDepLibrarySeetaFaceSeetaFace6index-masteruildlibx64
LIBS += -lSeetaFaceDetector600
LIBS += -lSeetaFaceLandmarker600
LIBS += -lSeetaFaceAntiSpoofingX600
LIBS += -lSeetaFaceTracking600
LIBS += -lSeetaFaceRecognizer610
LIBS += -lSeetaQualityAssessor300
LIBS += -lSeetaPoseEstimation600
}
}
#Linux aarch64
!msvc {
#添加头文件
# opencv引用buildroot构建时的4.5.4
INCLUDEPATH += /home/wongoing/Linux/itop/rk3588-linux/buildroot/output/rockchip_rk3588/host/aarch64-buildroot-linux-gnu/sysroot/usr/include/opencv4
INCLUDEPATH += /home/wongoing/Linux/itop/rk3588-linux/buildroot/output/rockchip_rk3588/host/aarch64-buildroot-linux-gnu/sysroot/usr/include/opencv4/opencv2
# SeetaFace6引用自己源码编译的
INCLUDEPATH += $$PWD/../thirdpart/SeetaFace/SeetaFace6/index-master/build/include
INCLUDEPATH += $$PWD/../thirdpart/SeetaFace/SeetaFace6/index-master/build/include/seeta
#添加库opencv
LIBS += -L/home/wongoing/Linux/itop/rk3588-linux/buildroot/output/rockchip_rk3588/host/aarch64-buildroot-linux-gnu/sysroot/usr/lib
LIBS += -lopencv_core
LIBS += -lopencv_imgproc
LIBS += -lopencv_imgcodecs
LIBS += -lopencv_videoio
LIBS += -lopencv_highgui
#添加库SeetaFace6
LIBS += -L$$PWD/../thirdpart/SeetaFace/SeetaFace6/index-master/build/lib/aarch64
LIBS += -lSeetaFaceDetector600
LIBS += -lSeetaFaceLandmarker600
LIBS += -lSeetaFaceAntiSpoofingX600
LIBS += -lSeetaFaceTracking600
LIBS += -lSeetaFaceRecognizer610
LIBS += -lSeetaQualityAssessor300
LIBS += -lSeetaPoseEstimation600
LIBS += -lSeetaAuthorize
LIBS += -ltennis
}



