完善个人信息

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

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


人脸识别iOS开发文档
1、人脸检测API
基本类型
    typedef MInt32 AFD_FSDK_OrientPriority;
    typedef MInt32 AFD_FSDK_OrientCode;
 
所有基本类型在平台库中有定义。 定义规则是在ANSIC 中的基本类型前加上字母“M”同时将类型的第一个字母改成大写。例如“long” 被定义成“MLong”
数据结构与枚举
AFD_FSDK_FACERES
描述: 检测到的脸部信息
/*定义*/
typedef struct{
    MRECT 	* rcFace;
    MLong 	nFace;
    AFD_FSDK_OrientCode 	* lfaceOrient;
} AFD_FSDK_FACERES, * LPAFD_FSDK_FACERES;
                                
成员变量
rcFace
人脸矩形框信息
nFace
人脸个数
lfaceOrient
人脸角度信息
AFD_FSDK_VERSION
描述: SDK版本信息
/*定义*/
 typedef struct
{
	MInt32 lCodebase;
	MInt32 lMajor;
	MInt32 lMinor;
	MInt32 lBuild;
	MPChar Version;
	MPChar BuildDate;
	MPChar CopyRight;
} ArcSoft_Face_Detection_Version;
                                
成员描述
lCodebase
代码库版本号
lMajor
主版本号
lMinor
次版本号
lBuild
编译版本号,递增
Version
字符串形式的版本号
BuildDate
编译时间
CopyRight
版权信息
AFD_FSDK_OrientPriority
描述: 定义脸部角度的检测范围
/*定义*/
enum _AFD_FSDK_OrientPriority{
AFD_FSDK_OPF_0_ONLY		= 0x1,
AFD_FSDK_OPF_90_ONLY		= 0x2,
AFD_FSDK_OPF_270_ONLY		= 0x3,
AFD_FSDK_OPF_180_ONLY		= 0x4,
AFD_FSDK_OPF_0_HIGHER_EXT	= 0x5
};
成员描述
AFD_FSDK_OPF_0_ONLY
检测0度(±45度)方向
AFD_FSDK_OPF_90_ONLY
检测90度(±45度)方向
AFD_FSDK_OPF_270_ONLY
检测270度(±45度)方向
AFD_FSDK_OPF_180_ONLY
检测180度(±45度) 方向
AFD_FSDK_OPF_0_HIGHER_EXT
检测0度,90度,180度,270度四个方向,其中0度更优先
AFD_FSDK_OrientCode
描述: 定义人脸检测结果中的人脸角度
enum _AFD_FSDK_OrientCode{
	AFD_FSDK_FOC_0	= 0x1,
	AFD_FSDK_FOC_90	= 0x2,
	AFD_FSDK_FOC_270	= 0x3,
	AFD_FSDK_FOC_180	= 0x4,
	AFD_FSDK_FOC_30	= 0x5,
	AFD_FSDK_FOC_60	= 0x6,
	AFD_FSDK_FOC_120	= 0x7,
	AFD_FSDK_FOC_150	= 0x8,
	AFD_FSDK_FOC_210	= 0x9,
	AFD_FSDK_FOC_240	= 0xa,
	AFD_FSDK_FOC_300	= 0xb,
	AFD_FSDK_FOC_330	= 0xc
};
成员描述
AFD_FSDK_FOC_0
0 度
AFD_FSDK_FOC_90
90度
AFD_FSDK_FOC_270
270度
AFD_FSDK_FOC_180
180度
AFD_FSDK_FOC_30
30度
AFD_FSDK_FOC_60
60度
AFD_FSDK_FOC_120
120度
AFD_FSDK_FOC_150
150度
AFD_FSDK_FOC_210
210度
AFD_FSDK_FOC_240
240度
AFD_FSDK_FOC_300
300度
AFD_FSDK_FOC_330
330度
支持的颜色格式
描述: 颜色格式及其对齐规则
ASVL_PAF_NV12  /*8-bit Y 层,之后是 8-bit 的 2x2 采样的 U 层和 V 层*/
ASVL_PAF_RGB24_B8G8R8  /*每个像素 8-bit B,8-bit R,8-bit R*/
                
API说明
AFD_FSDK_InitialFaceEngine
描述: 初始化脸部检测引擎
原型
MRESULT AFD_FSDK_InitialFaceEngine(
	MPChar					AppId,
	MPChar					SDKKey,
	MByte					*pMem,
	MInt32					lMemSize,
	MHandle	 			*pEngine,
	AFD_FSDK_OrientPriority		iOrientPriority,
	MInt32		 			nScale,
	MInt32					nMaxFaceNum
);
参数
AppId
[in] 用户申请SDK时获取的App Id
SDKKey
[in] 用户申请SDK时获取的SDK Key
pMem
[in] 分配给引擎使用的内存地址
lMemSize
[in] 分配给引擎使用的内存大小
pEngine
[out] 引擎handle
iOrientPriority
[in] 期望的脸部检测角度范围
nScale
[in] 用于数值表示的最小人脸尺寸 有效值范围[2,50] 推荐值 16。该尺寸是人脸相对于所在图片的长边的占比。例如,如果用户想检测到的最小人脸尺寸是图片长度的1/8,那么这个nScale就应该设置为8
nMaxFaceNum
[in] 用户期望引擎最多能检测出的人脸数 有效值范围[1,50]
返回值: 成功返回MOK,否则返回失败code。失败codes如下所列:
MERR_INVALID_PARAM 参数输入非法
MERR_NO_MEMORY 内存不足
AFD_FSDK_StillImageFaceDetection
描述: 根据输入的图像检测出人脸位置,一般用于静态图像检测
原型
MRESULT AFD_FSDK_StillImageFaceDetection(
	 MHandle		hEngine,
	 LPASVLOFFSCREEN	pImgData,
	 LPAFD_FSDK_FACERES	*pFaceRes
);
         
参数
hEngine
[in] 引擎handle
pImgData
[in] 待检测的图像信息
pFaceRes
[out] 人脸检测结果
返回值: 成功返回MOK,否则返回失败code
AFD_FSDK_UninitialFaceEngine
描述: 销毁引擎,释放相应资源
原型
MRESULT AFD_FSDK_UninitialFaceEngine(
MHandle 	hEngine
);
                            
参数
hEngine
[in] 引擎handle
返回值: 成功返回MOK,否则返回失败code。失败codes如下所列:
MERR_INVALID_PARAM 参数输入非法
AFD_FSDK_GetVersion
描述: 获取SDK版本信息
原型
MRESULT AFD_FSDK_UninitialFaceEngine(
MHandle 	hEngine
);
                
参数
hEngine
[in] 引擎handle
C语言示例代码
注意,使用时请替换申请的APPID SDKKEY,并设置好文件路径和图像尺寸
#include <stdio.h >
#include <stdlib.h>
#include <stdint.h>
#include <Windows.h>
#include "arcsoft_fsdk_face_detection.h"
#include "merror.h"

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

#define WORKBUF_SIZE        (40*1024*1024)
#define INPUT_IMAGE_PATH "sample.bmp"
#define APPID		""			//APPID
#define SDKKey		""			//SDKKey

bool readBmp24(const char* path, uint8_t **imageData, int *pWidth, int *pHeight)
{
	if (path == NULL || imageData == NULL || pWidth == NULL || pHeight == NULL)
	{
		return false;
	}
	FILE *fp = fopen(path, "rb");
	if (fp == NULL)
	{
		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;
	if (24 == biBitCount)
	{
		int lineByte = ((*pWidth) * biBitCount / 8 + 3) / 4 * 4;
		*imageData = (uint8_t *)malloc(lineByte * (*pHeight));
		uint8_t * data = (uint8_t *)malloc(lineByte * (*pHeight));
		fseek(fp, 54, SEEK_SET);
		fread(data, 1, lineByte * (*pHeight), fp);
		for (int i = 0; i < *pHeight; i++)
		{
			for (int j = 0; j < *pWidth; j++)
			{
				memcpy((*imageData) + i * (*pWidth) * 3 + j * 3, data + (((*pHeight) - 1) - i) * lineByte + j * 3, 3);
			}
		}
		free(data);
	}
	else
	{
		fclose(fp);
		return false;
	}
	fclose(fp);
	return true;
}
int main()
{
	/* 初始化引擎和变量 */
	MRESULT nRet = MERR_UNKNOWN;
	MHandle hEngine = nullptr;
	MInt32 nScale = 16;
	MInt32 nMaxFace = 10;
	MByte *pWorkMem = (MByte *)malloc(WORKBUF_SIZE);
	if (pWorkMem == nullptr)
	{
		return -1;
	}
	nRet = AFD_FSDK_InitialFaceEngine(APPID, SDKKey, pWorkMem, WORKBUF_SIZE, &hEngine, AFD_FSDK_OPF_0_HIGHER_EXT, nScale, nMaxFace);
	if (nRet != MOK)
	{
		return -1;
	}
	/* 打印版本信息 */
	const AFD_FSDK_Version * pVersionInfo = nullptr;
	pVersionInfo = AFD_FSDK_GetVersion(hEngine);
	fprintf(stdout, "%d %d %d %d\n", pVersionInfo->lCodebase, pVersionInfo->lMajor, pVersionInfo->lMinor, pVersionInfo->lBuild);
	fprintf(stdout, "%s\n", pVersionInfo->Version);
	fprintf(stdout, "%s\n", pVersionInfo->BuildDate);
	fprintf(stdout, "%s\n", pVersionInfo->CopyRight);

	/* 读取静态图片信息,并保存到ASVLOFFSCREEN结构体 (以ASVL_PAF_RGB24_B8G8R8格式为例) */
	ASVLOFFSCREEN offInput = { 0 };
	offInput.u32PixelArrayFormat = ASVL_PAF_RGB24_B8G8R8;
	offInput.ppu8Plane[0] = nullptr;
	readBmp24(INPUT_IMAGE_PATH, (uint8_t**)&offInput.ppu8Plane[0], &offInput.i32Width, &offInput.i32Height);
	if (!offInput.ppu8Plane[0])
	{
		fprintf(stderr, "Fail to ReadBmp(%s)\n", INPUT_IMAGE_PATH);
		AFD_FSDK_UninitialFaceEngine(hEngine);
		free(pWorkMem);
		return -1;
	}
	else
	{
		fprintf(stdout, "Picture width : %d , height : %d \n", offInput.i32Width, offInput.i32Height);
	}
	offInput.pi32Pitch[0] = offInput.i32Width * 3;

	/* 人脸检测 */
	LPAFD_FSDK_FACERES	FaceRes = nullptr;
	nRet = AFD_FSDK_StillImageFaceDetection(hEngine, &offInput, &FaceRes);
	if (nRet != MOK)
	{
		fprintf(stderr, "Face Detection failed, error code: %d\n", nRet);
	}
	else
	{
		fprintf(stdout, "The number of face: %d\n", FaceRes->nFace);
		for (int i = 0; i < FaceRes->nFace; ++i)
		{
			fprintf(stdout, "Face[%d]: rect[%d,%d,%d,%d], Face orient: %d\n", i, FaceRes->rcFace[i].left, FaceRes->rcFace[i].top, FaceRes->rcFace[i].right, FaceRes->rcFace[i].bottom, FaceRes->lfaceOrient[i]);
		}
	}

	/* 释放引擎和内存 */
	nRet = AFD_FSDK_UninitialFaceEngine(hEngine);
	if (nRet != MOK)
	{
		fprintf(stderr, "UninitialFaceEngine failed , errorcode is %d \n", nRet);
	}
	free(offInput.ppu8Plane[0]);
	free(pWorkMem);
	return 0;
}