Ubuntu下虹软实时人脸识别

Ubuntu下虹软实时人脸识别@TOC
自留自用

环境配置:

新建工作空间文件夹Code
Code文件夹下建
build、img、lib、include、src文件夹
CMakeLists.txt文件
如图,给虹软的头文件和库分别放到include和lib文件夹下
文件路径
CMakeLists.txt文件内容:

cmake_minimum_required(VERSION 2.8)

project (Show)

find_package( OpenCV REQUIRED )


#指定头文件目录
INCLUDE_DIRECTORIES(${PROJECT_SOURCE_DIR}/include)    

#指定链接库文件目录
LINK_DIRECTORIES(${PROJECT_SOURCE_DIR}/lib)
LINK_DIRECTORIES(../linux_so)

add_executable( test
 src/test.cpp )


target_link_libraries( test ${OpenCV_LIBS}
arcsoft_face
arcsoft_face_engine
 )

src文件夹下test内容如下:

#include "opencv2/core.hpp"
#include "opencv2/imgproc.hpp"
#include "opencv2/highgui.hpp"
#include "opencv2/videoio.hpp"
#include <iostream>
#include"/home/livvedia/Code/include/amcomdef.h"
#include"/home/livvedia/Code/include/arcsoft_face_sdk.h"
#include"/home/livvedia/Code/include/asvloffscreen.h"
#include"/home/livvedia/Code/include/merror.h"

using namespace cv;
using namespace std;

#define APPID "BnsJDuaWSpgv5y6D3rQz7xRdpegsaMeWvZv3AfLVR5hb"
#define SDKKEY "AjHemSRB4G17mKTPGVP8RzYaKn8pagVJMFFmyeZrEnBX"
#define MERR_ASF_BASE_ALREADY_ACTIVATED 90114
#define SafeFree(p) { if ((p)) free(p); (p) = NULL; }
#define SafeArrayDelete(p) { if ((p)) delete [] (p); (p) = NULL; } 
#define SafeDelete(p) { if ((p)) delete (p); (p) = NULL; } 
 

int main()
{
	 int a,b,c,d;    //定义两个点坐标变量

	//激活SDK
	MRESULT res = ASFActivation(APPID, SDKKEY);
	if (res!= MOK && MERR_ASF_BASE_ALREADY_ACTIVATED != res)
		printf("ALActivation fail: %d\n", res);
	else
		printf("ALActivation sucess: %d\n", res);

    //初始化引擎
    MHandle handle = NULL;
	MInt32 mask = ASF_FACE_DETECT | ASF_FACERECOGNITION | ASF_AGE | ASF_GENDER | ASF_FACE3DANGLE;
	res = ASFInitEngine(ASF_DETECT_MODE_IMAGE, ASF_OP_0_ONLY, 16, 5, mask, &handle);
	if (res != MOK)
		printf("ALInitEngine fail: %d\n", res);
	else
		printf("ALInitEngine sucess: %d\n", res);
 
	Mat img ;
	VideoCapture capture;
	capture.open(0);
    if(capture.isOpened())
    {
        cout << "Capture is opened" << endl;
        for(;;)
        {
            capture >> img;
            if(img.empty())
                break;

			ASF_MultiFaceInfo detectedFaces1;
			ASF_SingleFaceInfo SingleDetectedFaces1 ;
			ASF_FaceFeature feature1 ;
			ASF_FaceFeature copyfeature1 ;
			res = ASFDetectFaces(handle, img.cols, img.rows, ASVL_PAF_RGB24_B8G8R8, (MUInt8*)img.ptr<uchar>(0), &detectedFaces1);
			if (MOK == res)
			{
			//负责检测单张人脸
				SingleDetectedFaces1.faceRect.left = detectedFaces1.faceRect[0].left;
				SingleDetectedFaces1.faceRect.top = detectedFaces1.faceRect[0].top;
				SingleDetectedFaces1.faceRect.right = detectedFaces1.faceRect[0].right;
				SingleDetectedFaces1.faceRect.bottom = detectedFaces1.faceRect[0].bottom;
				SingleDetectedFaces1.faceOrient = detectedFaces1.faceOrient[0];
				a = SingleDetectedFaces1.faceRect.left;
				b = SingleDetectedFaces1.faceRect.right;
				c = SingleDetectedFaces1.faceRect.top;
				d = SingleDetectedFaces1.faceRect.bottom;
				rectangle(img, Rect(a, c, (b - a), (d - c)), Scalar(0, 0, 255), 4);
			}
 
			// 人脸信息检测
			MInt32 processMask = ASF_AGE | ASF_GENDER | ASF_FACE3DANGLE;
			res = ASFProcess(handle, img.cols, img.rows, ASVL_PAF_RGB24_B8G8R8, (MUInt8*)img.ptr<uchar>(0), &detectedFaces1, processMask);
			if (res == MOK)
				{
					cout << "人脸信息检测成功" << endl;
				}
	
			// 获取年龄
			ASF_AgeInfo ageInfo = { 0 };
			res = ASFGetAge(handle, &ageInfo);
			if (res != MOK)
			printf("ASFGetAge fail: %d\n", res);
			else
			{
				string str;
				stringstream strm;
				strm<<*ageInfo.ageArray;
				strm>>str;       //将int型转换为字符串类型输出
				cout <<"年龄检测结果:"<< *ageInfo.ageArray << endl;
				// 输出信息
				putText(img,"age:"+ str,
				Point(b, c),
				FONT_HERSHEY_COMPLEX, 1, // font face and scale
				Scalar(255, 255, 255), // white
				1, LINE_AA); // line thickness and type
			}

			// 获取性别
			ASF_GenderInfo genderInfo = { 0 };
			res = ASFGetGender(handle, &genderInfo);
			if (res != MOK)
			printf("ASFGetGender fail: %d\n", res);
			else
			{
				if (*genderInfo.genderArray == 0)
					{
						cout << "性别检测结果:男性" << endl;
						putText(img, "Boy!",
           				 	Point(b, c+50),
           					FONT_HERSHEY_COMPLEX, 1, // font face and scale
       		     			Scalar(255, 255, 255), // white
          		 		 1, LINE_AA); // line thickness and type
					}
				if (*genderInfo.genderArray == 1)
					{
						cout << "性别检测结果:女性" << endl;
						putText(img, "Girl!",
           				 Point(b, c+50),
           				 FONT_HERSHEY_COMPLEX, 1, // font face and scale
       		    		 Scalar(255, 255, 255), // white
          			  1, LINE_AA); // line thickness and type				
					}
			}

			// 获取3D角度
			ASF_Face3DAngle angleInfo = { 0 };
			res = ASFGetFace3DAngle(handle, &angleInfo);
			if (res != MOK)
				cout << "获得3D角度失败" << endl;
			else
				{
					cout << "roll=" << angleInfo.roll[0] << endl;
					cout << "yaw=" << angleInfo.yaw[0] << endl;
					cout << "pitch=" << angleInfo.pitch[0] << endl;
				}
			imshow("out", img);
			// waitKey(2);
 
            if(waitKey(10) >= 0)
                break;
        }
    }
    else
    {
        cout << "No capture" << endl;
        img = Mat::zeros(480, 640, CV_8UC1);
        
        imshow("Sample", img);
        waitKey(0);
    }
	system("pause");
	return 0;
}

进build文件夹,打开终端依次输入指令

cmake ..
make
./test
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值