完善个人信息

完善您的账号信息,便于为您提供更精准的服务

跳过
开发者类型:
企业名称:
联系人姓名:
真实姓名:
行业:
地区:

 无标题文档
人脸识别Linux开发文档
3、人脸比对API
基本类型
所有基本类型在平台库中有定义。 定义规则是在ANSIC 中的基本类型前加上字母“M”同时将类型的第一个字母改成大写。例如“long” 被定义成“MLong”
数据结构与枚举
AFR_FSDK_FACEINPUT
描述: 脸部信息
定义
typedef struct{
MRECT		rcFace;
AFR_FSDK_OrientCode  lOrient;
} AFR_FSDK_FACEINPUT, *LPAFR_FSDK_FACEINPUT;
                                
成员描述
rcFace
脸部矩形框信息
lOrient
脸部旋转角度
AFR_FSDK_FACEMODEL
描述: 脸部特征信息
定义
typedef struct{
MByte		*pbFeature;
MInt32		lFeatureSize;
} AFR_FSDK_FACEMODEL, *LPAFR_FSDK_FACEMODEL;
                                
成员描述
pbFeature
提取到的脸部特征
lFeatureSize
特征信息长度
AFR_FSDK_VERSION
描述: 引擎版本信息
定义
typedef struct{
MInt32			lCodebase;
MInt32			lMajor;
MInt32			lMinor;
MInt32			lBuild;
MInt32 		lFeatureLevel;
MPChar			Version;
MPChar			BuildDate;
MPChar  		CopyRight;
} AFR_FSDK_VERSION, *LPAFR_FSDK_VERSION;
                                
成员描述
lCodebase
代码库版本号
lMajor
主版本号
lMinor
次版本号
lBuild
编译版本号,递增
lFeatureLevel
特征库版本号
Version
字符串形式的版本号
BuildDate
编译时间
CopyRight
版权
枚举
AFR_FSDK_ORIENTCODE
描述: 基于逆时针的脸部方向枚举值
定义
enum AFR_FSDK_ORIENTCODE{
AFR_FSDK_FOC_0		= 0x1,
AFR_FSDK_FOC_90		= 0x2,
AFR_FSDK_FOC_270		= 0x3,
AFR_FSDK_FOC_180 = 0x4,
AFR_FSDK_FOC_30		= 0x5,
AFR_FSDK_FOC_60		= 0x6,
AFR_FSDK_FOC_120		= 0x7,
AFR_FSDK_FOC_150		= 0x8,
AFR_FSDK_FOC_210		= 0x9,
AFR_FSDK_FOC_240		= 0xa,
AFR_FSDK_FOC_300		= 0xb,
AFR_FSDK_FOC_330		= 0xc
};
                  
成员描述
AFR_FSDK_FOC_0
0 度
AFR_FSDK_FOC_90
90度
AFR_FSDK_FOC_270
270度
AFR_FSDK_FOC_180
180度
AFR_FSDK_FOC_30
30度
AFR_FSDK_FOC_60
60度
AFR_FSDK_FOC_120
120度
AFR_FSDK_FOC_150
150度
AFR_FSDK_FOC_210
210度
AFR_FSDK_FOC_240
240度
AFR_FSDK_FOC_300
300度
AFR_FSDK_FOC_330
330度
支持的颜色格式
描述: 颜色格式及其对齐规则
定义
ASVL_PAF_I420 	 8-bit Y层,之后是8-bit2x2 采样的U层和V
ASVL_PAF_YUYV 	 Y0, U0, Y1, V0
ASVL_PAF_RGB24_B8G8R8 	BGR24, B8G8R8
                                
API Reference
AFR_FSDK_InitialEngine
描述: 初始化引擎参数
原型
MRESULT AFR_FSDK_InitialEngine(
MPChar		AppId,
MPChar		SDKKey,
Mbyte		*pMem,
MInt32		lMemSize,
MHandle	        *phEngine
);
                 
参数
AppId
[in] 用户申请SDK时获取的App Id
SDKKey
[in] 用户申请SDK时获取的SDK Key
pMem
[in] 分配给引擎使用的内存地址
lMemSize
[in] 分配给引擎使用的内存大小
phEngine
[out] 引擎handle
返回值: 成功返回MOK,否则返回失败code。失败codes如下所列:
MERR_INVALID_PARAM 参数输入非法
MERR_NO_MEMORY 内存不足
AFR_FSDK_ExtractFRFeature
描述: 获取脸部特征参数
原型
MRESULT AFR_FSDK_ExtractFRFeature (
    MHandle			hEngine,
    LPASVLOFFSCREEN		pInputImage,
    LPAFR_FSDK_FACEINPUT	pFaceRes,
    LPAFR_FSDK_FACEMODEL	pFaceModels
);
                            
参数
hEngine
[in] 引擎handle
pInputImage
[in] 输入的图像数据
pFaceRes
[in] 已检测到的脸部信息
pFaceModels
[out] 提取的脸部特征信息
返回值: 成功返回MOK,否则返回失败code。失败codes如下所列:
MERR_INVALID_PARAM 参数输入非法
MERR_NO_MEMORY 内存不足
AFR_FSDK_FacePairMatching
描述: 脸部特征比较
原型
MRESULT AFR_FSDK_FacePairMatching(
	MHandle			hEngine,
	AFR_FSDK_FACEMODEL		*reffeature,
	AFR_FSDK_FACEMODEL		*probefeature,
	MFloat     			*pfSimilScore
);
                            
参数
hEngine
[in] 引擎handle
reffeature
[in] 已有脸部特征信息
probefeature
[in] 被比较的脸部特征信息
pfSimilScore
[out] 脸部特征相似程度数值
返回值: 成功返回MOK,否则返回失败code。失败codes如下所列:
MERR_INVALID_PARAM 参数输入非法
MERR_NO_MEMORY 内存不足
AFR_FSDK_UninitialEngine
描述: 销毁引擎,释放相应资源
原型
MRESULT AFR_FSDK_UninitialEngine(
	MHandle          hEngine
);
                            
参数
hEngine
[in] 引擎handle
返回值: 成功返回MOK,否则返回失败code。失败codes如下所列:
MERR_INVALID_PARAM 参数输入非法
AFR_FSDK_GetVersion
描述: 获取SDK版本信息参数
原型
const AFR_FSDK_VERSION *  AFR_FSDK_GetVersion(
     MHandle          hEngine
     );

                            
参数
hEngine
[in] 引擎handle
其他说明
其他说明: 此版本为免费开放的标准版本(为保证最优体验,建议注册人脸数小于1000),若有定制升级需求,请联系我们。
C语言示例代码
注意,使用时请替换申请的 APPID 和 SDKKEY,并设置好文件路径和图像尺寸

    #include "stdafx.h"
    #include <stdlib.h>
    #include <stdint.h>
    #include <Windows.h>
    #include "arcsoft_fsdk_face_recognition.h"
    #include "merror.h"

    #pragma comment(lib,"libarcsoft_fsdk_face_recognition.lib")

    #define WORKBUF_SIZE        (40*1024*1024)
    #define INPUT_IMAGE1_PATH "sample1.bmp"
    #define INPUT_IMAGE2_PATH "sample2.bmp"

    bool readBmp(const char* path, uint8_t **imageData, int *pWidth, int *pHeight)
    {
        if (path == NULL || imageData == NULL || pWidth == NULL || pHeight == NULL)
        {
            fprintf(stderr, "ReadBmp para error\r\n");
            return false;
        }
        FILE *fp = fopen(path, "rb");
        if (fp == 0)
        {
            fprintf(stderr, "Bmp file open failed\r\n");
            return false;
        }
     fseek(fp, sizeof(BITMAPFILEHEADER), 0);  BITMAPINFOHEADER head;
        fread(&head, sizeof(BITMAPINFOHEADER), 1, fp);
        *pWidth = head.biWidth;  	*pHeight = head.biHeight;  	int biBitCount = head.biBitCount;  	int lineByte = ((*pWidth) * biBitCount / 8 + 3) / 4 * 4;  	*imageData = (uint8_t *)malloc(lineByte * (*pHeight));  	for (int i = 0; i < *pHeight; i++)
        {
            fseek(fp, (*pHeight - 1 - i) * lineByte + 54, SEEK_SET);   	 	fread(*imageData + i * (*pWidth) * 3, 1, (*pWidth) * 3, fp);
        }
        fclose(fp);  	return true;
    } int _tmain(int argc, _TCHAR* argv[])
    {
        //初始化
        MRESULT nRet = MERR_UNKNOWN;  	MHandle hEngine = nullptr;  	char APPID[256] = "APPID";  	char SDKKey[256] = "SDKKey";  	MInt32 nScale = 16;
        MInt32 nMaxFace = 10;
        MByte *pWorkMem = (MByte *)malloc(WORKBUF_SIZE);
        if (pWorkMem == nullptr)
        {
            fprintf(stderr, "fail to malloc workbuf\r\n");
            return -1;
        }
        nRet = AFR_FSDK_InitialEngine(APPID, SDKKey, pWorkMem, WORKBUF_SIZE,
    &hEngine);
        if (nRet != MOK || hEngine == nullptr)
        {
            fprintf(stderr, "InitialFaceEngine failed , errorcode is %d \r\n", nRet);
            return -1;
        }
        //获取版本信息
        const AFR_FSDK_Version * pVersionInfo = nullptr;  	pVersionInfo = AFR_FSDK_GetVersion(hEngine);  	fprintf(stdout, "%d %d %d %d %d\r\n", pVersionInfo->lCodebase, pVersionInfo->lMajor, pVersionInfo->lMinor, pVersionInfo->lBuild, pVersionInfo-
    >lFeatureLevel);  	fprintf(stdout, "%s\r\n", pVersionInfo->Version);  	fprintf(stdout, "%s\r\n", pVersionInfo->BuildDate);  	fprintf(stdout, "%s\r\n", pVersionInfo->CopyRight);
        //读取第一张bmp图片数据
        ASVLOFFSCREEN offInput1 = { 0 };
        offInput1.u32PixelArrayFormat = ASVL_PAF_RGB24_B8G8R8;  	offInput1.ppu8Plane[0] = nullptr;
        readBmp(INPUT_IMAGE1_PATH, (uint8_t**)&offInput1.ppu8Plane[0],
    &offInput1.i32Width, &offInput1.i32Height);
        if (!offInput1.ppu8Plane[0])
        {
            fprintf(stderr, "fail to ReadBmp(%s)\r\n", INPUT_IMAGE1_PATH);
            AFR_FSDK_UninitialEngine(hEngine);
            free(pWorkMem);  	 	return -1;
        }
        offInput1.pi32Pitch[0] = offInput1.i32Width * 3;
        AFR_FSDK_FACEMODEL faceModels1 = { 0 };
        {
            AFR_FSDK_FACEINPUT faceResult;
            //第一张人脸信息通过face detection\face tracking获得  	 	faceResult.lOrient = AFR_FSDK_FOC_0;//人脸方向  	 	faceResult.rcFace.left = 346;//人脸框位置  	 	faceResult.rcFace.top = 58;  	 	faceResult.rcFace.right = 440;
            faceResult.rcFace.bottom = 151;
            //提取第一张人脸特征
            AFR_FSDK_FACEMODEL LocalFaceModels = { 0 };
            nRet = AFR_FSDK_ExtractFRFeature(hEngine, &offInput1, &faceResult,
    &LocalFaceModels);
            if (nRet != MOK)
            {
                fprintf(stderr, "fail to Extract 1st FR Feature, error
    code: %d\r\n", nRet);
            }
            faceModels1.lFeatureSize = LocalFaceModels.lFeatureSize;  	 	faceModels1.pbFeature = (MByte*)malloc(faceModels1.lFeatureSize);  	 	memcpy(faceModels1.pbFeature, LocalFaceModels.pbFeature, faceModels1.lFeatureSize);
        }

        //读取第二张bmp图片数据
        ASVLOFFSCREEN offInput2 = { 0 };
        offInput2.u32PixelArrayFormat = ASVL_PAF_RGB24_B8G8R8;  	offInput2.ppu8Plane[0] = nullptr;
        readBmp(INPUT_IMAGE2_PATH, (uint8_t**)&offInput2.ppu8Plane[0],
    &offInput2.i32Width, &offInput2.i32Height);
        if (!offInput2.ppu8Plane[0])
        {
            fprintf(stderr, "fail to ReadBmp(%s)\r\n", INPUT_IMAGE2_PATH);
            free(offInput1.ppu8Plane[0]);  	 	AFR_FSDK_UninitialEngine(hEngine);
            free(pWorkMem);  	 	return -1;
        }
        offInput2.pi32Pitch[0] = offInput2.i32Width * 3;
        AFR_FSDK_FACEMODEL faceModels2 = { 0 };
        {
            AFR_FSDK_FACEINPUT faceResult;
            //第二张人脸信息通过face detection\face tracking获得  	 	faceResult.lOrient = AFR_FSDK_FOC_0;//人脸方向  	 	faceResult.rcFace.left = 122;//人脸框位置  	 	faceResult.rcFace.top = 76;  	 	faceResult.rcFace.right = 478;
            faceResult.rcFace.bottom = 432;
            //提取第二张人脸特征
            AFR_FSDK_FACEMODEL LocalFaceModels = { 0 };
            nRet = AFR_FSDK_ExtractFRFeature(hEngine, &offInput2, &faceResult,
    &LocalFaceModels);
            if (nRet != MOK)
            {
       fprintf(stderr, "fail to Extract 2nd FR Feature, error code: %d\r\n", nRet);
            }
            faceModels2.lFeatureSize = LocalFaceModels.lFeatureSize;  	 	faceModels2.pbFeature = (MByte*)malloc(faceModels2.lFeatureSize);  	 	memcpy(faceModels2.pbFeature, LocalFaceModels.pbFeature, faceModels2.lFeatureSize);
        }
        //对比两张人脸特征,获得比对结果
        MFloat  fSimilScore = 0.0f;  	nRet = AFR_FSDK_FacePairMatching(hEngine, &faceModels1, &faceModels2,
    &fSimilScore);
        if (nRet == MOK)
        {
            fprintf(stdout, "fSimilScore =  %f\r\n", fSimilScore);
        }
        else  	{  	 	fprintf(stderr, "FacePairMatching failed , errorcode is %d \r\n", nRet);
        }


        //反初始化
        free(offInput1.ppu8Plane[0]);  	free(offInput2.ppu8Plane[0]);  	nRet = AFR_FSDK_UninitialEngine(hEngine);
        if (nRet != MOK)
        {
            fprintf(stderr, "UninitialFaceEngine failed , errorcode is %d \r\n", nRet);
        }
        free(pWorkMem);  	free(faceModels1.pbFeature);  	free(faceModels2.pbFeature);  	return 0;
    }