完善个人信息

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

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


人脸识别iOS开发文档
2、人脸跟踪API
基本类型
typedef MInt32 AFT_FSDK_OrientPriority;
typedef MInt32 AFT_FSDK_OrientCode;
所有基本类型在平台库中有定义。 定义规则是在ANSIC 中的基本类型前加上字母“M”同时将类型的第一个字母改成大写。例如“long” 被定义成“MLong”
数据结构与枚举
AFT_FSDK_FACERES
描述: 检测到的脸部信息
定义
    typedef struct{
    MInt32 		nFace;
    AFT_FSDK_OrientCode lfaceOrient;
    MRECT 			*rcFace;
} AFT_FSDK_FACERES, *LPAFT_FSDK_FACERES;
                                  
成员描述
rcFace
人脸矩形框信息
nFace
人脸个数
lfaceOrient
人脸角度信息
AFT_FSDK_Version
描述: SDK版本信息
定义
    typedef struct{
    MInt32 lCodebase;
    MInt32 lMajor;
    MInt32 lMinor;
    MInt32 lBuild;
    MPChar Version;
    MPChar BuildDate;
    MPChar CopyRight	;
} AFT_FSDK_Version;


                                         
成员描述
lCodebase
代码库版本号
lMajor
主版本号
lMinor
次版本号
lBuild
编译版本号,递增
Version
字符串形式的版本号
BuildDate
编译时间
CopyRight
版权信息
AFT_FSDK_OrientPriority
描述: 定义脸部检测角度的优先级
定义
enum _AFT_FSDK_OrientPriority{
    AFT_FSDK_OPF_0_ONLY		= 0x1,
    AFT_FSDK_OPF_90_ONLY	= 0x2,
    AFT_FSDK_OPF_270_ONLY	= 0x3,
    AFT_FSDK_OPF_180_ONLY	= 0x4,
    AFT_FSDK_OPF_0_HIGHER_EXT	= 0x5,
};
                                            
成员描述
AFT_FSDK_OPF_0_ONLY
检测0度方向
AFT_FSDK_OPF_90_ONLY
检测90度方向
AFT_FSDK_OPF_270_ONLY
检测270度方向
AFT_FSDK_OPF_180_ONLY
检测180度方向
AFT_FSDK_OPF_0_HIGHER_EXT
检测0度,90度,180度,270度四个方向,其中0度更优先
AFT_FSDK_OrientCode
描述: 定义检测返回的人脸角度
定义
enum _AFT_FSDK_OrientCode {
     AFT_FSDK_FOC_0     = 0x1,
     AFT_FSDK_FOC_90    = 0x2,
     AFT_FSDK_FOC_270   = 0x3,
     AFT_FSDK_FOC_180   = 0x4
};
                                        
成员描述
AFT_FSDK_FOC_0
0 度
AFT_FSDK_FOC_90
90度
AFT_FSDK_FOC_270
270度
AFT_FSDK_FOC_180
180度
支持的颜色格式
描述: 颜色格式及其对齐规则
定义
ASVL_PAF_I420 	8-bit Y层,之后是8-bit2x2 采样的U层和V
ASVL_PAF_YUYV 	Y0, U0, Y1, V0
ASVL_PAF_RGB24_B8G8R8 	BGR24, B8G8R8
                            
API说明
AFT_FSDK_InitialFaceEngine
描述: 初始化脸部检测引擎
原型
MRESULT AFT_FSDK_InitialFaceEngine(
	MPChar 	AppId,
    MPChar 	SDKKey,
    MByte*		pMem,
    MInt32		lMemSize,
    MHandle 	*pEngine,
    AFT_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,16] 推荐值 16
nMaxFaceNum
[in] 用户期望引擎最多能检测出的人脸数 有效值范围[1,20]
返回值: 成功返回MOK,否则返回失败code。失败codes如下所列:
MERR_INVALID_PARAM 参数输入非法
MERR_NO_MEMORY 内存不足
AFT_FSDK_FaceFeatureDetect
描述: 根据输入的图像检测人脸,一般用于视频检测,多帧方式
原型
MRESULT AFT_FSDK_FaceFeatureDetect(
    AFT_FSDK_ENGINE      	 hEngine,
    LPASVLOFFSCREEN  	 pImgData,
    LPAFT_FSDK_FACERES        *pFaceRes,
);
                                    

参数
hEngine
[in] 引擎handle
pImgData
[in] 带检测图像信息
pFaceRes
[out] 人脸检测结果
说明:
在一个init/unit 过程中, 只支持相同分辨率的图像数据
返回值: 成功返回MOK,否则返回失败code。失败codes如下所列:
MERR_INVALID_PARAM 参数输入非法
MERR_BAD_STATE 状态不正确
AFT_FSDK_UninitialFaceEngine
描述: 销毁引擎,释放相应资源
原型
MRESULT AFT_FSDK_UninitialFaceEngine(
    MHandle        hEngine,
);
                                    
参数
hEngine
[in] 引擎handle
返回值: 成功返回MOK,否则返回失败code。失败codes如下所列:
MERR_INVALID_PARAM 参数输入非法
AFT_FSDK_GetVersion
描述: 获取SDK版本信息
原型
const AFT_FSDK_Version * AFT_FSDK_GetVersion(
    MHandle	    hEngine
);
                                   
参数
hEngine
[in] 引擎句柄
C语言示例代码
注意,使用时请替换申请的APPID SDKKEY,并设置好文件路径和图像尺寸

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

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

    #define WORKBUF_SIZE        (40*1024*1024)
    #define INPUT_IMAGE_PATH "sample.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;
        LPAFT_FSDK_FACERES FaceRes = nullptr;  	MByte *pWorkMem = (MByte *)malloc(WORKBUF_SIZE);
        if (pWorkMem == nullptr)
        {
            fprintf(stderr, "fail to malloc workbuf\r\n");
            return -1;
        }
        nRet = AFT_FSDK_InitialFaceEngine(APPID, SDKKey, pWorkMem, WORKBUF_SIZE,
    &hEngine, AFT_FSDK_OPF_0_HIGHER_EXT, nScale, nMaxFace);
        if (nRet != MOK || hEngine == nullptr)
        {
            fprintf(stderr, "InitialFaceEngine failed , errorcode is %d \r\n", nRet);
            return -1;
        }
        //获取版本信息
        const AFT_FSDK_Version * pVersionInfo = nullptr;  	pVersionInfo = AFT_FSDK_GetVersion(hEngine);
        fprintf(stdout, "%d %d %d %d\r\n", pVersionInfo->lCodebase, pVersionInfo-
    >lMajor, pVersionInfo->lMinor, pVersionInfo->lBuild);  	fprintf(stdout, "%s\r\n", pVersionInfo->Version);  	fprintf(stdout, "%s\r\n", pVersionInfo->BuildDate);  	fprintf(stdout, "%s\r\n", pVersionInfo->CopyRight);
        //读取bmp图片数据
        ASVLOFFSCREEN offInput = { 0 };
        offInput.u32PixelArrayFormat = ASVL_PAF_RGB24_B8G8R8;  	offInput.ppu8Plane[0] = nullptr;
        readBmp(INPUT_IMAGE_PATH, (uint8_t**)&offInput.ppu8Plane[0],
    &offInput.i32Width, &offInput.i32Height);
        if (!offInput.ppu8Plane[0])
        {
            fprintf(stderr, "fail to ReadBmp(%s)\r\n", INPUT_IMAGE_PATH);
            AFT_FSDK_UninitialFaceEngine(hEngine);  	 	free(pWorkMem);
            return -1;
        }
        else
        {
            fprintf(stdout, "Picture width : %d , height : %d \r\n", offInput.i32Width, offInput.i32Height);
        }
        offInput.pi32Pitch[0] = offInput.i32Width * 3;
        //人脸跟踪
        int nRepeat = 0;
        while (nRepeat++ <10)
        {
            nRet = AFT_FSDK_FaceFeatureDetect(hEngine, &offInput, &FaceRes);  	 	if (nRet == MOK)
            {
                fprintf(stdout, "The number of face: %d\r\n", FaceRes->nFace);
                for (int i = 0; i < FaceRes->nFace; ++i)
                {
                    fprintf(stdout, "Repeat [%d] ,Face[%d]:
    rect[%d,%d,%d,%d]\r\n", nRepeat, i, FaceRes->rcFace[i].left, FaceRes-
    >rcFace[i].top, FaceRes->rcFace[i].right, FaceRes->rcFace[i].bottom);
                }
            }
            else
            {

    nRet); 	 	fprintf(stderr, "Face Detection failed, error code: %d\r\n",

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