/* 第一种:原图片格式方法 */
#include "stdafx.h"
#include "stdlib.h"
#include "arcsoft_fsdk_fic.h"
#pragma comment(lib,"libarcsoft_fsdk_fic.lib")
#define APPID "" //APPID
#define SDKKey "" //SDKKey
int main() {
/* 初始化人证比对引擎*/
MHandle hEngine = NULL;
MRESULT res = ArcSoft_FIC_InitialEngine(APPID, SDKKey, &hEngine);
if (res != MOK) {
printf("Initial Engine failed, error code: %d\n", res);
return -1;
}
/* 读取预览静态图片信息,并保存到ASVLOFFSCREEN结构体 (以ASVL_PAF_RGB24_B8G8R8 格式为例) 图片数据为BGR原始数据 */
ASVLOFFSCREEN imgInfo0 = { 0 };
imgInfo0.i32Width = IMAGE_WIDTH;
imgInfo0.i32Height = IMAGE_HEIGHT;
imgInfo0.u32PixelArrayFormat = ASVL_PAF_RGB24_B8G8R8;
imgInfo0.pi32Pitch[0] = imgInfo0.i32Width * 3;
imgInfo0.ppu8Plane[0] = (MUInt8*)malloc(imgInfo0.i32Height*imgInfo0.pi32Pitch[0]);
FILE* fp1 = fopen("IMAGE_PATH", "rb");
if (fp1) {
fread(imgInfo0.ppu8Plane[0],
imgInfo0.i32Height*imgInfo0.pi32Pitch[0], 1, fp1);
fclose(fp1);
}
/* 人脸特征提取 0-静态图片 1-视频 */
LPAFIC_FSDK_FACERES pFaceRes=(LPAFIC_FSDK_FACERES)malloc(sizeof(AFIC_FSDK_FACERES));
MRESULT res = ArcSoft_FIC_FaceDataFeatureExtraction(hEngine, 0, &imgInfo0, pFaceRes);
if (res != MOK) {
printf("Face Feature Extraction failed, error code: %d\n", res);
return -1;
}
/* 读取证件照静态图片信息,并保存到ASVLOFFSCREEN结构体 (以 ASVL_PAF_RGB24_B8G8R8格式为例) 图片数据为BGR原始数据 */
ASVLOFFSCREEN imgInfo1 = { 0 };
imgInfo1.i32Width = IMAGE_WIDTH; imgInfo1.i32Height = IMAGE_HEIGHT;
imgInfo1.u32PixelArrayFormat = ASVL_PAF_RGB24_B8G8R8;
imgInfo1.pi32Pitch[0] = imgInfo1.i32Width * 3;
// imgInfo1.ppu8Plane[0] = (MUInt8*)malloc(imgInfo1.i32Height*imgInfo1.pi32Pitch[0]);
FILE* fp2 = fopen("IMAGE_PATH", "rb");
if (fp2) {
fread(imgInfo1.ppu8Plane[0], imgInfo1.i32Height*imgInfo1.pi32Pitch[0], 1, fp1);
fclose(fp2);
}
/* 证件照特征提取 */
MRESULT res = ArcSoft_FIC_IdCardDataFeatureExtraction(hEngine, &imgInfo1);
if (res != MOK) {
printf("IdCard Feature Extraction failed, error code: %d\n", res);
return -1;
}
/* 人证比对 */
MFloat pSimilarScore = 0.0f;
MInt32 pResult = 0;
MFloat g_threshold = 0.82;
MRESULT res = ArcSoft_FIC_FaceIdCardCompare(hEngine, g_threshold, &pSimilarScore, &pResult);
if (res != MOK) {
printf("Face IdCard Compare failed, error code: %d\n", res);
return -1;
}
/* 反初始化引擎 */
MRESULT res = ArcSoft_FIC_UninitialEngine(hEngine);
if (res != MOK) {
printf("Uninitial Engine failed, error code: %d\n", res);
return -1;
}
free(pFaceRes);
free(imgInfo0.ppu8Plane[0]);
free(imgInfo1.ppu8Plane[0]);
return 0;
}
/* 第二种:OpenCv方法 */
#include "stdafx.h"
#include
#include "arcsoft_fsdk_fic.h"
#pragma comment(lib,"libarcsoft_fsdk_fic.lib")
#pragma comment(lib,"mpbase.lib")
#define APPID "" //APPID
#define SDKKey "" //SDKKey
int main() {
IplImage* img0 = cvLoadImage("");
IplImage* img1 = cvLoadImage("");
if (img0 && img1) { /* 初始化人证比对引擎*/
MHandle hEngine = NULL;
MRESULT res = ArcSoft_FIC_InitialEngine(APPID, SDKKey, &hEngine);
if (res != MOK) {
printf("Initial Engine failed, error code: %d\n", res);
return -1;
} /* 读取预览静态图片信息,并保存到ASVLOFFSCREEN结构体 (以 ASVL_PAF_RGB24_B8G8R8格式为例) 图片数据为BGR原始数据 */
ASVLOFFSCREEN imgInfo0 = { 0 };
imgInfo0.i32Width = img0->width;
imgInfo0.i32Height = img0->height;
imgInfo0.u32PixelArrayFormat = ASVL_PAF_RGB24_B8G8R8;
imgInfo0.pi32Pitch[0] = imgInfo0.i32Width * 3;
imgInfo0.ppu8Plane[0] = (MUInt8*)img0->imageData; /* 人脸特征提取 0-静态图片 1-视频 */
LPAFIC_FSDK_FACERES pFaceRes=(LPAFIC_FSDK_FACERES)malloc(sizeof(AFIC_FSDK_FACERES));
MRESULT res = ArcSoft_FIC_FaceDataFeatureExtraction(hEngine, 0, &imgInfo0, pFaceRes);
if (res != MOK) {
printf("Face Feature Extraction failed, error code: %d\n", res);
return -1;
}
/* 读取证件照静态图片信息,并保存到ASVLOFFSCREEN结构体 (以 ASVL_PAF_RGB24_B8G8R8格式为例) 图片数据为BGR原始数据 */
ASVLOFFSCREEN imgInfo1 = { 0 };
imgInfo1.i32Width = img1->width;
imgInfo1.i32Height = img1->height;
imgInfo1.u32PixelArrayFormat = ASVL_PAF_RGB24_B8G8R8;
imgInfo1.pi32Pitch[0] = imgInfo1.i32Width * 3;
imgInfo1.ppu8Plane[0] = (MUInt8*)img1->imageData;
/* 证件照特征提取 */
MRESULT res = ArcSoft_FIC_IdCardDataFeatureExtraction(hEngine, &imgInfo1);
if (res != MOK) {
printf("IdCard Feature Extraction failed, error code: %d\n", res);
return -1;
}
/* 人证比对 */
MFloat pSimilarScore = 0.0f;
MInt32 pResult = 0;
MFloat g_threshold = 0.82;
MRESULT res = ArcSoft_FIC_FaceIdCardCompare(hEngine, g_threshold, &pSimilarScore, &pResult);
if (res != MOK) {
printf("Face IdCard Compare failed, error code: %d\n", res);
return -1;
}
/* 反初始化引擎 */
MRESULT res = ArcSoft_FIC_UninitialEngine(hEngine);
if (res != MOK) {
printf("Uninitial Engine failed, error code: %d\n", res);
return -1;
}
}
cvReleaseImage(&img0);
cvReleaseImage(&img1);
return 0;
}