飞腾派
直播中

jf_98561620

2年用户 16经验值
擅长:嵌入式技术 控制/MCU
私信 关注

【飞腾派4G版免费试用】飞腾派SeetafaceEngine人脸检测

收到个飞腾派,周末有空玩玩。。。

Seetaface是2016年中科院老师开源的的人脸识别引擎。https://github.com/seetaface/SeetaFaceEngine
源码使用的OpenCV版本是早期OpenCV–2.4.11,需手工修改为支持OpenCV-4.x版本函数。Seetaface包含 人脸检测FaceDetection人脸对齐FaceAlignment人脸识别FaceIdentification等三部分功能。
image.png下面是在飞腾派下编译FaceDetection人脸检测模块。

$cd /SeetaFaceEngine-master/FaceDetection
$ mkdir build
$ cd build
$ cmake -D
CUDA_USE_STATIC_CUDA_RUNTIME=OFF ..
$ make -j4

飞腾派是ARM架构,不支持MSSE,报错 error: unrecognized command-line option ‘-msse4.1’,打开CMakeLists.txt删除USE_SSE相关定义即可。
编译成功后,得到人脸检测demofacedet_test,人脸检测用户态库libseeta_facedet_lib.so
image.png上面demo只支持检测本地目录的人脸图片,不太方便演示,改成从UVC摄像头获取人脸照片,这里需要先安装openCV(网上很多相关教程,这里就不做介绍了)。
编写以下代码,从UVC摄像头取图送往人脸模块模块进行定位,这里可以使用codeblocks、qt等 IDE软件,在工程设定so库和头文件路径,然后编译。

#include <cstdint>
#include <fstream>
#include <iostream>
#include <string>
#include "opencv2/highgui/highgui.hpp"
#include "opencv2/imgproc/imgproc.hpp"
#include "face_detection.h"
using namespace std;
using namespace cv;

int seeta_fd_main(int argc, char** argv)
{
    bool result_cam = 0;
    cv::VideoCapture capture;
    result_cam = capture.open(“/dev/video0”, cv::CAP_V4L2);//打开摄像头
    if(result_cam < 1) {
        printf("open camera fail: %d\\n", result_cam);
        return -1;
    }
    capture.set(cv::CAP_PROP_FOURCC, cv::VideoWriter::fourcc('M', 'J', 'P', 'G'));
    capture.set(cv::CAP_PROP_FRAME_WIDTH, 640);
    capture.set(cv::CAP_PROP_FRAME_HEIGHT, 480);
    capture.set(cv::CAP_PROP_FPS, 30);
    cv::Mat frame;
    cv::Mat gray;
    seeta::FaceDetection detector(“../../seetaface/seeta_fd_frontal_v1.0.bin”);//模型
    detector.SetMinFaceSize(40);
    detector.SetScoreThresh(2.f);
    detector.SetImagePyramidScaleFactor(0.8f);
    detector.SetWindowStep(4, 4);
    while(1)
    {
        capture >> frame;
        if (frame.empty()) continue;
        cvtColor(frame, gray, COLOR_BGR2GRAY);
        seeta::ImageDataimg_data;
        img_data.data = gray.data;
        img_data.width = gray.cols;
        img_data.height = gray.rows;
        img_data.num_channels = 1;
        std::vector<seeta::FaceInfo> faces = detector.Detect(img_data);
        cv::Rectface_rect;
        int32_t num_face = static_cast<int32_t>(faces.size());
        for (int32_t i = 0; i < num_face; i++) {
            face_rect.x = faces[i].bbox.x;
            face_rect.y = faces[i].bbox.y;
            face_rect.width = faces[i].bbox.width;
            face_rect.height = faces[i].bbox.height;
            cv::rectangle(frame, face_rect, CV_RGB(0, 0, 255), 4, 8, 0);
        }

        cv::namedWindow("seetaface", cv::WINDOW_AUTOSIZE);
        cv::imshow(“seetaface”, frame);//显示人脸检测结果
        if (cv::waitKey(1) == 27)  break;
    }
    cv::destroyAllWindows();
    return 0;
}

这里编译得到UVC demo程序OpenCV_UVC,运行人脸检测试程序,并根据PID号绑定大核运行(测试使用了工程自带的人脸检测model库)。
$ ./OpenCV_UVC
$ top //获取PID…
$ taskset -cp 2 5503image.png

。。。

FaceAlignment、人脸识别FaceIdentification模块待续。。。 |

更多回帖

发帖
×
20
完善资料,
赚取积分