1030 changed files with 395854 additions and 0 deletions
@ -0,0 +1,90 @@ |
|||||
|
#ifndef CWFaceAttribute_H |
||||
|
#define CWFaceAttribute_H |
||||
|
|
||||
|
#include "CWFaceConfig.h" |
||||
|
|
||||
|
|
||||
|
#if defined (__cplusplus) |
||||
|
extern "C" { |
||||
|
#endif |
||||
|
|
||||
|
|
||||
|
|
||||
|
/**
|
||||
|
* 功能:创建年龄段性别人种属性句柄 |
||||
|
* 输入: |
||||
|
* pConfigurePath - 模型配置文件 |
||||
|
* pLicence - 授权码(仅用于安卓平台,PC端传NULL即可) |
||||
|
* 输出: |
||||
|
* errCode - 成功返回CW_OK,失败返回其他 |
||||
|
* 返回值: |
||||
|
* void* - 属性句柄: 成功返回句柄,失败返回0 |
||||
|
*/ |
||||
|
CW_FACE_API |
||||
|
void* cwCreateAttributeHandle(cw_errcode_t* errCode, const char* pConfigurePath, const char* pLicence); |
||||
|
|
||||
|
|
||||
|
/**
|
||||
|
* 功能:释放年龄段性别人种属性句柄 |
||||
|
* 输入: |
||||
|
* pAttributeHandle - 属性句柄 |
||||
|
* 输出: |
||||
|
* 无 |
||||
|
* 返回值: |
||||
|
* 无 |
||||
|
*/ |
||||
|
CW_FACE_API |
||||
|
void cwReleaseAttributeHandle(void* pAttributeHandle); |
||||
|
|
||||
|
|
||||
|
/**
|
||||
|
* 功能:获得年龄段估计 |
||||
|
* 输入: |
||||
|
* pAttributeHandle - 属性句柄 |
||||
|
* pAlignedFace - 对齐人脸数据 |
||||
|
* 输出: |
||||
|
* pAgeGroup - 年龄估计值 |
||||
|
* 返回值: |
||||
|
* 错误码 |
||||
|
*/ |
||||
|
CW_FACE_API |
||||
|
cw_errcode_t cwGetAgeEval(void* pAttributeHandle, cw_aligned_face_t* pAlignedFace, int* pAgeGroup); |
||||
|
|
||||
|
|
||||
|
/**
|
||||
|
* 功能:获得性别估计 |
||||
|
* 输入: |
||||
|
* pAttributeHandle - 属性句柄 |
||||
|
* pAlignedFace - 对齐人脸数据 |
||||
|
* 输出: |
||||
|
* pGender - 性别估计值,0 女性, 1 男性 |
||||
|
* confidence - 置信度,0-1之间的小数, 值越大可信度越高 |
||||
|
* 返回值: |
||||
|
* 错误码 |
||||
|
*/ |
||||
|
CW_FACE_API |
||||
|
cw_errcode_t cwGetGenderEval(void* pAttributeHandle, cw_aligned_face_t* pAlignedFace, int* pGender, float* confidence); |
||||
|
|
||||
|
|
||||
|
/**
|
||||
|
* 功能:获得人种估计 |
||||
|
* 输入: |
||||
|
* pAttributeHandle - 属性句柄 |
||||
|
* pAlignedFace - 对齐人脸数据 |
||||
|
* 输出: |
||||
|
* pRace - 人种估计值,0 黑人 1 白人 2 黄人 |
||||
|
* confidence - 置信度,0-1之间的小数, 值越大可信度越高 |
||||
|
* 返回值: |
||||
|
* 错误码 |
||||
|
*/ |
||||
|
CW_FACE_API |
||||
|
cw_errcode_t cwGetRaceEval(void* pAttributeHandle, cw_aligned_face_t* pAlignedFace, int* pRace, float* confidence); |
||||
|
|
||||
|
|
||||
|
#if defined (__cplusplus) |
||||
|
} |
||||
|
#endif |
||||
|
|
||||
|
|
||||
|
#endif |
||||
|
|
||||
@ -0,0 +1,371 @@ |
|||||
|
#ifndef CWFaceDefine_H |
||||
|
#define CWFaceDefine_H |
||||
|
|
||||
|
|
||||
|
#ifdef CWFACESDK_EXPORTS |
||||
|
#define CW_FACE_API __declspec(dllexport) |
||||
|
#else |
||||
|
#define CW_FACE_API |
||||
|
#endif |
||||
|
|
||||
|
|
||||
|
/***************
|
||||
|
* 检测功能开关选项 |
||||
|
*/ |
||||
|
#define CW_OP_DET 0 // (1<<0)进行人脸检测,并返回人脸矩形位置,默认开启
|
||||
|
#define CW_OP_TRACK 2 // (1<<1)进行人脸跟踪,并返回人脸跟踪的ID
|
||||
|
#define CW_OP_KEYPT 4 // (1<<2)进行人脸关键点检测,并返回人脸上的关键点坐标信息
|
||||
|
#define CW_OP_ALIGN 8 // (1<<3)进行人脸图像对齐,并返回对齐后的人脸图像,用来提取特征
|
||||
|
#define CW_OP_QUALITY 16 // (1<<4)人脸质量评估开关(质量分子项开关在配置文件中配置)
|
||||
|
#define CW_OP_ALL 30 // (所有开关综合)总开关
|
||||
|
|
||||
|
|
||||
|
/***************
|
||||
|
* 通用错误码 |
||||
|
*/ |
||||
|
typedef enum cw_errcode |
||||
|
{ |
||||
|
CW_SDKLIT_OK = 0, // 成功 or 合法
|
||||
|
|
||||
|
CW_UNKNOWN_ERR = 20000, // 未知错误
|
||||
|
CW_DETECT_INIT_ERR, // 初始化人脸检测器失败:如加载模型失败等
|
||||
|
CW_KEYPT_INIT_ERR, // 初始化关键点检测器失败:如加载模型失败等
|
||||
|
CW_QUALITY_INIT_ERR, // 初始化跟踪器失败:如加载模型失败等
|
||||
|
|
||||
|
CW_DET_ERR, // 检测失败
|
||||
|
CW_TRACK_ERR, // 跟踪失败
|
||||
|
CW_KEYPT_ERR, // 提取关键点失败
|
||||
|
CW_ALIGN_ERR, // 对齐人脸失败
|
||||
|
CW_QUALITY_ERR, // 质量评估失败
|
||||
|
|
||||
|
CW_EMPTY_FRAME_ERR, // 空图像
|
||||
|
CW_UNSUPPORT_FORMAT_ERR, // 图像格式不支持
|
||||
|
CW_ROI_ERR, // ROI设置失败
|
||||
|
CW_UNINITIALIZED_ERR, // 尚未初始化
|
||||
|
CW_MINMAX_ERR, // 最小最大人脸设置失败
|
||||
|
CW_OUTOF_RANGE_ERR, // 数据范围错误
|
||||
|
CW_UNAUTHORIZED_ERR, // 未授权
|
||||
|
CW_PARAM_INVALID, // 参数无效
|
||||
|
CW_METHOD_UNAVAILABLE, // 方法无效
|
||||
|
CW_BUFFER_EMPTY, // 缓冲区空
|
||||
|
|
||||
|
CW_FILE_UNAVAILABLE, // 文件不存在:如加载的模型不存在等.
|
||||
|
CW_DEVICE_UNAVAILABLE, // 设备不存在
|
||||
|
CW_DEVICE_ID_UNAVAILABLE, // 设备id不存在
|
||||
|
CW_EXCEEDMAXHANDLE_ERR, // 超过授权最大句柄数
|
||||
|
|
||||
|
CW_RECOG_FEATURE_MODEL_ERR, // 加载特征识别模型失败
|
||||
|
CW_RECOG_ALIGNEDFACE_ERR, // 对齐图片数据错误
|
||||
|
CW_RECOG_MALLOCMEMORY_ERR, // 预分配特征空间不足
|
||||
|
|
||||
|
CW_RECOG_FEATUREDATA_ERR, // 特征数据错误
|
||||
|
CW_RECOG_EXCEEDMAXFEASPEED, // 超过授权最大提特征速度
|
||||
|
CW_RECOG_EXCEEDMAXCOMSPEED, // 超过授权最大比对速度
|
||||
|
CW_RECOG_GROUPSIZE_ERR, // 特征比对特征数N超过最大授权数
|
||||
|
CW_RECOG_CONVERT_ERR, // 特征转换失败
|
||||
|
CW_RECOG_NOFACEDET, // 未检测到人脸
|
||||
|
|
||||
|
CW_LICENCE_JSON_CREATE_ERR, // Json操作失败
|
||||
|
CW_LICENCE_DECRYPT_ERR, // 加密失败
|
||||
|
CW_LICENCE_HTTP_ERROR, // HTTP失败
|
||||
|
CW_LICENCE_MALLOCMEMORY_ERR, // 授权内存分配不足
|
||||
|
CW_LICENCE_KEY_DEVICE_ERR, // 获取设备文件错误
|
||||
|
CW_LICENCE_KEY_LICENSE_ERR, // 获取授权文件错误
|
||||
|
CW_LICENCE_KEY_INSTALL_ERR, // 安装授权文件错误
|
||||
|
|
||||
|
CW_ATTRI_AGEGENDER_MODEL_ERR, //加载年龄性别模型失败
|
||||
|
CW_ATTRI_EVAL_AGE_ERR, //年龄识别失败
|
||||
|
CW_ATTRI_EVAL_GENDER_ERR, //性别识别失败
|
||||
|
CW_ATTRI_EVAL_RACE_ERR, //种族识别失败
|
||||
|
} cw_errcode_t; |
||||
|
|
||||
|
/***************
|
||||
|
* 关键点信息 |
||||
|
*/ |
||||
|
#define CW_MAX_KEYPT_NUM 68 |
||||
|
typedef struct cw_point |
||||
|
{ |
||||
|
float x; |
||||
|
float y; |
||||
|
} cw_point_t; |
||||
|
|
||||
|
typedef struct cw_keypt |
||||
|
{ |
||||
|
cw_point_t points[CW_MAX_KEYPT_NUM]; // 关键点
|
||||
|
int nkeypt; // 关键点个数
|
||||
|
float keyptScore; // 关键点得分,推荐阈值为0.7
|
||||
|
} cw_keypt_t; |
||||
|
|
||||
|
|
||||
|
/***************
|
||||
|
* 质量分检测错误码 |
||||
|
*/ |
||||
|
typedef enum cw_quality_errcode |
||||
|
{ |
||||
|
CW_QUALITY_OK = 0, // 质量分数据有效
|
||||
|
CW_QUALITY_NO_DATA = 20150, // 质量分数据无效,原因:尚未检测
|
||||
|
CW_QUALITY_ERROR_UNKNOWN, // 未知错误
|
||||
|
} cw_quality_errcode_t; |
||||
|
|
||||
|
|
||||
|
/***************
|
||||
|
* 接口功能参数 |
||||
|
*/ |
||||
|
typedef struct cw_det_param |
||||
|
{ |
||||
|
int roiX; // roi, 默认整帧图像0, 0, 0, 0 若设置为异常值检测阶段将恢复默认
|
||||
|
int roiY; |
||||
|
int roiWidth; |
||||
|
int roiHeight; |
||||
|
|
||||
|
int minSize; // 检测人脸尺寸范围: pc端默认[48,600];移动端默认[100,400]
|
||||
|
int maxSize; |
||||
|
const char* pConfigFile; // 内部参数配置文件路径,此参数只能设置(set);从句柄内部获取出来的一律无效
|
||||
|
} cw_det_param_t; |
||||
|
|
||||
|
|
||||
|
/***************
|
||||
|
* 图像旋转角度(逆时针) |
||||
|
*/ |
||||
|
typedef enum cw_img_angle |
||||
|
{ |
||||
|
CW_IMAGE_ANGLE_0 = 0, |
||||
|
CW_IMAGE_ANGLE_90, |
||||
|
CW_IMAGE_ANGLE_180, |
||||
|
CW_IMAGE_ANGLE_270 |
||||
|
} cw_img_angle_t; |
||||
|
|
||||
|
|
||||
|
/***************
|
||||
|
* 图像镜像 |
||||
|
*/ |
||||
|
typedef enum cw_img_mirror |
||||
|
{ |
||||
|
CW_IMAGE_MIRROR_NONE = 0, // 不镜像
|
||||
|
CW_IMAGE_MIRROR_HOR, // 水平镜像
|
||||
|
CW_IMAGE_MIRROR_VER, // 垂直镜像
|
||||
|
CW_IMAGE_MIRROR_HV // 垂直和水平镜像
|
||||
|
} cw_img_mirror_t; |
||||
|
|
||||
|
|
||||
|
/***************
|
||||
|
* 图像格式 |
||||
|
*/ |
||||
|
typedef enum cw_img_form |
||||
|
{ |
||||
|
CW_IMAGE_GRAY8 = 0, |
||||
|
CW_IMAGE_BGR888, |
||||
|
CW_IMAGE_BGRA8888, |
||||
|
CW_IMAGE_RGB888, |
||||
|
CW_IMAGE_RGBA8888, |
||||
|
CW_IMAGE_YUV420P, |
||||
|
CW_IMAGE_YV12, |
||||
|
CW_IMAGE_NV12, |
||||
|
CW_IMAGE_NV21, |
||||
|
CW_IMAGE_BINARY, |
||||
|
} cw_img_form_t; |
||||
|
|
||||
|
|
||||
|
/***************
|
||||
|
* 图像 |
||||
|
*/ |
||||
|
typedef struct cw_img |
||||
|
{ |
||||
|
long long frameId; // 帧号
|
||||
|
char* data; // 图像数据(必须预分配足够的空间)
|
||||
|
int dataLen; // 数据长度,CW_IMAGE_BINARY格式必须设置,其他格式可不设
|
||||
|
int width; // 宽, CW_IMAGE_BINARY格式可不设,其他格式必须设置
|
||||
|
int height; // 高, CW_IMAGE_BINARY格式可不设,其他格式必须设置
|
||||
|
cw_img_form_t format; // 图像格式
|
||||
|
cw_img_mirror_t mirror; // 镜像
|
||||
|
cw_img_angle_t angle; // 旋转角度
|
||||
|
} cw_img_t; |
||||
|
|
||||
|
|
||||
|
/***************
|
||||
|
* 人脸区域 |
||||
|
*/ |
||||
|
typedef struct cw_facepos_rect |
||||
|
{ |
||||
|
int x; |
||||
|
int y; |
||||
|
int width; |
||||
|
int height; |
||||
|
} cw_facepos_rect_t; |
||||
|
|
||||
|
|
||||
|
/***************
|
||||
|
* 对齐人脸图像结构 |
||||
|
*/ |
||||
|
#define CW_ALIGNED_SIZE 128 |
||||
|
typedef struct cw_aligned_face |
||||
|
{ |
||||
|
char data[CW_ALIGNED_SIZE * CW_ALIGNED_SIZE]; // 对齐人脸图像数据
|
||||
|
int width; // 宽
|
||||
|
int height; // 高
|
||||
|
int nChannels; // 图像通道
|
||||
|
} cw_aligned_face_t; |
||||
|
|
||||
|
|
||||
|
/***************
|
||||
|
* 人脸质量分 |
||||
|
*/ |
||||
|
#define FACE_QUALITY_MAX_COUNT 20 |
||||
|
typedef struct cw_quality |
||||
|
{ |
||||
|
cw_quality_errcode_t errcode; // 质量分析错误码
|
||||
|
float scores[FACE_QUALITY_MAX_COUNT]; /* 质量分分数项,具体含义(根据数据下标顺序):
|
||||
|
* 0 - 人脸质量总分,0.72 |
||||
|
* 1 - 清晰度,越大表示越清晰,推荐范围0.65-1.0(在启用第16个项mog分数的总分时,此分数为常数1.0,请忽略) |
||||
|
* 2 - 亮度,越大表示越亮,推荐范围0.2-0.8 |
||||
|
* 3 - 人脸角度,左转为正,右转为负 |
||||
|
* 4 - 人脸角度,抬头为正,低头为负 |
||||
|
* 5 - 人脸角度,顺时针为正,逆时针为负 |
||||
|
* 6 - 左右转程度,越大表示角度越正,推荐范围0.5-1.0 |
||||
|
* 7 - 抬低头程度,越大表示角度越正,推荐范围0.5-1.0 |
||||
|
* 8 - 肤色接近真人肤色程度,越大表示越真实,推荐范围0.5-1.0 |
||||
|
* 9 - 张嘴分数, 越大表示越可能张嘴,推荐范围0.0-0.5 |
||||
|
* 10 - 左眼睁眼分数, 越大表示左眼越可能是睁眼,推荐范围0.5-1.0 |
||||
|
* 11 - 右眼睁眼分数, 越大表示右眼越可能是睁眼,推荐范围0.5-1.0 |
||||
|
* 12 - 戴黑框眼镜置信度,越大表示戴黑框眼镜的可能性越大,推荐范围0.0-0.5 |
||||
|
* 13 - 戴墨镜的置信分,越大表示戴墨镜的可能性越大,推荐范围0.0-0.5 |
||||
|
* 14 - 左眼眼睛被遮挡的置信度,越大表示眼镜越可能被遮挡,目前只在睁眼分小于0.5时有意义,推荐范围0.0-0.5 |
||||
|
* 15 - 右眼眼睛被遮挡的置信度,越大表示眼镜越可能被遮挡,目前只在睁眼分小于0.5时有意义,推荐范围0.0-0.5 |
||||
|
* 16 - mog清晰度,返回0.0~1.0的分数,越大越清晰,阈值建议0.100001 |
||||
|
* 17 - 口罩分,0.0~1.0,越大表示越不可能带口罩,建议阈值0.44左右.(注意要用支持口罩检测的检测模型) |
||||
|
*/ |
||||
|
} cw_quality_t; |
||||
|
|
||||
|
|
||||
|
/***************
|
||||
|
* 人脸综合信息 |
||||
|
*/ |
||||
|
typedef struct cw_face_res |
||||
|
{ |
||||
|
long long frameId; // 人脸所在帧号
|
||||
|
|
||||
|
int detected; // 0: 跟踪到的人脸; 1: 检测到的人脸; 2:检测到但不会被进行后续计算(关键点)的人脸;
|
||||
|
// 3: 可能是静态误检框;4:大角度人脸; 5:关键点错误; 6:不需再处理的人脸(只有标记为1的人脸,关键点、
|
||||
|
// 对齐、质量分才有效;但除0之外其他都可能有口罩分)7:被估计为低质量人脸
|
||||
|
|
||||
|
int trackId; // 人脸ID(ID<0表示没有进入跟踪)
|
||||
|
|
||||
|
cw_facepos_rect_t faceRect; // 人脸框
|
||||
|
|
||||
|
cw_keypt_t keypt; // 关键点
|
||||
|
|
||||
|
cw_aligned_face_t faceAligned; // 对齐人脸
|
||||
|
|
||||
|
cw_quality_t quality; // 人脸质量
|
||||
|
|
||||
|
} cw_face_res_t; |
||||
|
|
||||
|
|
||||
|
/***************
|
||||
|
* 人脸识别句柄模式 |
||||
|
*/ |
||||
|
typedef enum cw_recog_pattern |
||||
|
{ |
||||
|
CW_FEATURE_EXTRACT = 0, // 特征提取
|
||||
|
CW_RECOGNITION = 1 // 识 别
|
||||
|
} cw_recog_pattern_t; |
||||
|
|
||||
|
|
||||
|
|
||||
|
|
||||
|
//////////////////////////////////////////////////////////////////////////红外活体
|
||||
|
|
||||
|
/***************
|
||||
|
* 红外活体检测结果返回值 |
||||
|
*/ |
||||
|
typedef enum cw_nirliv_det_rst |
||||
|
{ |
||||
|
CW_NIR_LIV_DET_LIVE = 0, // 以阈值0.5判断为活体
|
||||
|
CW_NIR_LIV_DET_UNLIVE, // 以阈值0.5判断为非活体
|
||||
|
CW_NIR_LIV_DET_DIST_FAILED, // 人脸距离检测未通过
|
||||
|
CW_NIR_LIV_DET_SKIN_FAILED, // 人脸肤色检测未通过
|
||||
|
CW_NIR_LIV_DET_NO_PAIR_FACE, // 未匹配到人脸
|
||||
|
CW_NIR_LIV_DET_IS_INIT // 红外活体检测结果初始值
|
||||
|
}cw_nirliv_det_rst_t; |
||||
|
|
||||
|
/***************
|
||||
|
* 红外活体检测错误码 |
||||
|
*/ |
||||
|
typedef enum cw_nirliveness_err |
||||
|
{ |
||||
|
CW_NIRLIV_OK = 0, // 成功返回
|
||||
|
CW_NIRLIV_ERR_CREATE_HANDLE = 26000, // 创建红外活体检测句柄失败
|
||||
|
CW_NIRLIV_ERR_FREE_HANDLE, // 释放红外活体检测句柄失败
|
||||
|
CW_NIRLIV_ERR_FACE_PAIR, // 人脸匹配初始化失败
|
||||
|
CW_NIRLIV_ERR_CREAT_LOG_DIR, // 创建日志路径失败
|
||||
|
CW_NIRLIV_ERR_MODEL_NOTEXIST, // 输入模型不存在
|
||||
|
CW_NIRLIV_ERR_MODEL_FAILED, // 输入模型初始化失败
|
||||
|
CW_NIRLIV_ERR_INPUT_UNINIT, // 输入未初始化
|
||||
|
CW_NIRLIV_ERR_NIR_NO_FACE, // 输入红外图片没有人脸
|
||||
|
CW_NIRLIV_ERR_VIS_NO_FACE, // 输入可见光图片没有人脸
|
||||
|
CW_NIRLIV_ERR_NO_PAIR_FACE, // 输入可见光和红外图片人脸未能匹配
|
||||
|
CW_NIRLIV_ERR_PUSH_DATA, // 输入数据失败
|
||||
|
CW_NIRLIV_ERR_NUM_LANDMARKS, // 输入可见光图片和红外图片关键点个数不等
|
||||
|
CW_NIRLIV_ERR_NO_LANDMARKS, // 输入红外图片没有人脸关键点
|
||||
|
CW_NIRLIV_ERR_INPUT_IMAGE, // 输入红外图片或者可见光图片不是多通道
|
||||
|
CW_NIRLIV_ERR_UNAUTHORIZED, // 没有license(未授权)
|
||||
|
CW_NIRLIV_ERR_FACE_NUM_ERR, // 未开启人脸匹配开关时,可见光或红外图像人脸大于1
|
||||
|
CW_NIRLIV_ERR_CAM_UNCW, // 非云从定制摄像头
|
||||
|
CW_NIRLIV_ERR_UNKNOWN, // 未知结果
|
||||
|
CW_NIRLIV_ERR_MAXHANDLE, // 超过最大红外活体最大授权句柄数
|
||||
|
CW_NIRLIV_ERR_NIRIMAGE, // 输入红外图片数据错误
|
||||
|
CW_NIRLIV_ERR_VISIMAGE, // 输入可见光图片数据错误
|
||||
|
} cw_nirliveness_err_t; |
||||
|
|
||||
|
/***************
|
||||
|
* 红外活体图像数据 |
||||
|
*/ |
||||
|
typedef struct cw_nirliv_img |
||||
|
{ |
||||
|
char* data; // 图像数据(必须预分配足够的空间)
|
||||
|
int dataLen; // 数据长度,只有CW_IMAGE_BINARY格式需要设置
|
||||
|
int width; // 宽, CW_IMAGE_BINARY格式可不设置,其他格式必须设置
|
||||
|
int height; // 高, CW_IMAGE_BINARY格式可不设置,其他格式必须设置
|
||||
|
cw_img_form_t format; // 图像格式,详情见cw_img_form_t
|
||||
|
} cw_nirliv_img_t; |
||||
|
|
||||
|
|
||||
|
/***************
|
||||
|
* 红外活体人脸相关信息 |
||||
|
*/ |
||||
|
|
||||
|
typedef struct cw_nirliv_face_param |
||||
|
{ |
||||
|
float fSkinScore; // 输入肤色置信分
|
||||
|
float fKeyScore; // 输入关键点置信分
|
||||
|
cw_point_t *pKeypoints; // 输入关键点信息
|
||||
|
} cw_nirliv_face_param_t; |
||||
|
|
||||
|
|
||||
|
/***************
|
||||
|
* 红外活体检测输入的人脸图片数据 |
||||
|
*/ |
||||
|
typedef struct cw_nirliv_detinfo |
||||
|
{ |
||||
|
int nLandmarks; // 关键点个数
|
||||
|
|
||||
|
cw_nirliv_img_t *pNirImg; // NIR红外图片信息
|
||||
|
cw_nirliv_img_t *pVisImg; // VIS可见光图片信息
|
||||
|
|
||||
|
cw_nirliv_face_param_t *pNirInfo; // NIR红外人脸信息
|
||||
|
cw_nirliv_face_param_t *pVisInfo; // VIS可见光人脸信息
|
||||
|
} cw_nirliv_detinfo_t; |
||||
|
|
||||
|
|
||||
|
/***************
|
||||
|
* 红外活体检测结果 |
||||
|
*/ |
||||
|
typedef struct cw_nirliv_res |
||||
|
{ |
||||
|
cw_nirliv_det_rst_t livRst; // 输出红外活体检测结果返回值
|
||||
|
float score; // 输出红外活体检测得分,非活体的时候为0
|
||||
|
} cw_nirliv_res_t; |
||||
|
|
||||
|
|
||||
|
#endif |
||||
|
|
||||
@ -0,0 +1,107 @@ |
|||||
|
#ifndef CWFaceDetection_H |
||||
|
#define CWFaceDetection_H |
||||
|
|
||||
|
#include "CWFaceConfig.h" |
||||
|
|
||||
|
#if defined (__cplusplus) |
||||
|
extern "C" { |
||||
|
#endif |
||||
|
|
||||
|
/**
|
||||
|
* 功能:创建检测器句柄 |
||||
|
* 输入: |
||||
|
* pConfigFile - 模型参数配置文件 |
||||
|
* pLicense - 授权码(仅用于安卓平台,PC端传NULL即可) |
||||
|
* 输出: |
||||
|
* errCode - 成功返回CW_SDKLIT_OK,失败返回其他 |
||||
|
* 返回值: |
||||
|
* 检测器句柄 - 成功返回句柄,失败返回0 |
||||
|
*/ |
||||
|
CW_FACE_API |
||||
|
void* cwCreateDetHandle(cw_errcode_t* errCode, const char* pConfigFile, const char* pLicense); |
||||
|
|
||||
|
|
||||
|
/**
|
||||
|
* 功能:释放检测器 |
||||
|
* 输入: |
||||
|
* pDetector - 检测器句柄 |
||||
|
* 输出: |
||||
|
* 无 |
||||
|
* 返回值: |
||||
|
* 无 |
||||
|
*/ |
||||
|
CW_FACE_API |
||||
|
void cwReleaseDetHandle(void* pDetector); |
||||
|
|
||||
|
|
||||
|
/**
|
||||
|
* 功能:获取检测器参数 |
||||
|
* 输入: |
||||
|
* pDetector - 检测器句柄 |
||||
|
* 输出: |
||||
|
* param - 检测器参数 |
||||
|
* 返回值: |
||||
|
* cw_errcode_t - 成功返回CW_SDKLIT_OK,失败返回其他 |
||||
|
*/ |
||||
|
CW_FACE_API |
||||
|
cw_errcode_t cwGetFaceParam(void* pDetector, cw_det_param_t* param); |
||||
|
|
||||
|
|
||||
|
/**
|
||||
|
* 功能:设置检测器参数(必须先调用cwGetFaceParam再使用此函数) |
||||
|
* 输入: |
||||
|
* pDetector - 检测器句柄 |
||||
|
* param - 参数 |
||||
|
* 输出: |
||||
|
* 无 |
||||
|
* 返回值: |
||||
|
* cw_errcode_t - 成功返回CW_SDKLIT_OK,失败返回其他 |
||||
|
*/ |
||||
|
CW_FACE_API |
||||
|
cw_errcode_t cwSetFaceParam(void* pDetector, const cw_det_param_t* param); |
||||
|
|
||||
|
|
||||
|
/**
|
||||
|
* 功能:人脸检测跟踪接口 |
||||
|
* 输入: |
||||
|
* pDetector - 检测器句柄 |
||||
|
* pFrameImg - 被检测图像 |
||||
|
* iBuffLen - 存放检测结果pFaceBuffer数组的元素个数 |
||||
|
* iOp - 操作码 |
||||
|
* 输出: |
||||
|
* pFaceBuffer - 存放检测结果的数组 |
||||
|
* nFaceNum - 实际被检测到的人脸数 |
||||
|
* 返回值: |
||||
|
* cw_errcode_t - 成功返回CW_SDKLIT_OK,失败返回其他 |
||||
|
*/ |
||||
|
CW_FACE_API |
||||
|
cw_errcode_t cwFaceDetection(void* pDetector, |
||||
|
cw_img_t* pFrameImg, |
||||
|
cw_face_res_t* pFaceBuffer, |
||||
|
int iBuffLen, |
||||
|
int* nFaceNum, |
||||
|
int iOp); |
||||
|
|
||||
|
|
||||
|
/**
|
||||
|
* 功能:清除检测跟踪状态信息函数 |
||||
|
* 输入: |
||||
|
* pDetector - 检测器句柄 |
||||
|
* 输出: |
||||
|
* 无 |
||||
|
* 返回值: |
||||
|
* cw_errcode_t - 成功返回CW_SDKLIT_OK,失败返回其他 |
||||
|
*/ |
||||
|
CW_FACE_API |
||||
|
cw_errcode_t cwResetDetTrackState(void* pDetector); |
||||
|
|
||||
|
|
||||
|
|
||||
|
#if defined (__cplusplus) |
||||
|
} |
||||
|
#endif |
||||
|
|
||||
|
|
||||
|
#endif |
||||
|
|
||||
|
|
||||
@ -0,0 +1,86 @@ |
|||||
|
#ifndef CW_NISLIVENESS_DET_SDK_H |
||||
|
#define CW_NISLIVENESS_DET_SDK_H |
||||
|
|
||||
|
|
||||
|
#include "CWFaceConfig.h" |
||||
|
|
||||
|
|
||||
|
#if defined (__cplusplus) |
||||
|
extern "C" { |
||||
|
#endif |
||||
|
|
||||
|
|
||||
|
|
||||
|
/**
|
||||
|
* 创建红外活体检测器 |
||||
|
* 输入: |
||||
|
* sNirModelPath - 红外活体检测器模型文件 |
||||
|
* srecogModelPath - 红外活体识别模型文件 |
||||
|
* pMatrixParaDir - 匹配文件路径,只支持640*480以及480*640分辨率 |
||||
|
* pLogPath - 要保存log的目录 |
||||
|
* fSkinThresh - 肤色阈值,默认0.35 |
||||
|
* pLicence - 授权码(仅用于安卓平台,PC端传NULL即可) |
||||
|
* 输出: |
||||
|
* errCode - 红外活体错误码 |
||||
|
* 返回值: |
||||
|
* 红外活体句柄 - 成功返回句柄,失败返回0 |
||||
|
*/ |
||||
|
CW_FACE_API |
||||
|
void* cwCreateNirLivenessHandle(cw_nirliveness_err_t *errCode, |
||||
|
const char *pNirModelPath, |
||||
|
const char *pRecogModelPath, |
||||
|
const char *pPairFilePath, |
||||
|
const char *pLogPath, |
||||
|
const float skinThresh, |
||||
|
const char *pLicence ); |
||||
|
|
||||
|
|
||||
|
/**
|
||||
|
* 释放红外活体句柄 |
||||
|
* 输入: |
||||
|
* pHandle - 红外活体句柄 |
||||
|
* 输出: |
||||
|
* 无 |
||||
|
* 返回值: |
||||
|
* 无 |
||||
|
*/ |
||||
|
CW_FACE_API |
||||
|
void cwReleaseNirLivenessHandle(void *pHandle); |
||||
|
|
||||
|
|
||||
|
/**
|
||||
|
* 红外活体检测接口 |
||||
|
* 输入: |
||||
|
* pHandle - 红外活体句柄 |
||||
|
* pNirLivDetInfo - 输入的红外和可见光图片及关键点等信息 |
||||
|
* 输出: |
||||
|
* pNirLivRes - 红外活体检测结果,需事先分配内存 |
||||
|
* 返回值: |
||||
|
* cw_nirliveness_err_t - 错误码 |
||||
|
*/ |
||||
|
CW_FACE_API |
||||
|
cw_nirliveness_err_t cwFaceNirLivenessDet(void *pHandle, cw_nirliv_detinfo_t *pNirLivDetInfo, cw_nirliv_res_t *pNirLivRes); |
||||
|
|
||||
|
|
||||
|
/**
|
||||
|
* 功能:判断可见光和红外活体中的最大人脸是否为活体 |
||||
|
* 输入: |
||||
|
* pDetector - 检测句柄 |
||||
|
* pNirHandle - 红外句柄 |
||||
|
* pImgVis - 可见光图片数据 |
||||
|
* pImgNir - 红外图片数据 |
||||
|
* 输出: |
||||
|
* pNirLivRes - 存放红外活体检测结果的数组,需事先分配内存 |
||||
|
* 返回值: |
||||
|
* cw_errcode_t - 成功返回CW_SDKLIT_OK,失败返回其他 |
||||
|
*/ |
||||
|
CW_FACE_API |
||||
|
cw_nirliveness_err_t cwFaceNirByImageData(void* pDetector, void* pNirHandle, cw_img_t* pImgVis, cw_img_t* pImgNir, cw_nirliv_res_t *pNirLivRes); |
||||
|
|
||||
|
|
||||
|
|
||||
|
#if defined (__cplusplus) |
||||
|
} |
||||
|
#endif |
||||
|
|
||||
|
#endif |
||||
@ -0,0 +1,115 @@ |
|||||
|
#ifndef CWFaceRecognition_H |
||||
|
#define CWFaceRecognition_H |
||||
|
|
||||
|
|
||||
|
#include "CWFaceConfig.h" |
||||
|
|
||||
|
|
||||
|
|
||||
|
#if defined (__cplusplus) |
||||
|
extern "C" { |
||||
|
#endif |
||||
|
|
||||
|
|
||||
|
|
||||
|
/**
|
||||
|
* 功能:创建识别句柄 |
||||
|
* 输入: |
||||
|
* pConfigurePath - 模型配置文件 |
||||
|
* pLicence - 授权码(仅用于安卓平台,PC端传NULL即可) |
||||
|
* emRecogPattern - 创建的句柄类型 |
||||
|
* 输出: |
||||
|
* errCode - 错误码:成功返回CW_SDKLIT_OK,失败返回其他 |
||||
|
* 返回值: |
||||
|
* void* - 识别句柄:成功返回句柄,失败返回0 |
||||
|
*/ |
||||
|
CW_FACE_API |
||||
|
void* cwCreateRecogHandle(cw_errcode_t* errCode, |
||||
|
const char* pConfigurePath, |
||||
|
const char* pLicence, |
||||
|
cw_recog_pattern_t emRecogPattern); |
||||
|
|
||||
|
|
||||
|
/**
|
||||
|
* 功能:释放识别句柄 |
||||
|
* 输入: |
||||
|
* pRecogHandle - 识别句柄 |
||||
|
* 输出: |
||||
|
* 无 |
||||
|
* 返回值: |
||||
|
* 无 |
||||
|
*/ |
||||
|
CW_FACE_API |
||||
|
void cwReleaseRecogHandle(void* pRecogHandle); |
||||
|
|
||||
|
|
||||
|
/**
|
||||
|
* 功能:获取特征长度 |
||||
|
* 输入: |
||||
|
* pRecogHandle - 识别句柄 |
||||
|
* 输出: |
||||
|
* 无 |
||||
|
* 返回值: |
||||
|
* int - 特征长度 |
||||
|
*/ |
||||
|
CW_FACE_API |
||||
|
int cwGetFeatureLength(void* pRecogHandle); |
||||
|
|
||||
|
|
||||
|
/**
|
||||
|
* 功能:提取人脸特征,一次只提取一个特征 |
||||
|
* 输入: |
||||
|
* pRecogHandle - 识别句柄 |
||||
|
* alignedFace - 对齐的人脸数据指针 |
||||
|
* 输出: |
||||
|
* pFeatueData - 返回的特征数据,需要预先分配足够空间 |
||||
|
* 返回值: |
||||
|
* cw_errcode_t - 成功返回CW_SDKLIT_OK,失败返回其他 |
||||
|
*/ |
||||
|
CW_FACE_API |
||||
|
cw_errcode_t cwGetFaceFeature(void* pRecogHandle, cw_aligned_face_t* alignedFace, void* pFeatueData); |
||||
|
|
||||
|
|
||||
|
|
||||
|
/**
|
||||
|
* 功能:计算1个特征与N个特征的相似度,返回的相似度pScores的个数为N个 |
||||
|
* 输入: |
||||
|
* pRecogHandle - 识别句柄 |
||||
|
* pFea1 - 特征1,只能是一个特征 |
||||
|
* pFea2 - 特征2,可以是N个特征 |
||||
|
* iFea2Num - 特征2的个数 |
||||
|
* 输出: |
||||
|
* pScores - 返回的相似度分数数组,长度为iFea2Num,需要预先分配空间 |
||||
|
* 返回值: |
||||
|
* cw_errcode_t - 成功返回CW_SDKLIT_OK,失败返回其他 |
||||
|
*/ |
||||
|
CW_FACE_API |
||||
|
cw_errcode_t cwComputeMatchScore(void* pRecogHandle, const void* pFea1, const void* pFea2, int iFea2Num, float* pScores); |
||||
|
|
||||
|
|
||||
|
/**
|
||||
|
* 功能:比对两个图片中最大人脸特征,获取相似度 |
||||
|
* 输入: |
||||
|
* pDetector - 检测句柄 |
||||
|
* pRecogHandle - 识别句柄 |
||||
|
* pFrameImg1 - 图片1数据 |
||||
|
* pFrameImg2 - 图片2数据 |
||||
|
* 输出: |
||||
|
* fScore - 比对分数 |
||||
|
* 返回值: |
||||
|
* cw_errcode_t - 成功返回CW_SDKLIT_OK,失败返回其他 |
||||
|
*/ |
||||
|
CW_FACE_API |
||||
|
cw_errcode_t cwVerifyImageData(void* pDetector, void* pRecogHandle, cw_img_t* pFrameImg1, cw_img_t* pFrameImg2, float *fScore); |
||||
|
|
||||
|
|
||||
|
|
||||
|
|
||||
|
#if defined (__cplusplus) |
||||
|
} |
||||
|
#endif |
||||
|
|
||||
|
|
||||
|
|
||||
|
#endif |
||||
|
|
||||
@ -0,0 +1,81 @@ |
|||||
|
#ifndef CWFaceVersion_H |
||||
|
#define CWFaceVersion_H |
||||
|
|
||||
|
|
||||
|
#include "CWFaceConfig.h" |
||||
|
|
||||
|
|
||||
|
#if defined (__cplusplus) |
||||
|
extern "C" { |
||||
|
#endif |
||||
|
|
||||
|
|
||||
|
/**
|
||||
|
* 功能:获取SDK版本信息 |
||||
|
* 输入: |
||||
|
* iBuffLen - 输出buf分配字节长度 |
||||
|
* 输出: |
||||
|
* pVersion - 版本信息,需事先分配内存 |
||||
|
* 返回值: |
||||
|
* cw_errcode_t - 成功返回CW_SDKLIT_OK,失败返回其他 |
||||
|
*/ |
||||
|
CW_FACE_API |
||||
|
cw_errcode_t cwGetSDKVersion(char* pVersion, int iBuffLen); |
||||
|
|
||||
|
|
||||
|
/**
|
||||
|
* 功能:获取设备码 |
||||
|
* 输入: |
||||
|
* iBuffLen - 输出buf分配字节长度,不低于160字节 |
||||
|
* 输出: |
||||
|
* pDeviceInfo - 设备唯一码,需事先分配内存,不低于160字节 |
||||
|
* iUseLen - 输出的设备码的长度 |
||||
|
* 返回值: |
||||
|
* cw_errcode_t - 成功返回CW_SDKLIT_OK,失败返回其他 |
||||
|
*/ |
||||
|
CW_FACE_API |
||||
|
cw_errcode_t cwGetDeviceInfo(char* pDeviceInfo, int iBuffLen, int *iUseLen); |
||||
|
|
||||
|
|
||||
|
/**
|
||||
|
* 功能:通过网络授权安装licence,生成的V2C授权文件会保存在当前目录,用于windows和linux |
||||
|
* 输入: |
||||
|
* sAppKey - 授权AppKey,需从云从科技获取 |
||||
|
* sAppSecret - 授权AppSecret,需从云从科技获取 |
||||
|
* sProductId - 授权ProductId,需从云从科技获取 |
||||
|
* 输出: |
||||
|
* 无 |
||||
|
* 返回值: |
||||
|
* cw_errcode_t - 成功返回CW_SDKLIT_OK,失败返回其他 |
||||
|
*/ |
||||
|
CW_FACE_API |
||||
|
cw_errcode_t cwInstallLicence(const char* sAppKey, const char* sAppSecret, const char* sProductId); |
||||
|
|
||||
|
|
||||
|
/**
|
||||
|
* 功能:获取移动端授权码licence,PC端无效 |
||||
|
* 输入: |
||||
|
* sAppKey - 授权AppKey,需从云从科技获取 |
||||
|
* sAppSecret - 授权AppSecret,需从云从科技获取 |
||||
|
* sProductId - 授权ProductId,需从云从科技获取 |
||||
|
* iBuffLen - 分配字节长度,不低于300字节 |
||||
|
* 输出: |
||||
|
* pLicence - 输出licence码,需事先分配内存,不低于300字节 |
||||
|
* iUseLen - 输出的licence码的长度 |
||||
|
* 返回值: |
||||
|
* cw_errcode_t - 成功返回CW_SDKLIT_OK,失败返回其他 |
||||
|
*/ |
||||
|
CW_FACE_API |
||||
|
cw_errcode_t cwGetLicence(const char* sAppKey, const char* sAppSecret, const char* sProductId, char* pLicence, int iBuffLen, int *iUseLen); |
||||
|
|
||||
|
|
||||
|
|
||||
|
#if defined (__cplusplus) |
||||
|
} |
||||
|
#endif |
||||
|
|
||||
|
|
||||
|
#endif |
||||
|
|
||||
|
|
||||
|
|
||||
@ -0,0 +1,2 @@ |
|||||
|
featureWeight.bin filter=lfs diff=lfs merge=lfs -text |
||||
|
nirLiveness_model_20181102_pc.bin filter=lfs diff=lfs merge=lfs -text |
||||
@ -0,0 +1,26 @@ |
|||||
|
<VERSION>190312</VERSION> |
||||
|
<ModelType>modelp</ModelType> |
||||
|
<CloudWalk> |
||||
|
<MODELP> |
||||
|
<MODEL> |
||||
|
<NETS> |
||||
|
<NET> |
||||
|
<Model>feature.bin</Model> |
||||
|
<Weights>featureWeight.bin</Weights> |
||||
|
<OutFeature>feature_norm</OutFeature> |
||||
|
</NET> |
||||
|
</NETS> |
||||
|
<PCA> |
||||
|
<Model>pca_proj.bin</Model> |
||||
|
</PCA> |
||||
|
<LDA> |
||||
|
<Mu>-140.29</Mu> |
||||
|
<Sigma>0.01837</Sigma> |
||||
|
<Model>mdl.bin</Model> |
||||
|
</LDA> |
||||
|
<TRANS> |
||||
|
<Flip>false</Flip> |
||||
|
</TRANS> |
||||
|
</MODEL> |
||||
|
</MODELP> |
||||
|
</CloudWalk> |
||||
@ -0,0 +1,26 @@ |
|||||
|
<VERSION>190312</VERSION> |
||||
|
<ModelType>modelp</ModelType> |
||||
|
<CloudWalk> |
||||
|
<MODELP> |
||||
|
<MODEL> |
||||
|
<NETS> |
||||
|
<NET> |
||||
|
<Model>feature.bin</Model> |
||||
|
<Weights>featureWeight.bin</Weights> |
||||
|
<OutFeature>feature_norm</OutFeature> |
||||
|
</NET> |
||||
|
</NETS> |
||||
|
<PCA> |
||||
|
<Model>pca_proj.bin</Model> |
||||
|
</PCA> |
||||
|
<LDA> |
||||
|
<Mu>-146.83</Mu> |
||||
|
<Sigma>0.0122</Sigma> |
||||
|
<Model>mdl.bin</Model> |
||||
|
</LDA> |
||||
|
<TRANS> |
||||
|
<Flip>false</Flip> |
||||
|
</TRANS> |
||||
|
</MODEL> |
||||
|
</MODELP> |
||||
|
</CloudWalk> |
||||
@ -0,0 +1,96 @@ |
|||||
|
<?xml version="1.0"?> |
||||
|
<opencv_storage> |
||||
|
<!-- VIP Frontend Configurations by Cloudwalk. --> |
||||
|
<!-- 如果使用默认参数值,注释相应行即可 --> |
||||
|
<VIP_Frontend> |
||||
|
<!-- 创建句柄所需初始化参数 --> |
||||
|
<Face_INIT_Params> |
||||
|
<!-- 前端worker数,范围1~6. 默认3. (建议根据实际设备性能和应用情景设置最佳值,如E5上10路建议设为2或者3) --> |
||||
|
<Worker_Num>3</Worker_Num> |
||||
|
<!-- 检测器尺度计算worker数,范围1~6,默认3,可根据实际情况启动多workers --> |
||||
|
<Worker_DETS_Num>3</Worker_DETS_Num> |
||||
|
<!-- 检测器滑窗计算worker数,范围1~6,默认1,可根据实际情况启动多workers(效果不如尺度并行,核心数很多时建议进行分配) --> |
||||
|
<Worker_DETW_Num>1</Worker_DETW_Num> |
||||
|
<!-- 加载模型方式(0-文件方式),dl版暂时支持文件模式 --> |
||||
|
<Model_Mode>0</Model_Mode> |
||||
|
<!-- 人脸检测器模型(文件方式时有效, DL版) --> |
||||
|
<str_face_detect_model_dl>faceDetector_3_20.mdl</str_face_detect_model_dl> |
||||
|
<!-- 人脸检测器模型(文件方式时有效, 非DL版) --> |
||||
|
<str_face_detect_model>faceDetector_2_4.mdl</str_face_detect_model> |
||||
|
<!-- dl关键点检测器模型(文件方式时有效) --> |
||||
|
<str_face_keypt_model_dl>landmarks_2_0_2.bin</str_face_keypt_model_dl> |
||||
|
<!-- 质量分检测器模型(文件方式时有效) --> |
||||
|
<str_face_quality_model>face_quality_4_2.bin</str_face_quality_model> |
||||
|
<!-- Face_INIT_Params --> |
||||
|
</Face_INIT_Params> |
||||
|
<!-- 接口功能参数 --> |
||||
|
<Face_DetTrack_Params> |
||||
|
<!-- 每帧最大人脸数 --> |
||||
|
<Faces_Num_Max_Frame>50</Faces_Num_Max_Frame> |
||||
|
<!-- 检出性能,范围1-10,越大检出率越低,但误检越小. 默认2 --> |
||||
|
<Neighbors_Num_Min>2</Neighbors_Num_Min> |
||||
|
<!-- 检测精细度,范围1.1 ~ 1.80,越大速度越快,但越不精细. 默认1.20 --> |
||||
|
<scale_up_ratio>1.2000000476837158e+000</scale_up_ratio> |
||||
|
<!-- 检测精细度,范围0.9 ~ 0.3,越小速度越快,但越不精细. 默认0.709 --> |
||||
|
<scale_up_ratio_dl>7.0899999141693115e-001</scale_up_ratio_dl> |
||||
|
<!-- 检测精细度,范围大于等于1,越大速度越慢,但越精细。默认2(此参数建议不动) --> |
||||
|
<step_win_in_pixel_dl>2</step_win_in_pixel_dl> |
||||
|
<!-- 检测精细度,范围0.1 ~ 0.25,越大速度越快,但越不精细. 默认0.13 --> |
||||
|
<Win_Step_Ratio>1.2999999523162842e-001</Win_Step_Ratio> |
||||
|
<!-- 局部检测子图扩展比例,范围[1.4,3.0],默认1.80 --> |
||||
|
<Local_ImgSize_Expand_Ratio>1.7999999523162842e+000</Local_ImgSize_Expand_Ratio> |
||||
|
<!-- 局部检测人脸扩展比,范围[1.2~1.5],默认1.30 --> |
||||
|
<Local_FaceSize_Range_Ratio>1.2999999523162842e+000</Local_FaceSize_Range_Ratio> |
||||
|
<!-- 跟踪开关下,后续计算(关键点或对齐或质量分)开关打开时的隔帧参数,范围[0,2],0-所有检测人脸都进行后续计算,1-仅全局检测人脸不计算,2-每隔一帧进行后续计算. 默认2 --> |
||||
|
<Post_Detect_Frequency>0</Post_Detect_Frequency> |
||||
|
<!-- 没有检测到的人脸是否进行“串联+跟踪”.0关闭,非0开启,默认1开启 --> |
||||
|
<Lost_Track>1</Lost_Track> |
||||
|
<!-- 预跟踪帧数,默认2 --> |
||||
|
<Frame_Num_For_New>2</Frame_Num_For_New> |
||||
|
<!-- 检测性能水平,相当于检测图缩小比例,范围(1~6).数字越小缩小比例越大,反之亦然.默认1,如果性能不好建议6(不做任何缩放),如果检测超大图可设置1~5. --> |
||||
|
<Perfmon_Level>6</Perfmon_Level> |
||||
|
<!-- 图像预处理方式, 0-不做任何处理, 1-高斯模糊预处理, 其他-不错处理, 默认0不做预处理. --> |
||||
|
<Image_Preprocess_Mode>0</Image_Preprocess_Mode> |
||||
|
<!-- 对齐人脸图颜色空间类型:1-灰度图;2-双通道图;3-彩色图 --> |
||||
|
<ImgAligned_Color_Mode>1</ImgAligned_Color_Mode> |
||||
|
<!-- 静态误检过滤所需人脸框数量,为正则启动过滤,为0或者为负则不启动,默认0不启动。 --> |
||||
|
<Fake_Face_Filter_Aggregate>0.</Fake_Face_Filter_Aggregate> |
||||
|
<!-- 是否过滤比设定的最小人脸还小的人脸,0-不过滤,非0-过滤 --> |
||||
|
<face_filter_over_small>1</face_filter_over_small> |
||||
|
<!-- 等时间间距选最佳人脸策略下的第一阶段如果有人脸过此阈值,直接抛出该阶段的最佳人脸 --> |
||||
|
<best_face_first_threshold>8.0000001192092896e-001</best_face_first_threshold> |
||||
|
<!-- 是否打开检测器属性:1-打开,其他关闭。默认打开。 --> |
||||
|
<open_property_by_detector>0</open_property_by_detector> |
||||
|
<!-- 检测角度过滤阈值,建议0.125。值越大速度越快,越多的人脸(质量较差的)被滤掉,折中考虑. --> |
||||
|
<filt_by_detected_angle_threshold>0</filt_by_detected_angle_threshold> |
||||
|
<!-- 是否启动快速质量分模式(使用关键点得分作为质量总分,其他质量分项将无意义),1开启,其他关闭 --> |
||||
|
<fast_quality_mode>0</fast_quality_mode> |
||||
|
<!-- 算法是否复用用户传进来的图像data. --> |
||||
|
<frame_data_reused>1</frame_data_reused> |
||||
|
<!-- 总分开关 --> |
||||
|
<Quality_TotalScore_Switch>1</Quality_TotalScore_Switch> |
||||
|
<!-- 模糊光照分开关 --> |
||||
|
<Quality_IMG_Switch>1</Quality_IMG_Switch> |
||||
|
<!-- 肤色真假分开关 --> |
||||
|
<Quality_Skinness_Switch>1</Quality_Skinness_Switch> |
||||
|
<!-- 姿态(角度)分开关 --> |
||||
|
<Quality_Pose_Switch>1</Quality_Pose_Switch> |
||||
|
<!-- 眼睛分开关 --> |
||||
|
<Quality_EyeOpenness_Switch>1</Quality_EyeOpenness_Switch> |
||||
|
<!-- 嘴巴分开关 --> |
||||
|
<Quality_MouthOpenness_Switch>1</Quality_MouthOpenness_Switch> |
||||
|
<!-- 黑框眼镜分开关 --> |
||||
|
<Quality_BlackFrameglass_Switch>1</Quality_BlackFrameglass_Switch> |
||||
|
<!-- 墨镜分开关 --> |
||||
|
<Quality_Sunglass_Switch>1</Quality_Sunglass_Switch> |
||||
|
<!-- 眼睛被遮挡分开关 --> |
||||
|
<Quality_EyeOcclusion_Switch>1</Quality_EyeOcclusion_Switch> |
||||
|
<!-- mog清晰度分开关 --> |
||||
|
<Quality_MogClearness_Switch>1</Quality_MogClearness_Switch> |
||||
|
<!-- 所有质量开关综合 --> |
||||
|
<All_Score_Switch>1</All_Score_Switch> |
||||
|
<!-- Face_DetTrack_Params --> |
||||
|
</Face_DetTrack_Params> |
||||
|
<!-- VIP Frontend Configurations by Cloudwalk. --> |
||||
|
</VIP_Frontend> |
||||
|
</opencv_storage> |
||||
@ -0,0 +1,96 @@ |
|||||
|
<?xml version="1.0"?> |
||||
|
<opencv_storage> |
||||
|
<!-- VIP Frontend Configurations by Cloudwalk. --> |
||||
|
<!-- 如果使用默认参数值,注释相应行即可 --> |
||||
|
<VIP_Frontend> |
||||
|
<!-- 创建句柄所需初始化参数 --> |
||||
|
<Face_INIT_Params> |
||||
|
<!-- 前端worker数,范围1~6. 默认3. (建议根据实际设备性能和应用情景设置最佳值,如E5上10路建议设为2或者3) --> |
||||
|
<Worker_Num>3</Worker_Num> |
||||
|
<!-- 检测器尺度计算worker数,范围1~6,默认3,可根据实际情况启动多workers --> |
||||
|
<Worker_DETS_Num>3</Worker_DETS_Num> |
||||
|
<!-- 检测器滑窗计算worker数,范围1~6,默认1,可根据实际情况启动多workers(效果不如尺度并行,核心数很多时建议进行分配) --> |
||||
|
<Worker_DETW_Num>2</Worker_DETW_Num> |
||||
|
<!-- 加载模型方式(0-文件方式),dl版暂时支持文件模式 --> |
||||
|
<Model_Mode>0</Model_Mode> |
||||
|
<!-- 人脸检测器模型(文件方式时有效, DL版) --> |
||||
|
<str_face_detect_model_dl>faceDetector_3_20deepnet1_4_3.mdl</str_face_detect_model_dl> |
||||
|
<!-- 人脸检测器模型(文件方式时有效, 非DL版) --> |
||||
|
<str_face_detect_model>faceDetector_2_4.mdl</str_face_detect_model> |
||||
|
<!-- dl关键点检测器模型(文件方式时有效) --> |
||||
|
<str_face_keypt_model_dl>landmarks_2_0_2.bin</str_face_keypt_model_dl> |
||||
|
<!-- 质量分检测器模型(文件方式时有效) --> |
||||
|
<str_face_quality_model>face_quality_4_2.bin</str_face_quality_model> |
||||
|
<!-- Face_INIT_Params --> |
||||
|
</Face_INIT_Params> |
||||
|
<!-- 接口功能参数 --> |
||||
|
<Face_DetTrack_Params> |
||||
|
<!-- 每帧最大人脸数 --> |
||||
|
<Faces_Num_Max_Frame>50</Faces_Num_Max_Frame> |
||||
|
<!-- 检出性能,范围1-10,越大检出率越低,但误检越小. 默认2 --> |
||||
|
<Neighbors_Num_Min>2</Neighbors_Num_Min> |
||||
|
<!-- 检测精细度,范围1.1 ~ 1.80,越大速度越快,但越不精细. 默认1.20 --> |
||||
|
<scale_up_ratio>1.2000000476837158e+000</scale_up_ratio> |
||||
|
<!-- 检测精细度,范围0.9 ~ 0.3,越小速度越快,但越不精细. 默认0.709 --> |
||||
|
<scale_up_ratio_dl>7.0899999141693115e-001</scale_up_ratio_dl> |
||||
|
<!-- 检测精细度,范围大于等于1,越大速度越慢,但越精细。默认2(此参数建议不动) --> |
||||
|
<step_win_in_pixel_dl>2</step_win_in_pixel_dl> |
||||
|
<!-- 检测精细度,范围0.1 ~ 0.25,越大速度越快,但越不精细. 默认0.13 --> |
||||
|
<Win_Step_Ratio>1.2999999523162842e-001</Win_Step_Ratio> |
||||
|
<!-- 局部检测子图扩展比例,范围[1.4,3.0],默认1.80 --> |
||||
|
<Local_ImgSize_Expand_Ratio>1.7999999523162842e+000</Local_ImgSize_Expand_Ratio> |
||||
|
<!-- 局部检测人脸扩展比,范围[1.2~1.5],默认1.30 --> |
||||
|
<Local_FaceSize_Range_Ratio>1.2999999523162842e+000</Local_FaceSize_Range_Ratio> |
||||
|
<!-- 跟踪开关下,后续计算(关键点或对齐或质量分)开关打开时的隔帧参数,范围[0,2],0-所有检测人脸都进行后续计算,1-仅全局检测人脸不计算,2-每隔一帧进行后续计算. 默认2 --> |
||||
|
<Post_Detect_Frequency>0</Post_Detect_Frequency> |
||||
|
<!-- 没有检测到的人脸是否进行“串联+跟踪”.0关闭,非0开启,默认1开启 --> |
||||
|
<Lost_Track>1</Lost_Track> |
||||
|
<!-- 预跟踪帧数,默认2 --> |
||||
|
<Frame_Num_For_New>2</Frame_Num_For_New> |
||||
|
<!-- 检测性能水平,相当于检测图缩小比例,范围(1~6).数字越小缩小比例越大,反之亦然.默认1,如果性能不好建议6(不做任何缩放),如果检测超大图可设置1~5. --> |
||||
|
<Perfmon_Level>6</Perfmon_Level> |
||||
|
<!-- 图像预处理方式, 0-不做任何处理, 1-高斯模糊预处理, 其他-不错处理, 默认0不做预处理. --> |
||||
|
<Image_Preprocess_Mode>0</Image_Preprocess_Mode> |
||||
|
<!-- 对齐人脸图颜色空间类型:1-灰度图;2-双通道图;3-彩色图 --> |
||||
|
<ImgAligned_Color_Mode>1</ImgAligned_Color_Mode> |
||||
|
<!-- 静态误检过滤所需人脸框数量,为正则启动过滤,为0或者为负则不启动,默认0不启动。 --> |
||||
|
<Fake_Face_Filter_Aggregate>0.</Fake_Face_Filter_Aggregate> |
||||
|
<!-- 是否过滤比设定的最小人脸还小的人脸,0-不过滤,非0-过滤 --> |
||||
|
<face_filter_over_small>1</face_filter_over_small> |
||||
|
<!-- 等时间间距选最佳人脸策略下的第一阶段如果有人脸过此阈值,直接抛出该阶段的最佳人脸 --> |
||||
|
<best_face_first_threshold>8.0000001192092896e-001</best_face_first_threshold> |
||||
|
<!-- 是否打开检测器属性:1-打开,其他关闭。默认打开。 --> |
||||
|
<open_property_by_detector>0</open_property_by_detector> |
||||
|
<!-- 检测角度过滤阈值,建议0.125。值越大速度越快,越多的人脸(质量较差的)被滤掉,折中考虑. --> |
||||
|
<filt_by_detected_angle_threshold>0</filt_by_detected_angle_threshold> |
||||
|
<!-- 是否启动快速质量分模式(使用关键点得分作为质量总分,其他质量分项将无意义),1开启,其他关闭 --> |
||||
|
<fast_quality_mode>0</fast_quality_mode> |
||||
|
<!-- 算法是否复用用户传进来的图像data. --> |
||||
|
<frame_data_reused>1</frame_data_reused> |
||||
|
<!-- 总分开关 --> |
||||
|
<Quality_TotalScore_Switch>1</Quality_TotalScore_Switch> |
||||
|
<!-- 模糊光照分开关 --> |
||||
|
<Quality_IMG_Switch>1</Quality_IMG_Switch> |
||||
|
<!-- 肤色真假分开关 --> |
||||
|
<Quality_Skinness_Switch>1</Quality_Skinness_Switch> |
||||
|
<!-- 姿态(角度)分开关 --> |
||||
|
<Quality_Pose_Switch>1</Quality_Pose_Switch> |
||||
|
<!-- 眼睛分开关 --> |
||||
|
<Quality_EyeOpenness_Switch>1</Quality_EyeOpenness_Switch> |
||||
|
<!-- 嘴巴分开关 --> |
||||
|
<Quality_MouthOpenness_Switch>1</Quality_MouthOpenness_Switch> |
||||
|
<!-- 黑框眼镜分开关 --> |
||||
|
<Quality_BlackFrameglass_Switch>1</Quality_BlackFrameglass_Switch> |
||||
|
<!-- 墨镜分开关 --> |
||||
|
<Quality_Sunglass_Switch>1</Quality_Sunglass_Switch> |
||||
|
<!-- 眼睛被遮挡分开关 --> |
||||
|
<Quality_EyeOcclusion_Switch>1</Quality_EyeOcclusion_Switch> |
||||
|
<!-- mog清晰度分开关 --> |
||||
|
<Quality_MogClearness_Switch>1</Quality_MogClearness_Switch> |
||||
|
<!-- 所有质量开关综合 --> |
||||
|
<All_Score_Switch>1</All_Score_Switch> |
||||
|
<!-- Face_DetTrack_Params --> |
||||
|
</Face_DetTrack_Params> |
||||
|
<!-- VIP Frontend Configurations by Cloudwalk. --> |
||||
|
</VIP_Frontend> |
||||
|
</opencv_storage> |
||||
@ -0,0 +1,13 @@ |
|||||
|
<VERSION>170313_AGE</VERSION> |
||||
|
<CloudWalk> |
||||
|
<MODEL> |
||||
|
<NETS> |
||||
|
<NET> |
||||
|
<Model>age_gender_tensor.prototxt</Model> |
||||
|
<Weights>age_gender_tensor.caffemodel</Weights> |
||||
|
<OutFeature>output</OutFeature> |
||||
|
</NET> |
||||
|
</NETS> |
||||
|
</MODEL> |
||||
|
</CloudWalk> |
||||
|
|
||||
Binary file not shown.
File diff suppressed because it is too large
@ -0,0 +1,13 @@ |
|||||
|
<VERSION>FaceGender181010</VERSION> |
||||
|
<CloudWalk> |
||||
|
<MODEL> |
||||
|
<NETS> |
||||
|
<NET> |
||||
|
<Model>model.bin</Model> |
||||
|
<Weights>weight.bin</Weights> |
||||
|
<OutFeature>loss</OutFeature> |
||||
|
</NET> |
||||
|
</NETS> |
||||
|
</MODEL> |
||||
|
</CloudWalk> |
||||
|
|
||||
Binary file not shown.
Binary file not shown.
@ -0,0 +1,13 @@ |
|||||
|
<VERSION>FaceRace181011</VERSION> |
||||
|
<CloudWalk> |
||||
|
<MODEL> |
||||
|
<NETS> |
||||
|
<NET> |
||||
|
<Model>model.bin</Model> |
||||
|
<Weights>weight.bin</Weights> |
||||
|
<OutFeature>prob</OutFeature> |
||||
|
</NET> |
||||
|
</NETS> |
||||
|
</MODEL> |
||||
|
</CloudWalk> |
||||
|
|
||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -0,0 +1,3 @@ |
|||||
|
version https://git-lfs.github.com/spec/v1 |
||||
|
oid sha256:a50da40075e0ddf257796492d6d29ce273cd1405f7f968959822cd4ede71ed91 |
||||
|
size 24506057 |
||||
Binary file not shown.
Binary file not shown.
@ -0,0 +1,13 @@ |
|||||
|
<?xml version="1.0"?> |
||||
|
<opencv_storage> |
||||
|
<MATRIX type_id="opencv-matrix"> |
||||
|
<rows>3</rows> |
||||
|
<cols>3</cols> |
||||
|
<dt>d</dt> |
||||
|
<data> |
||||
|
9.7347784042358398e-001 3.1790971755981445e-002 |
||||
|
-9.5726318359375000e+000 3.3823758363723755e-002 |
||||
|
7.8234243392944336e-001 5.7563110351562500e+001 |
||||
|
2.1420419216156006e-008 -4.3772161006927490e-008 |
||||
|
1.0000057220458984e+000</data></MATRIX> |
||||
|
</opencv_storage> |
||||
@ -0,0 +1,13 @@ |
|||||
|
<?xml version="1.0"?> |
||||
|
<opencv_storage> |
||||
|
<MATRIX type_id="opencv-matrix"> |
||||
|
<rows>3</rows> |
||||
|
<cols>3</cols> |
||||
|
<dt>d</dt> |
||||
|
<data> |
||||
|
9.4498615586013912e-001 1.0133313172564584e-001 |
||||
|
2.7968245980155189e+000 9.1128408462592958e-004 |
||||
|
8.6220615318591198e-001 1.7946323882964407e+001 |
||||
|
-2.3245294578089215e-016 3.8857805861880479e-016 |
||||
|
1.0000000000000107e+000</data></MATRIX> |
||||
|
</opencv_storage> |
||||
Binary file not shown.
@ -0,0 +1,3 @@ |
|||||
|
version https://git-lfs.github.com/spec/v1 |
||||
|
oid sha256:19cbcc650ec721a269e8c832c419ab65613b57bfd6884f9fc153e1f5ae9b3ae5 |
||||
|
size 53360172 |
||||
Binary file not shown.
@ -0,0 +1,245 @@ |
|||||
|
<?xml version="1.0" encoding="utf-8"?> |
||||
|
<Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> |
||||
|
<ItemGroup Label="ProjectConfigurations"> |
||||
|
<ProjectConfiguration Include="Debug|Win32"> |
||||
|
<Configuration>Debug</Configuration> |
||||
|
<Platform>Win32</Platform> |
||||
|
</ProjectConfiguration> |
||||
|
<ProjectConfiguration Include="Debug|x64"> |
||||
|
<Configuration>Debug</Configuration> |
||||
|
<Platform>x64</Platform> |
||||
|
</ProjectConfiguration> |
||||
|
<ProjectConfiguration Include="Release_Xp|Win32"> |
||||
|
<Configuration>Release_Xp</Configuration> |
||||
|
<Platform>Win32</Platform> |
||||
|
</ProjectConfiguration> |
||||
|
<ProjectConfiguration Include="Release_Xp|x64"> |
||||
|
<Configuration>Release_Xp</Configuration> |
||||
|
<Platform>x64</Platform> |
||||
|
</ProjectConfiguration> |
||||
|
<ProjectConfiguration Include="Release|Win32"> |
||||
|
<Configuration>Release</Configuration> |
||||
|
<Platform>Win32</Platform> |
||||
|
</ProjectConfiguration> |
||||
|
<ProjectConfiguration Include="Release|x64"> |
||||
|
<Configuration>Release</Configuration> |
||||
|
<Platform>x64</Platform> |
||||
|
</ProjectConfiguration> |
||||
|
</ItemGroup> |
||||
|
<PropertyGroup Label="Globals"> |
||||
|
<ProjectGuid>{C0F38F1A-A697-4F2B-BA4C-37041C2ABBC0}</ProjectGuid> |
||||
|
<Keyword>Win32Proj</Keyword> |
||||
|
<RootNamespace>Demo</RootNamespace> |
||||
|
</PropertyGroup> |
||||
|
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" /> |
||||
|
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration"> |
||||
|
<ConfigurationType>Application</ConfigurationType> |
||||
|
<UseDebugLibraries>true</UseDebugLibraries> |
||||
|
<PlatformToolset>v110</PlatformToolset> |
||||
|
<CharacterSet>Unicode</CharacterSet> |
||||
|
</PropertyGroup> |
||||
|
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration"> |
||||
|
<ConfigurationType>Application</ConfigurationType> |
||||
|
<UseDebugLibraries>true</UseDebugLibraries> |
||||
|
<PlatformToolset>v110</PlatformToolset> |
||||
|
<CharacterSet>Unicode</CharacterSet> |
||||
|
</PropertyGroup> |
||||
|
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration"> |
||||
|
<ConfigurationType>Application</ConfigurationType> |
||||
|
<UseDebugLibraries>false</UseDebugLibraries> |
||||
|
<PlatformToolset>v110</PlatformToolset> |
||||
|
<WholeProgramOptimization>true</WholeProgramOptimization> |
||||
|
<CharacterSet>Unicode</CharacterSet> |
||||
|
</PropertyGroup> |
||||
|
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release_Xp|Win32'" Label="Configuration"> |
||||
|
<ConfigurationType>Application</ConfigurationType> |
||||
|
<UseDebugLibraries>false</UseDebugLibraries> |
||||
|
<PlatformToolset>v110_xp</PlatformToolset> |
||||
|
<WholeProgramOptimization>true</WholeProgramOptimization> |
||||
|
<CharacterSet>Unicode</CharacterSet> |
||||
|
</PropertyGroup> |
||||
|
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration"> |
||||
|
<ConfigurationType>Application</ConfigurationType> |
||||
|
<UseDebugLibraries>false</UseDebugLibraries> |
||||
|
<PlatformToolset>v110</PlatformToolset> |
||||
|
<WholeProgramOptimization>true</WholeProgramOptimization> |
||||
|
<CharacterSet>Unicode</CharacterSet> |
||||
|
</PropertyGroup> |
||||
|
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release_Xp|x64'" Label="Configuration"> |
||||
|
<ConfigurationType>Application</ConfigurationType> |
||||
|
<UseDebugLibraries>false</UseDebugLibraries> |
||||
|
<PlatformToolset>v110</PlatformToolset> |
||||
|
<WholeProgramOptimization>true</WholeProgramOptimization> |
||||
|
<CharacterSet>Unicode</CharacterSet> |
||||
|
</PropertyGroup> |
||||
|
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" /> |
||||
|
<ImportGroup Label="ExtensionSettings"> |
||||
|
</ImportGroup> |
||||
|
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'"> |
||||
|
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" /> |
||||
|
</ImportGroup> |
||||
|
<ImportGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="PropertySheets"> |
||||
|
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" /> |
||||
|
</ImportGroup> |
||||
|
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|Win32'"> |
||||
|
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" /> |
||||
|
</ImportGroup> |
||||
|
<ImportGroup Condition="'$(Configuration)|$(Platform)'=='Release_Xp|Win32'" Label="PropertySheets"> |
||||
|
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" /> |
||||
|
</ImportGroup> |
||||
|
<ImportGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="PropertySheets"> |
||||
|
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" /> |
||||
|
</ImportGroup> |
||||
|
<ImportGroup Condition="'$(Configuration)|$(Platform)'=='Release_Xp|x64'" Label="PropertySheets"> |
||||
|
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" /> |
||||
|
</ImportGroup> |
||||
|
<PropertyGroup Label="UserMacros" /> |
||||
|
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'"> |
||||
|
<LinkIncremental>true</LinkIncremental> |
||||
|
<OutDir>$(SolutionDir)$(Platform)\$(Configuration)\</OutDir> |
||||
|
</PropertyGroup> |
||||
|
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'"> |
||||
|
<LinkIncremental>true</LinkIncremental> |
||||
|
<OutDir>$(SolutionDir)$(Platform)\$(Configuration)\</OutDir> |
||||
|
</PropertyGroup> |
||||
|
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'"> |
||||
|
<LinkIncremental>false</LinkIncremental> |
||||
|
<OutDir>..\build_32\bin\</OutDir> |
||||
|
</PropertyGroup> |
||||
|
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release_Xp|Win32'"> |
||||
|
<LinkIncremental>false</LinkIncremental> |
||||
|
<OutDir>..\build_xp\bin\</OutDir> |
||||
|
</PropertyGroup> |
||||
|
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'"> |
||||
|
<LinkIncremental>false</LinkIncremental> |
||||
|
<OutDir>..\build_64\bin\</OutDir> |
||||
|
</PropertyGroup> |
||||
|
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release_Xp|x64'"> |
||||
|
<LinkIncremental>false</LinkIncremental> |
||||
|
<OutDir>..\build_64\bin\</OutDir> |
||||
|
</PropertyGroup> |
||||
|
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'"> |
||||
|
<ClCompile> |
||||
|
<PrecompiledHeader> |
||||
|
</PrecompiledHeader> |
||||
|
<WarningLevel>Level3</WarningLevel> |
||||
|
<Optimization>Disabled</Optimization> |
||||
|
<PreprocessorDefinitions>WIN32;_DEBUG;_CONSOLE;_CRT_SECURE_NO_WARNINGS;%(PreprocessorDefinitions)</PreprocessorDefinitions> |
||||
|
<SDLCheck>true</SDLCheck> |
||||
|
<AdditionalIncludeDirectories>../CWFaceSDK;opencv2411/include;opencv2411/include/opencv;opencv2411/include/opencv2;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories> |
||||
|
</ClCompile> |
||||
|
<Link> |
||||
|
<SubSystem>Console</SubSystem> |
||||
|
<GenerateDebugInformation>true</GenerateDebugInformation> |
||||
|
<AdditionalLibraryDirectories>..\build_32\lib.debug;lib32</AdditionalLibraryDirectories> |
||||
|
<AdditionalDependencies>CWFaceSDKd.lib;opencv_core2411d.lib;opencv_highgui2411d.lib;opencv_imgproc2411d.lib;%(AdditionalDependencies)</AdditionalDependencies> |
||||
|
</Link> |
||||
|
</ItemDefinitionGroup> |
||||
|
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'"> |
||||
|
<ClCompile> |
||||
|
<PrecompiledHeader> |
||||
|
</PrecompiledHeader> |
||||
|
<WarningLevel>Level3</WarningLevel> |
||||
|
<Optimization>Disabled</Optimization> |
||||
|
<PreprocessorDefinitions>WIN32;_DEBUG;_CONSOLE;_CRT_SECURE_NO_WARNINGS;%(PreprocessorDefinitions)</PreprocessorDefinitions> |
||||
|
<SDLCheck>true</SDLCheck> |
||||
|
<AdditionalIncludeDirectories>../CWFaceSDK;opencv2411/include;opencv2411/include/opencv;opencv2411/include/opencv2;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories> |
||||
|
</ClCompile> |
||||
|
<Link> |
||||
|
<SubSystem>Console</SubSystem> |
||||
|
<GenerateDebugInformation>true</GenerateDebugInformation> |
||||
|
<AdditionalLibraryDirectories>..\build_64\lib.debug;lib64;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories> |
||||
|
<AdditionalDependencies>CWFaceSDKd.lib;opencv_core2411d.lib;opencv_highgui2411d.lib;opencv_imgproc2411d.lib;%(AdditionalDependencies)</AdditionalDependencies> |
||||
|
</Link> |
||||
|
</ItemDefinitionGroup> |
||||
|
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'"> |
||||
|
<ClCompile> |
||||
|
<WarningLevel>Level3</WarningLevel> |
||||
|
<PrecompiledHeader> |
||||
|
</PrecompiledHeader> |
||||
|
<Optimization>Disabled</Optimization> |
||||
|
<FunctionLevelLinking>true</FunctionLevelLinking> |
||||
|
<IntrinsicFunctions>true</IntrinsicFunctions> |
||||
|
<PreprocessorDefinitions>WIN32;NDEBUG;_CONSOLE;_CRT_SECURE_NO_WARNINGS;CWFACESDK_EXPORTS;%(PreprocessorDefinitions)</PreprocessorDefinitions> |
||||
|
<SDLCheck>true</SDLCheck> |
||||
|
<AdditionalIncludeDirectories>../CWFaceSDK;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories> |
||||
|
</ClCompile> |
||||
|
<Link> |
||||
|
<SubSystem>Console</SubSystem> |
||||
|
<GenerateDebugInformation>true</GenerateDebugInformation> |
||||
|
<EnableCOMDATFolding>true</EnableCOMDATFolding> |
||||
|
<OptimizeReferences>true</OptimizeReferences> |
||||
|
<AdditionalLibraryDirectories>..\build_32\lib</AdditionalLibraryDirectories> |
||||
|
<AdditionalDependencies>CWFaceSDK.lib;%(AdditionalDependencies)</AdditionalDependencies> |
||||
|
</Link> |
||||
|
</ItemDefinitionGroup> |
||||
|
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release_Xp|Win32'"> |
||||
|
<ClCompile> |
||||
|
<WarningLevel>Level3</WarningLevel> |
||||
|
<PrecompiledHeader> |
||||
|
</PrecompiledHeader> |
||||
|
<Optimization>Disabled</Optimization> |
||||
|
<FunctionLevelLinking>true</FunctionLevelLinking> |
||||
|
<IntrinsicFunctions>true</IntrinsicFunctions> |
||||
|
<PreprocessorDefinitions>WIN32;NDEBUG;_CONSOLE;_CRT_SECURE_NO_WARNINGS;%(PreprocessorDefinitions)</PreprocessorDefinitions> |
||||
|
<SDLCheck>true</SDLCheck> |
||||
|
<AdditionalIncludeDirectories>../CWFaceSDK;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories> |
||||
|
</ClCompile> |
||||
|
<Link> |
||||
|
<SubSystem>Console</SubSystem> |
||||
|
<GenerateDebugInformation>true</GenerateDebugInformation> |
||||
|
<EnableCOMDATFolding>true</EnableCOMDATFolding> |
||||
|
<OptimizeReferences>true</OptimizeReferences> |
||||
|
<AdditionalLibraryDirectories>..\build_xp\lib</AdditionalLibraryDirectories> |
||||
|
<AdditionalDependencies>CWFaceSDK.lib;%(AdditionalDependencies)</AdditionalDependencies> |
||||
|
</Link> |
||||
|
</ItemDefinitionGroup> |
||||
|
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'"> |
||||
|
<ClCompile> |
||||
|
<WarningLevel>Level3</WarningLevel> |
||||
|
<PrecompiledHeader> |
||||
|
</PrecompiledHeader> |
||||
|
<Optimization>Disabled</Optimization> |
||||
|
<FunctionLevelLinking>true</FunctionLevelLinking> |
||||
|
<IntrinsicFunctions>true</IntrinsicFunctions> |
||||
|
<PreprocessorDefinitions>WIN32;DEMO_X64;NDEBUG;_CONSOLE;_CRT_SECURE_NO_WARNINGS;%(PreprocessorDefinitions)</PreprocessorDefinitions> |
||||
|
<SDLCheck>true</SDLCheck> |
||||
|
<AdditionalIncludeDirectories>../CWFaceSDK;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories> |
||||
|
</ClCompile> |
||||
|
<Link> |
||||
|
<SubSystem>Console</SubSystem> |
||||
|
<GenerateDebugInformation>true</GenerateDebugInformation> |
||||
|
<EnableCOMDATFolding>true</EnableCOMDATFolding> |
||||
|
<OptimizeReferences>true</OptimizeReferences> |
||||
|
<AdditionalLibraryDirectories>..\build_64\lib</AdditionalLibraryDirectories> |
||||
|
<AdditionalDependencies>CWFaceSDK.lib;%(AdditionalDependencies)</AdditionalDependencies> |
||||
|
</Link> |
||||
|
</ItemDefinitionGroup> |
||||
|
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release_Xp|x64'"> |
||||
|
<ClCompile> |
||||
|
<WarningLevel>Level3</WarningLevel> |
||||
|
<PrecompiledHeader> |
||||
|
</PrecompiledHeader> |
||||
|
<Optimization>Disabled</Optimization> |
||||
|
<FunctionLevelLinking>true</FunctionLevelLinking> |
||||
|
<IntrinsicFunctions>true</IntrinsicFunctions> |
||||
|
<PreprocessorDefinitions>WIN32;NDEBUG;_CONSOLE;_CRT_SECURE_NO_WARNINGS;%(PreprocessorDefinitions)</PreprocessorDefinitions> |
||||
|
<SDLCheck>true</SDLCheck> |
||||
|
<AdditionalIncludeDirectories>../CWFaceSDK;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories> |
||||
|
</ClCompile> |
||||
|
<Link> |
||||
|
<SubSystem>Console</SubSystem> |
||||
|
<GenerateDebugInformation>true</GenerateDebugInformation> |
||||
|
<EnableCOMDATFolding>true</EnableCOMDATFolding> |
||||
|
<OptimizeReferences>true</OptimizeReferences> |
||||
|
<AdditionalLibraryDirectories>..\build_64\lib</AdditionalLibraryDirectories> |
||||
|
<AdditionalDependencies>CWFaceSDK.lib;%(AdditionalDependencies)</AdditionalDependencies> |
||||
|
</Link> |
||||
|
</ItemDefinitionGroup> |
||||
|
<ItemGroup> |
||||
|
<ClCompile Include="demo.cpp" /> |
||||
|
</ItemGroup> |
||||
|
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" /> |
||||
|
<ImportGroup Label="ExtensionTargets"> |
||||
|
</ImportGroup> |
||||
|
</Project> |
||||
@ -0,0 +1,22 @@ |
|||||
|
<?xml version="1.0" encoding="utf-8"?> |
||||
|
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> |
||||
|
<ItemGroup> |
||||
|
<Filter Include="源文件"> |
||||
|
<UniqueIdentifier>{4FC737F1-C7A5-4376-A066-2A32D752A2FF}</UniqueIdentifier> |
||||
|
<Extensions>cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx</Extensions> |
||||
|
</Filter> |
||||
|
<Filter Include="头文件"> |
||||
|
<UniqueIdentifier>{93995380-89BD-4b04-88EB-625FBE52EBFB}</UniqueIdentifier> |
||||
|
<Extensions>h;hpp;hxx;hm;inl;inc;xsd</Extensions> |
||||
|
</Filter> |
||||
|
<Filter Include="资源文件"> |
||||
|
<UniqueIdentifier>{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}</UniqueIdentifier> |
||||
|
<Extensions>rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms</Extensions> |
||||
|
</Filter> |
||||
|
</ItemGroup> |
||||
|
<ItemGroup> |
||||
|
<ClCompile Include="demo.cpp"> |
||||
|
<Filter>源文件</Filter> |
||||
|
</ClCompile> |
||||
|
</ItemGroup> |
||||
|
</Project> |
||||
@ -0,0 +1,996 @@ |
|||||
|
#include <vector> |
||||
|
#include <time.h> |
||||
|
#include <fstream> |
||||
|
#include "iostream" |
||||
|
#include "string.h" |
||||
|
#include "CWFaceDetection.h" |
||||
|
#include "CWFaceRecognition.h" |
||||
|
#include "CWFaceVersion.h" |
||||
|
#include "CWFaceAttribute.h" |
||||
|
#include "CWFaceNisLiveness.h" |
||||
|
|
||||
|
|
||||
|
#ifdef WIN32 |
||||
|
#include "io.h" |
||||
|
#else |
||||
|
#include <unistd.h> |
||||
|
#endif // WIN32
|
||||
|
|
||||
|
|
||||
|
// 授权licence
|
||||
|
#define CW_LICENCE "MjEyNDE0bm9kZXZpY2Vjd2F1dGhvcml6ZZ/l5uXj5+Xq3+bg5efm5Of+5eXj4Obg5Yjm5uvl5ubrkeXm5uvl5uai6+Xm5uvl5uTm6+Xm5uDm1efr5+vn6+er4Ofr5+vn66vn5+Xm5+Xn" |
||||
|
|
||||
|
#define MAX_NUM_FACES 20 //最多检测的人脸数
|
||||
|
|
||||
|
using namespace std; |
||||
|
|
||||
|
|
||||
|
// [8/7/2015 Lit] 功能:将一个全路径名分解为路径和文件名
|
||||
|
bool DivPathAndFileName(const string &sAllName, string &sPath, string &sFileName) |
||||
|
{ |
||||
|
int iPos = sAllName.find_last_of('\\'); |
||||
|
if (-1 == iPos) |
||||
|
{ |
||||
|
iPos = sAllName.find_last_of('/'); |
||||
|
if (-1 == iPos) |
||||
|
{ |
||||
|
sPath = "."; |
||||
|
sFileName = sAllName; |
||||
|
return true; |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
sPath = sAllName.substr(0, iPos); |
||||
|
sFileName = sAllName.substr(iPos + 1, sAllName.length() - iPos - 1); |
||||
|
return true; |
||||
|
} |
||||
|
|
||||
|
// [8/7/2015 Lit] 功能:提示用户输入图片路径,并获得文件夹路径
|
||||
|
bool GetImageAndPath(string &sPathPic, string &sPathFolder) |
||||
|
{ |
||||
|
char picPath[260] = {0}; |
||||
|
while (true) |
||||
|
{ |
||||
|
cout<<"Please Input Pic Path: "; |
||||
|
cin>>picPath; |
||||
|
|
||||
|
#ifdef WIN32 |
||||
|
if (-1 == _access(picPath, 0)) |
||||
|
{ |
||||
|
cout<<"Pic Not Found"<<endl; |
||||
|
continue; |
||||
|
} |
||||
|
#else |
||||
|
if (-1 == access(picPath, 0)) |
||||
|
{ |
||||
|
cout<<"Pic Not Found"<<endl; |
||||
|
continue; |
||||
|
} |
||||
|
#endif |
||||
|
|
||||
|
break; |
||||
|
} |
||||
|
|
||||
|
sPathPic = picPath; |
||||
|
string sFileName; |
||||
|
return DivPathAndFileName(sPathPic, sPathFolder, sFileName); |
||||
|
} |
||||
|
|
||||
|
int GetFeatureFromPath(void* pDetHandle, void* pRecogHandle, const string &sImagePath, void* pFeatueData) |
||||
|
{ |
||||
|
// 给图像结构体赋值
|
||||
|
std::ifstream ifs(sImagePath.c_str(), std::ios::binary); |
||||
|
ifs.seekg(0, std::ios::end); |
||||
|
int iImgLen = ifs.tellg(); |
||||
|
ifs.seekg(0, std::ios::beg); |
||||
|
char *szImg = new char[iImgLen]; |
||||
|
ifs.read(szImg, iImgLen); |
||||
|
|
||||
|
cw_img_t srcImg; |
||||
|
srcImg.frameId = 0; |
||||
|
srcImg.data = szImg; |
||||
|
srcImg.dataLen = iImgLen; |
||||
|
srcImg.angle = CW_IMAGE_ANGLE_0; |
||||
|
srcImg.format = CW_IMAGE_BINARY; |
||||
|
srcImg.mirror = CW_IMAGE_MIRROR_NONE; |
||||
|
|
||||
|
cw_face_res_t faceBuffers[MAX_NUM_FACES]; |
||||
|
int iFaceNum = 0; |
||||
|
// 人脸检测,获取对齐人脸
|
||||
|
cw_errcode_t errCode = cwFaceDetection(pDetHandle, &srcImg, faceBuffers, MAX_NUM_FACES, &iFaceNum, CW_OP_DET | CW_OP_ALIGN); |
||||
|
delete[] szImg; |
||||
|
|
||||
|
if (errCode != CW_SDKLIT_OK) |
||||
|
{ |
||||
|
cout<<"Face detect Error, Code: " << errCode << endl; |
||||
|
return -1; |
||||
|
} |
||||
|
if (iFaceNum < 1) |
||||
|
{ |
||||
|
cout<<"No Face Detected" << endl; |
||||
|
return -1; |
||||
|
} |
||||
|
if (faceBuffers[0].detected != 1) |
||||
|
{ |
||||
|
cout<<"Low Face Quality" << endl; |
||||
|
return -1; |
||||
|
} |
||||
|
|
||||
|
// 提取检测到的第一张人脸的特征
|
||||
|
errCode = cwGetFaceFeature(pRecogHandle, &faceBuffers[0].faceAligned, pFeatueData); |
||||
|
if (CW_SDKLIT_OK != errCode) |
||||
|
{ |
||||
|
cout<<"Get Feature Error: " << errCode << endl; |
||||
|
return -1; |
||||
|
} |
||||
|
|
||||
|
return 0; |
||||
|
} |
||||
|
|
||||
|
|
||||
|
int GetFaceInfoByImgData(void *pDetHandle, char *pImgData, int iImgLen, cw_face_res_t* pFaceBuffer) |
||||
|
{ |
||||
|
if (pImgData == NULL || iImgLen < 1) |
||||
|
{ |
||||
|
return 0; |
||||
|
} |
||||
|
|
||||
|
cw_img_t srcImg; |
||||
|
srcImg.frameId = 0; |
||||
|
srcImg.data = pImgData; |
||||
|
srcImg.dataLen = iImgLen; |
||||
|
srcImg.angle = CW_IMAGE_ANGLE_0; |
||||
|
srcImg.mirror = CW_IMAGE_MIRROR_NONE; |
||||
|
srcImg.format = CW_IMAGE_BINARY; |
||||
|
|
||||
|
int iFaceNum = 0; |
||||
|
// 检测,关键点与质量分
|
||||
|
cw_errcode_t errCode = cwFaceDetection(pDetHandle, &srcImg, pFaceBuffer, MAX_NUM_FACES, &iFaceNum, CW_OP_DET |CW_OP_KEYPT| CW_OP_QUALITY); |
||||
|
if (errCode != CW_SDKLIT_OK) |
||||
|
{ |
||||
|
cout<<"Face detect Error, Code: " << errCode << endl; |
||||
|
return 0; |
||||
|
} |
||||
|
if (iFaceNum < 1) |
||||
|
{ |
||||
|
cout<<"No Face Detected" << endl; |
||||
|
return 0; |
||||
|
} |
||||
|
|
||||
|
return iFaceNum; |
||||
|
} |
||||
|
|
||||
|
|
||||
|
void* CreateDetHandle(cw_errcode_t* errCode) |
||||
|
{ |
||||
|
// 32位和64位检测模型不能共用,64位用_configs_frontend.xml,非64位用_configs_frontend_x86_arm.xml
|
||||
|
#ifdef DEMO_X64 |
||||
|
std::string sModelXmlPath = "../../CWModels/_configs_frontend.xml"; |
||||
|
#else |
||||
|
std::string sModelXmlPath = "../../CWModels/_configs_frontend_x86_arm.xml"; |
||||
|
#endif // DEMO_X64
|
||||
|
|
||||
|
void *pDet = cwCreateDetHandle(errCode, sModelXmlPath.c_str(), CW_LICENCE); |
||||
|
if (pDet) |
||||
|
{ |
||||
|
cw_det_param_t param; |
||||
|
cwGetFaceParam(pDet, ¶m); |
||||
|
param.minSize = 48; |
||||
|
param.maxSize = 600; |
||||
|
param.pConfigFile = sModelXmlPath.c_str(); // 设置接口功能参数
|
||||
|
cwSetFaceParam(pDet, ¶m); |
||||
|
} |
||||
|
|
||||
|
return pDet; |
||||
|
} |
||||
|
|
||||
|
void* CreateRecogHandle(cw_errcode_t* errCode) |
||||
|
{ |
||||
|
#ifdef ANDROID |
||||
|
std::string sModelPath = "../../CWModels/CWR_Config_1_1.xml"; |
||||
|
#else |
||||
|
std::string sModelPath = "../../CWModels/CWR_Config_1_1.xml"; |
||||
|
#endif |
||||
|
|
||||
|
return cwCreateRecogHandle(errCode, sModelPath.c_str(), CW_LICENCE, CW_FEATURE_EXTRACT); |
||||
|
} |
||||
|
|
||||
|
void* CreateAttributeHandle(cw_errcode_t* errcode, const char *sModelPath) |
||||
|
{ |
||||
|
//加载的模型
|
||||
|
return cwCreateAttributeHandle (errcode,sModelPath,CW_LICENCE); |
||||
|
} |
||||
|
|
||||
|
// 创建红外活体句柄 ../../CWModels/hd171019.bin
|
||||
|
void* CreateNisLivenessHandle(cw_nirliveness_err_t* errCode) |
||||
|
{ |
||||
|
return cwCreateNirLivenessHandle(errCode, "../../CWModels/nirLiveness_model_20181102_pc.bin","../../CWModels/hd171019.bin","../../CWModels/matrix_para640x480.xml", |
||||
|
"./log", 0.35, CW_LICENCE); |
||||
|
} |
||||
|
|
||||
|
|
||||
|
// 安装授权,如果授权成功,不要再次调用
|
||||
|
void InstallKey(const char* sAppKey, const char* sAppSecret, const char* sProductId) |
||||
|
{ |
||||
|
cw_errcode_t errCode = cwInstallLicence(sAppKey, sAppSecret, sProductId); |
||||
|
cout << "cwInstallLicence: " << errCode << endl; |
||||
|
} |
||||
|
|
||||
|
// 安卓获取授权码
|
||||
|
void GetLicense(const char* sAppKey, const char* sAppSecret, const char* sProductId) |
||||
|
{ |
||||
|
char szLicense[600] = {0}; |
||||
|
int iUseLen = 0; |
||||
|
cw_errcode_t errCode = cwGetLicence(sAppKey, sAppSecret, sProductId, szLicense, 600, &iUseLen); |
||||
|
|
||||
|
cout << "cwGetLicence: " << errCode << endl; |
||||
|
cout << "license: " << szLicense << endl; |
||||
|
} |
||||
|
|
||||
|
int RetPause(int iRet, void *pDetHandle = NULL, void *pRecogHandle = NULL, void *pAgeHandle = NULL,void *pGenderHandle = NULL,void *pRaceHandle = NULL, void *pNisLiveHandle = NULL) |
||||
|
{ |
||||
|
// 程序退出时销毁句柄
|
||||
|
if (pDetHandle != NULL) |
||||
|
{ |
||||
|
cwReleaseDetHandle(pDetHandle); |
||||
|
pDetHandle = NULL; |
||||
|
} |
||||
|
if (pRecogHandle != NULL) |
||||
|
{ |
||||
|
cwReleaseRecogHandle(pRecogHandle); |
||||
|
pRecogHandle = NULL; |
||||
|
} |
||||
|
|
||||
|
if (pAgeHandle!=NULL) |
||||
|
{ |
||||
|
cwReleaseAttributeHandle (pAgeHandle); |
||||
|
pAgeHandle=NULL; |
||||
|
} |
||||
|
|
||||
|
if (pGenderHandle!=NULL) |
||||
|
{ |
||||
|
cwReleaseAttributeHandle (pGenderHandle); |
||||
|
pGenderHandle=NULL; |
||||
|
} |
||||
|
|
||||
|
if (pRaceHandle!=NULL) |
||||
|
{ |
||||
|
cwReleaseAttributeHandle (pRaceHandle); |
||||
|
pRaceHandle=NULL; |
||||
|
} |
||||
|
|
||||
|
if (pNisLiveHandle != NULL) |
||||
|
{ |
||||
|
cwReleaseNirLivenessHandle(pNisLiveHandle); |
||||
|
pNisLiveHandle = NULL; |
||||
|
} |
||||
|
|
||||
|
#ifdef WIN32 |
||||
|
system("pause"); |
||||
|
#endif // WIN32
|
||||
|
|
||||
|
return iRet; |
||||
|
} |
||||
|
|
||||
|
int DemoDetect(); // [6/29/2016 Lit]:人脸检测使用示例
|
||||
|
|
||||
|
int DemoQuality(); // [9/13/2016 Lit]:人脸质量使用示例
|
||||
|
|
||||
|
int DemoVerify(); // [6/29/2016 Lit]:人脸比对使用示例(1:1)
|
||||
|
|
||||
|
int DemoVerify2(); // [8/29/2018 Lit]:人脸比对使用示例,直接调用比对接口
|
||||
|
|
||||
|
int DemoRecog(); // [6/29/2016 Lit]:人脸识别使用示例(1:N)
|
||||
|
|
||||
|
int DemoAttribute(); // [16/10/2018 Lit]: 人脸属性使用示例
|
||||
|
|
||||
|
int DemoNisLiveness(); // [6/11/2018 Lit]: 红外活体使用示例
|
||||
|
|
||||
|
|
||||
|
int main() |
||||
|
{ |
||||
|
char szVer[100] = {0}; |
||||
|
cwGetSDKVersion(szVer, 100); |
||||
|
cout << "SDK Version: " << szVer; |
||||
|
cout << endl << endl; |
||||
|
|
||||
|
int iType = 0; |
||||
|
cout << "demo type:" << endl; |
||||
|
cout << "1 Face Detect" << endl; |
||||
|
cout << "2 Face Quality" << endl; |
||||
|
cout << "3 Face Verify" << endl; |
||||
|
cout << "4 Face Verify2" << endl; |
||||
|
cout << "5 Face Recognition" << endl; |
||||
|
cout << "6 Face Attribute" <<endl; |
||||
|
cout << "7 Face NisLiveness" << endl; |
||||
|
cout << "8 Exit" << endl << endl; |
||||
|
|
||||
|
cout << "Please Input Type:"; |
||||
|
cin >> iType; |
||||
|
|
||||
|
switch (iType) |
||||
|
{ |
||||
|
case 1: |
||||
|
return DemoDetect(); |
||||
|
case 2: |
||||
|
return DemoQuality(); |
||||
|
case 3: |
||||
|
return DemoVerify(); |
||||
|
case 4: |
||||
|
return DemoVerify2(); |
||||
|
case 5: |
||||
|
return DemoRecog(); |
||||
|
case 6: |
||||
|
return DemoAttribute(); |
||||
|
case 7: |
||||
|
return DemoNisLiveness(); |
||||
|
case 8: |
||||
|
return 0; |
||||
|
|
||||
|
default: |
||||
|
cout << "type error" << endl << endl; |
||||
|
cin.clear(); |
||||
|
cin.sync(); // 清空缓冲区
|
||||
|
main(); |
||||
|
return 0; |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
|
||||
|
// [6/29/2016 Lit]:人脸检测使用示例
|
||||
|
int DemoDetect() |
||||
|
{ |
||||
|
// 程序启动时创建句柄
|
||||
|
cw_errcode_t errCode = CW_SDKLIT_OK; |
||||
|
void *pDetHandle = CreateDetHandle(&errCode); |
||||
|
if (NULL == pDetHandle) |
||||
|
{ |
||||
|
std::cout<<"Create detector Error, Code: " << errCode << endl; |
||||
|
return RetPause(-1); |
||||
|
} |
||||
|
cout << endl; |
||||
|
|
||||
|
string sPath, sPathPic; |
||||
|
if (!GetImageAndPath(sPathPic, sPath)) |
||||
|
{ |
||||
|
return RetPause(-1, pDetHandle); |
||||
|
} |
||||
|
|
||||
|
std::ifstream ifs(sPathPic.c_str(), std::ios::binary); |
||||
|
ifs.seekg(0, std::ios::end); |
||||
|
int iImgLen = ifs.tellg(); |
||||
|
ifs.seekg(0, std::ios::beg); |
||||
|
char *szImg = new char[iImgLen]; |
||||
|
ifs.read(szImg, iImgLen); |
||||
|
|
||||
|
// 给图像结构体赋值
|
||||
|
cw_img_t srcImg; |
||||
|
srcImg.frameId = 0; |
||||
|
srcImg.data = szImg; |
||||
|
srcImg.dataLen = iImgLen; |
||||
|
srcImg.angle = CW_IMAGE_ANGLE_0; |
||||
|
srcImg.format = CW_IMAGE_BINARY; |
||||
|
|
||||
|
cw_face_res_t faceBuffers[MAX_NUM_FACES]; |
||||
|
int iFaceNum = 0; |
||||
|
// 只做人脸检测
|
||||
|
cw_errcode_t errDet = cwFaceDetection(pDetHandle, &srcImg, faceBuffers, MAX_NUM_FACES, &iFaceNum, CW_OP_DET); |
||||
|
delete[] szImg; |
||||
|
if (errDet != CW_SDKLIT_OK) |
||||
|
{ |
||||
|
cout<<"Face detect Error, Code: " << errDet << endl; |
||||
|
return RetPause(-1, pDetHandle); |
||||
|
} |
||||
|
if (iFaceNum < 1) |
||||
|
{ |
||||
|
cout<<"No Face Detected" << endl; |
||||
|
return RetPause(-1, pDetHandle); |
||||
|
} |
||||
|
|
||||
|
cout << "Face Number: " << iFaceNum << endl; |
||||
|
for (int i = 0; i < iFaceNum; i++) |
||||
|
{ |
||||
|
cout << "Face " << i + 1 << ": Pos: " << faceBuffers[i].faceRect.x << "," << faceBuffers[i].faceRect.y << "," << faceBuffers[i].faceRect.width << "," |
||||
|
<< faceBuffers[i].faceRect.height << endl; |
||||
|
} |
||||
|
|
||||
|
cout << "Face Detect Completely" << endl; |
||||
|
|
||||
|
return RetPause(0, pDetHandle); |
||||
|
} |
||||
|
|
||||
|
// [9/13/2016 Lit]:人脸质量使用示例
|
||||
|
int DemoQuality() |
||||
|
{ |
||||
|
// 程序启动时创建句柄
|
||||
|
cw_errcode_t errCode = CW_SDKLIT_OK; |
||||
|
void *pDetHandle = CreateDetHandle(&errCode); |
||||
|
if (NULL == pDetHandle) |
||||
|
{ |
||||
|
std::cout<<"Create detector Error, Code: " << errCode << endl; |
||||
|
return RetPause(-1); |
||||
|
} |
||||
|
cout << endl; |
||||
|
|
||||
|
string sPath, sPathPic; |
||||
|
if (!GetImageAndPath(sPathPic, sPath)) |
||||
|
{ |
||||
|
return RetPause(-1, pDetHandle); |
||||
|
} |
||||
|
|
||||
|
std::ifstream ifs(sPathPic.c_str(), std::ios::binary); |
||||
|
ifs.seekg(0, std::ios::end); |
||||
|
int iImgLen = ifs.tellg(); |
||||
|
ifs.seekg(0, std::ios::beg); |
||||
|
char *szImg = new char[iImgLen]; |
||||
|
ifs.read(szImg, iImgLen); |
||||
|
|
||||
|
// 给图像结构体赋值
|
||||
|
cw_img_t srcImg; |
||||
|
srcImg.frameId = 0; |
||||
|
srcImg.data = szImg; |
||||
|
srcImg.dataLen = iImgLen; |
||||
|
srcImg.angle = CW_IMAGE_ANGLE_0; |
||||
|
srcImg.format = CW_IMAGE_BINARY; |
||||
|
|
||||
|
cw_face_res_t faceBuffers[MAX_NUM_FACES]; |
||||
|
int iFaceNum = 0; |
||||
|
// 人脸检测和人脸质量操作 CW_OP_DET | CW_OP_QUALITY
|
||||
|
cw_errcode_t errDet = cwFaceDetection(pDetHandle, &srcImg, faceBuffers, MAX_NUM_FACES, &iFaceNum, CW_OP_DET | CW_OP_QUALITY); |
||||
|
delete[] szImg; |
||||
|
if (errDet != CW_SDKLIT_OK) |
||||
|
{ |
||||
|
cout<<"Face detect Error, Code: " << errDet << endl; |
||||
|
return RetPause(-1, pDetHandle); |
||||
|
} |
||||
|
if (iFaceNum < 1) |
||||
|
{ |
||||
|
cout<<"No Face Detected" << endl; |
||||
|
return RetPause(-1, pDetHandle); |
||||
|
} |
||||
|
|
||||
|
cout << "Face Number: " << iFaceNum << endl; |
||||
|
for (int i = 0; i < iFaceNum; i++) |
||||
|
{ |
||||
|
cw_quality_errcode errQuality = faceBuffers[i].quality.errcode; |
||||
|
if (CW_QUALITY_OK == errQuality) |
||||
|
{ |
||||
|
cout << "Face " << i + 1 << ": Pos: " << faceBuffers[i].faceRect.x << "," << faceBuffers[i].faceRect.y << "," << faceBuffers[i].faceRect.width << "," |
||||
|
<< faceBuffers[i].faceRect.height << " Quality Score: " << faceBuffers[i].quality.scores[0] << endl; |
||||
|
cout << "faceBuffers[i].quality.scores: [ "; |
||||
|
for(int m =0; m < (sizeof(faceBuffers[i].quality.scores) / sizeof(faceBuffers[i].quality.scores[0])); m++) |
||||
|
{ |
||||
|
cout << faceBuffers[0].quality.scores[m] << " "; |
||||
|
} |
||||
|
cout << " ]\n"; |
||||
|
} |
||||
|
else |
||||
|
{ |
||||
|
cout << "Face " << i + 1 << ": Pos: " << faceBuffers[i].faceRect.x << "," << faceBuffers[i].faceRect.y << "," << faceBuffers[i].faceRect.width << "," |
||||
|
<< faceBuffers[i].faceRect.height << " Quality Err: " << errQuality << endl; |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
cout << "Face Quality Completely" << endl; |
||||
|
|
||||
|
return RetPause(0, pDetHandle); |
||||
|
} |
||||
|
|
||||
|
// [6/29/2016 Lit]:人脸比对使用示例(1:1)
|
||||
|
int DemoVerify() |
||||
|
{ |
||||
|
cw_errcode_t errCode = CW_SDKLIT_OK; |
||||
|
void *pDetHandle = CreateDetHandle(&errCode); |
||||
|
if (NULL == pDetHandle) |
||||
|
{ |
||||
|
std::cout<<"Create detector Error, Code: " << errCode << std::endl; |
||||
|
return RetPause(-1); |
||||
|
} |
||||
|
|
||||
|
void *pRecogHandle = CreateRecogHandle(&errCode); |
||||
|
if (NULL == pRecogHandle || CW_SDKLIT_OK != errCode) |
||||
|
{ |
||||
|
std::cout<<"Create Recog Handle Error, Code: " << errCode << std::endl; |
||||
|
return RetPause(-1, pDetHandle); |
||||
|
} |
||||
|
cout << endl; |
||||
|
|
||||
|
string sPath, sPathPic1; |
||||
|
if (!GetImageAndPath(sPathPic1, sPath)) |
||||
|
{ |
||||
|
return RetPause(-1, pDetHandle); |
||||
|
} |
||||
|
|
||||
|
string sPathPic2; |
||||
|
if (!GetImageAndPath(sPathPic2, sPath)) |
||||
|
{ |
||||
|
return RetPause(-1, pDetHandle); |
||||
|
} |
||||
|
|
||||
|
int iFeaLen = cwGetFeatureLength(pRecogHandle); |
||||
|
char *pFeaFiled = new char[iFeaLen]; |
||||
|
if (0 != GetFeatureFromPath(pDetHandle, pRecogHandle, sPathPic1, pFeaFiled)) |
||||
|
{ |
||||
|
cout << "Pic1 Failed\n"; |
||||
|
delete[] pFeaFiled; |
||||
|
return RetPause(-1, pDetHandle, pRecogHandle,NULL); |
||||
|
} |
||||
|
|
||||
|
char *pFeaProbe = new char[iFeaLen]; |
||||
|
if (0 != GetFeatureFromPath(pDetHandle, pRecogHandle, sPathPic2, pFeaProbe)) |
||||
|
{ |
||||
|
cout << "Pic2 Failed\n"; |
||||
|
delete[] pFeaFiled; |
||||
|
delete[] pFeaProbe; |
||||
|
return RetPause(-1, pDetHandle, pRecogHandle,NULL); |
||||
|
} |
||||
|
|
||||
|
float scores[1] = {0.0}; |
||||
|
errCode = cwComputeMatchScore(pRecogHandle, pFeaProbe, pFeaFiled, 1, scores); |
||||
|
delete[] pFeaFiled; |
||||
|
delete[] pFeaProbe; |
||||
|
if (errCode != CW_SDKLIT_OK) |
||||
|
{ |
||||
|
cout << "Recog Error: " << errCode; |
||||
|
return RetPause(-1, pDetHandle, pRecogHandle,NULL); |
||||
|
} |
||||
|
|
||||
|
cout << "Verify Score: " << scores[0] << endl; |
||||
|
|
||||
|
cout << "Face Verify Completely" << endl; |
||||
|
|
||||
|
return RetPause(0, pDetHandle, pRecogHandle,NULL); |
||||
|
} |
||||
|
|
||||
|
// 直接调用比对接口
|
||||
|
int DemoVerify2() |
||||
|
{ |
||||
|
cw_errcode_t errCode = CW_SDKLIT_OK; |
||||
|
void *pDetHandle = CreateDetHandle(&errCode); |
||||
|
if (NULL == pDetHandle) |
||||
|
{ |
||||
|
std::cout<<"Create detector Error, Code: " << errCode << std::endl; |
||||
|
return RetPause(-1); |
||||
|
} |
||||
|
|
||||
|
void *pRecogHandle = CreateRecogHandle(&errCode); |
||||
|
if (NULL == pRecogHandle || CW_SDKLIT_OK != errCode) |
||||
|
{ |
||||
|
std::cout<<"Create Recog Handle Error, Code: " << errCode << std::endl; |
||||
|
return RetPause(-1, pDetHandle); |
||||
|
} |
||||
|
cout << endl; |
||||
|
|
||||
|
string sPath, sPathPic1; |
||||
|
if (!GetImageAndPath(sPathPic1, sPath)) |
||||
|
{ |
||||
|
return RetPause(-1, pDetHandle); |
||||
|
} |
||||
|
|
||||
|
string sPathPic2; |
||||
|
if (!GetImageAndPath(sPathPic2, sPath)) |
||||
|
{ |
||||
|
return RetPause(-1, pDetHandle); |
||||
|
} |
||||
|
|
||||
|
std::ifstream ifs(sPathPic1.c_str(), std::ios::binary); |
||||
|
ifs.seekg(0, std::ios::end); |
||||
|
int iImgLen = ifs.tellg(); |
||||
|
ifs.seekg(0, std::ios::beg); |
||||
|
char *szImg = new char[iImgLen]; |
||||
|
ifs.read(szImg, iImgLen); |
||||
|
|
||||
|
cw_img_t srcImg; |
||||
|
srcImg.frameId = 0; |
||||
|
srcImg.data = szImg; |
||||
|
srcImg.dataLen = iImgLen; |
||||
|
srcImg.angle = CW_IMAGE_ANGLE_0; |
||||
|
srcImg.format = CW_IMAGE_BINARY; |
||||
|
srcImg.mirror = CW_IMAGE_MIRROR_NONE; |
||||
|
|
||||
|
std::ifstream ifs2(sPathPic2.c_str(), std::ios::binary); |
||||
|
ifs2.seekg(0, std::ios::end); |
||||
|
int iImgLen2 = ifs2.tellg(); |
||||
|
ifs2.seekg(0, std::ios::beg); |
||||
|
char *szImg2 = new char[iImgLen2]; |
||||
|
ifs2.read(szImg2, iImgLen2); |
||||
|
|
||||
|
cw_img_t srcImg2; |
||||
|
srcImg2.frameId = 0; |
||||
|
srcImg2.data = szImg2; |
||||
|
srcImg2.dataLen = iImgLen2; |
||||
|
srcImg2.angle = CW_IMAGE_ANGLE_0; |
||||
|
srcImg2.format = CW_IMAGE_BINARY; |
||||
|
srcImg2.mirror = CW_IMAGE_MIRROR_NONE; |
||||
|
|
||||
|
float fScore = 0.0f; |
||||
|
errCode = cwVerifyImageData(pDetHandle, pRecogHandle, &srcImg, &srcImg2, &fScore); |
||||
|
delete[] szImg; |
||||
|
delete[] szImg2; |
||||
|
|
||||
|
if (errCode != CW_SDKLIT_OK) |
||||
|
{ |
||||
|
cout << "Verify Error: " << errCode; |
||||
|
return RetPause(-1, pDetHandle, pRecogHandle); |
||||
|
} |
||||
|
|
||||
|
cout << "Verify Score: " << fScore << endl; |
||||
|
|
||||
|
cout << "Face Verify Completely" << endl; |
||||
|
|
||||
|
return RetPause(0, pDetHandle, pRecogHandle); |
||||
|
} |
||||
|
|
||||
|
// [6/29/2016 Lit]:人脸识别使用示例(1:N)
|
||||
|
int DemoRecog() |
||||
|
{ |
||||
|
cw_errcode_t errCode = CW_SDKLIT_OK; |
||||
|
void *pDetHandle = CreateDetHandle(&errCode); |
||||
|
if (NULL == pDetHandle) |
||||
|
{ |
||||
|
std::cout<<"Create detector Error, Code: " << errCode << std::endl; |
||||
|
return RetPause(-1); |
||||
|
} |
||||
|
|
||||
|
void *pRecogHandle = CreateRecogHandle(&errCode); |
||||
|
if (NULL == pRecogHandle || CW_SDKLIT_OK != errCode) |
||||
|
{ |
||||
|
std::cout<<"Create Recog Handle Error, Code: " << errCode << std::endl; |
||||
|
return RetPause(-1, pDetHandle); |
||||
|
} |
||||
|
cout << endl; |
||||
|
|
||||
|
string sPath, sPathPic1; |
||||
|
if (!GetImageAndPath(sPathPic1, sPath)) |
||||
|
{ |
||||
|
return RetPause(-1, pDetHandle); |
||||
|
} |
||||
|
|
||||
|
string sPathPic2; |
||||
|
if (!GetImageAndPath(sPathPic2, sPath)) |
||||
|
{ |
||||
|
return RetPause(-1, pDetHandle); |
||||
|
} |
||||
|
|
||||
|
int iFeaLen = cwGetFeatureLength(pRecogHandle); |
||||
|
// 底库为图片1和图片2
|
||||
|
char *pFeaFiled = new char[iFeaLen * 2]; |
||||
|
if (0 != GetFeatureFromPath(pDetHandle, pRecogHandle, sPathPic1, pFeaFiled)) |
||||
|
{ |
||||
|
cout << "Pic2 Failed\n"; |
||||
|
delete[] pFeaFiled; |
||||
|
return RetPause(-1, pDetHandle, pRecogHandle); |
||||
|
} |
||||
|
if (0 != GetFeatureFromPath(pDetHandle, pRecogHandle, sPathPic2, pFeaFiled + iFeaLen)) |
||||
|
{ |
||||
|
cout << "Pic1 Failed\n"; |
||||
|
delete[] pFeaFiled; |
||||
|
return RetPause(-1, pDetHandle, pRecogHandle); |
||||
|
} |
||||
|
|
||||
|
// 用于检索
|
||||
|
char *pFeaProbe = new char[iFeaLen]; |
||||
|
if (0 != GetFeatureFromPath(pDetHandle, pRecogHandle, sPathPic2, pFeaProbe)) |
||||
|
{ |
||||
|
cout << "Pic2 Failed\n"; |
||||
|
delete[] pFeaFiled; |
||||
|
delete[] pFeaProbe; |
||||
|
return RetPause(-1, pDetHandle, pRecogHandle); |
||||
|
} |
||||
|
|
||||
|
// 识别图片2,底库为图片1和图片2
|
||||
|
float scores[2] = {0.0}; |
||||
|
errCode = cwComputeMatchScore(pRecogHandle, pFeaProbe, pFeaFiled, 2, scores); |
||||
|
delete[] pFeaFiled; |
||||
|
delete[] pFeaProbe; |
||||
|
if (errCode != CW_SDKLIT_OK) |
||||
|
{ |
||||
|
cout << "Recog Error: " << errCode; |
||||
|
return RetPause(-1, pDetHandle, pRecogHandle); |
||||
|
} |
||||
|
|
||||
|
cout << "Recog Score: " << endl << scores[0] << endl << scores[1] << endl; |
||||
|
|
||||
|
cout << "Face Recognise Completely" << endl; |
||||
|
|
||||
|
return RetPause(0, pDetHandle, pRecogHandle); |
||||
|
} |
||||
|
|
||||
|
|
||||
|
//[16/10/2018 Lit]: 人脸属性识别检测
|
||||
|
int DemoAttribute() |
||||
|
{ |
||||
|
cw_errcode errCode=CW_SDKLIT_OK; |
||||
|
void *pDetHandle = CreateDetHandle(&errCode); |
||||
|
if (pDetHandle == NULL) |
||||
|
{ |
||||
|
cout << "Create Detector Erroe,Code: "<< errCode << endl; |
||||
|
return RetPause(-1); |
||||
|
} |
||||
|
|
||||
|
|
||||
|
const char* AgeModelPath ="../../CWModels/attribute/ageGroup/CWR_Config3.0.xml"; |
||||
|
void *pAgeHandle=CreateAttributeHandle(&errCode,AgeModelPath); |
||||
|
if(NULL==pAgeHandle) |
||||
|
{ |
||||
|
cout<< "Create AgeAttribute Handle Error! ErrCode:"<< errCode << endl; |
||||
|
RetPause (-1); |
||||
|
} |
||||
|
|
||||
|
const char* GenderModelPath ="../../CWModels/attribute/faceGender/cw_gender_config.xml"; |
||||
|
void *pGenderHandle=CreateAttributeHandle(&errCode,GenderModelPath); |
||||
|
if(NULL==pGenderHandle) |
||||
|
{ |
||||
|
cout<< "Create GenderAttribute Handle Error! ErrCode:"<< errCode << endl; |
||||
|
RetPause (-1); |
||||
|
} |
||||
|
|
||||
|
const char* RaceModelPath ="../../CWModels/attribute/faceRace/cw_race_config.xml"; |
||||
|
void *pRaceHandle=CreateAttributeHandle(&errCode,RaceModelPath); |
||||
|
if(NULL==pRaceHandle) |
||||
|
{ |
||||
|
cout<< "Create RaceAttribute Handle Error! ErrCode:"<< errCode << endl; |
||||
|
RetPause (-1); |
||||
|
} |
||||
|
|
||||
|
cout << endl; |
||||
|
|
||||
|
string sPath, sPathPic; |
||||
|
if (!GetImageAndPath(sPathPic, sPath)) |
||||
|
{ |
||||
|
return RetPause(-1, pDetHandle, NULL); |
||||
|
} |
||||
|
|
||||
|
std::ifstream ifs(sPathPic.c_str(), std::ios::binary); |
||||
|
ifs.seekg(0, std::ios::end); |
||||
|
int iImgLen = ifs.tellg(); |
||||
|
ifs.seekg(0, std::ios::beg); |
||||
|
char *szImg = new char[iImgLen]; |
||||
|
ifs.read(szImg, iImgLen); |
||||
|
|
||||
|
// 给图像结构体赋值
|
||||
|
cw_img_t srcImg; |
||||
|
srcImg.frameId = 0; |
||||
|
srcImg.data = szImg; |
||||
|
srcImg.dataLen = iImgLen; |
||||
|
srcImg.angle = CW_IMAGE_ANGLE_0; |
||||
|
srcImg.format = CW_IMAGE_BINARY; |
||||
|
srcImg.mirror = CW_IMAGE_MIRROR_NONE; |
||||
|
|
||||
|
cw_face_res_t faceBuffers[MAX_NUM_FACES]; |
||||
|
int iFaceNum = 0; |
||||
|
// 人脸检测,获取对齐人脸
|
||||
|
errCode = cwFaceDetection(pDetHandle, &srcImg, faceBuffers, MAX_NUM_FACES, &iFaceNum, CW_OP_DET | CW_OP_ALIGN); |
||||
|
delete[] szImg; |
||||
|
if (errCode != CW_SDKLIT_OK) |
||||
|
{ |
||||
|
cout << "Face detect Error, Code: " << errCode << endl; |
||||
|
return RetPause(-1, pDetHandle, NULL, pAgeHandle,pGenderHandle,pRaceHandle); |
||||
|
} |
||||
|
if (iFaceNum < 1) |
||||
|
{ |
||||
|
cout<<"No Face Detected" << endl; |
||||
|
return RetPause(-1, pDetHandle, NULL, pAgeHandle,pGenderHandle,pRaceHandle); |
||||
|
} |
||||
|
|
||||
|
int iAge = 0, iGender = 0, iRace = 0; |
||||
|
float fConfidence =0.0; |
||||
|
for (int i = 0; i < iFaceNum; i++) |
||||
|
{ |
||||
|
//年龄段
|
||||
|
errCode = cwGetAgeEval(pAgeHandle, &faceBuffers[i].faceAligned, &iAge); |
||||
|
if (CW_SDKLIT_OK == errCode) |
||||
|
{ |
||||
|
printf("Face %d AgeGroup: %d\n", i + 1, iAge); |
||||
|
} |
||||
|
else |
||||
|
{ |
||||
|
printf("Face %d Age Error: %d\n", i + 1, errCode); |
||||
|
} |
||||
|
|
||||
|
//性别
|
||||
|
errCode = cwGetGenderEval(pGenderHandle, &faceBuffers[i].faceAligned, &iGender, &fConfidence); |
||||
|
if (CW_SDKLIT_OK == errCode) |
||||
|
{ |
||||
|
printf("Face %d Gender: %d, Confidence: %.2f\n", i + 1, iGender, fConfidence); |
||||
|
} |
||||
|
else |
||||
|
{ |
||||
|
printf("Face %d Gender Error: %d\n", i + 1, errCode); |
||||
|
} |
||||
|
|
||||
|
//种族
|
||||
|
errCode = cwGetRaceEval(pRaceHandle, &faceBuffers[i].faceAligned, &iRace, &fConfidence); |
||||
|
if (CW_SDKLIT_OK == errCode) |
||||
|
{ |
||||
|
printf("Face %d Race: %d, Confidence: %.2f\n", i + 1, iRace, fConfidence); |
||||
|
} |
||||
|
else |
||||
|
{ |
||||
|
printf("Face %d Race Error: %d\n", i + 1, errCode); |
||||
|
} |
||||
|
|
||||
|
} |
||||
|
|
||||
|
cout << "Face Attribute Completely" << endl; |
||||
|
return RetPause(0, pDetHandle, NULL, pAgeHandle,pGenderHandle,pRaceHandle); |
||||
|
} |
||||
|
|
||||
|
// [9/4/2017 Lit]:红外活体检测Demo
|
||||
|
int DemoNisLiveness() |
||||
|
{ |
||||
|
cw_errcode_t errCode = CW_SDKLIT_OK; |
||||
|
void *pDetHandle = CreateDetHandle(&errCode); |
||||
|
if (NULL == pDetHandle) |
||||
|
{ |
||||
|
std::cout<<"Create detector Error, Code: " << errCode << std::endl; |
||||
|
return RetPause(-1); |
||||
|
} |
||||
|
|
||||
|
cw_nirliveness_err_t errNis = CW_NIRLIV_OK; |
||||
|
void *pNisLiveness = CreateNisLivenessHandle(&errNis); |
||||
|
if (pNisLiveness == NULL) |
||||
|
{ |
||||
|
std::cout<<"Create NisLiveness Error, Code: " << errNis << std::endl; |
||||
|
return RetPause(-1, pDetHandle); |
||||
|
} |
||||
|
std::cout << endl; |
||||
|
|
||||
|
string sPath, sPathPicVis; // 可见光照片
|
||||
|
if (!GetImageAndPath(sPathPicVis, sPath)) |
||||
|
{ |
||||
|
return RetPause(-1, pDetHandle,NULL, NULL, NULL,NULL, pNisLiveness); |
||||
|
} |
||||
|
|
||||
|
string sPathPicNir; // 红外照片
|
||||
|
if (!GetImageAndPath(sPathPicNir, sPath)) |
||||
|
{ |
||||
|
return RetPause(-1, pDetHandle,NULL, NULL, NULL,NULL, pNisLiveness); |
||||
|
} |
||||
|
|
||||
|
// 可见光图片
|
||||
|
std::ifstream ifs(sPathPicVis.c_str(), std::ios::binary); |
||||
|
ifs.seekg(0, std::ios::end); |
||||
|
int iImgLen = ifs.tellg(); |
||||
|
if (iImgLen < 1) |
||||
|
{ |
||||
|
std::cout << "可见光图片错误"; |
||||
|
return RetPause(-1, pDetHandle,NULL, NULL, NULL,NULL, pNisLiveness); |
||||
|
} |
||||
|
ifs.seekg(0, std::ios::beg); |
||||
|
char *szImg = new char[iImgLen]; |
||||
|
ifs.read(szImg, iImgLen); |
||||
|
|
||||
|
// 红外图片
|
||||
|
std::ifstream ifsNir(sPathPicNir.c_str(), std::ios::binary); |
||||
|
ifsNir.seekg(0, std::ios::end); |
||||
|
int iImgLenNir = ifsNir.tellg(); |
||||
|
if (iImgLenNir < 1) |
||||
|
{ |
||||
|
delete[] szImg; |
||||
|
std::cout << "红外图片错误"; |
||||
|
return RetPause(-1, pDetHandle,NULL, NULL, NULL,NULL, pNisLiveness); |
||||
|
} |
||||
|
ifsNir.seekg(0, std::ios::beg); |
||||
|
char *szImgNir = new char[iImgLenNir]; |
||||
|
ifsNir.read(szImgNir, iImgLenNir); |
||||
|
|
||||
|
#if 0 |
||||
|
|
||||
|
// 采用封装红外活体接口
|
||||
|
cw_img_t srcImgVis; |
||||
|
srcImgVis.frameId = 0; |
||||
|
srcImgVis.data = szImg; |
||||
|
srcImgVis.dataLen = iImgLen; |
||||
|
srcImgVis.angle = CW_IMAGE_ANGLE_0; |
||||
|
srcImgVis.format = CW_IMAGE_BINARY; |
||||
|
srcImgVis.mirror = CW_IMAGE_MIRROR_NONE; |
||||
|
|
||||
|
cw_img_t srcImgNir; |
||||
|
srcImgNir.frameId = 0; |
||||
|
srcImgNir.data = szImgNir; |
||||
|
srcImgNir.dataLen = iImgLenNir; |
||||
|
srcImgNir.angle = CW_IMAGE_ANGLE_0; |
||||
|
srcImgNir.format = CW_IMAGE_BINARY; |
||||
|
srcImgNir.mirror = CW_IMAGE_MIRROR_NONE; |
||||
|
|
||||
|
cw_nirliv_res_t nirLivRes; |
||||
|
errNis = cwFaceNirByImageData(pDetHandle, pNisLiveness, &srcImgVis, &srcImgNir, &nirLivRes); |
||||
|
if (errNis == CW_NIRLIV_OK) |
||||
|
{ |
||||
|
std::cout << "liveness state: " << nirLivRes.livRst << ", score: " << nirLivRes.score << std::endl; |
||||
|
} |
||||
|
else |
||||
|
{ |
||||
|
std::cout << "cwFaceNirByImageData Error: " << errNis << std::endl; |
||||
|
} |
||||
|
|
||||
|
delete[] szImg; |
||||
|
delete[] szImgNir; |
||||
|
|
||||
|
cout << "\nFace NisLiveness Completely" << endl; |
||||
|
|
||||
|
return RetPause(0, pDetHandle, NULL, NULL, pNisLiveness); |
||||
|
|
||||
|
#else |
||||
|
|
||||
|
// 采用原始红外活体接口
|
||||
|
cw_face_res_t *faceBuffersVis = new cw_face_res_t[MAX_NUM_FACES]; |
||||
|
int iFaceNumVis = GetFaceInfoByImgData(pDetHandle, szImg, iImgLen, faceBuffersVis); |
||||
|
if (iFaceNumVis < 1) |
||||
|
{ |
||||
|
cout << "可见光检测失败"; |
||||
|
delete[] szImg; |
||||
|
delete[] szImgNir; |
||||
|
delete[] faceBuffersVis; |
||||
|
return RetPause(-1, pDetHandle,NULL, NULL, NULL,NULL, pNisLiveness); |
||||
|
} |
||||
|
|
||||
|
cw_face_res_t *faceBuffersNis = new cw_face_res_t[MAX_NUM_FACES]; |
||||
|
int iFaceNumNis = GetFaceInfoByImgData(pDetHandle, szImgNir, iImgLenNir, faceBuffersNis); |
||||
|
if (iFaceNumNis < 1) |
||||
|
{ |
||||
|
cout << "红外检测失败"; |
||||
|
delete[] szImg; |
||||
|
delete[] faceBuffersVis; |
||||
|
delete[] szImgNir; |
||||
|
delete[] faceBuffersNis; |
||||
|
return RetPause(-1, pDetHandle,NULL, NULL, NULL,NULL, pNisLiveness); |
||||
|
} |
||||
|
cout << endl; |
||||
|
|
||||
|
|
||||
|
// 取红外和可见光图片中的第一个人脸做活体
|
||||
|
cw_nirliv_detinfo_t detInfo; |
||||
|
detInfo.nLandmarks = faceBuffersVis[0].keypt.nkeypt; //关键点个数
|
||||
|
|
||||
|
// 红外图片数据
|
||||
|
detInfo.pNirImg = new cw_nirliv_img_t(); |
||||
|
detInfo.pNirImg->data = szImgNir; |
||||
|
detInfo.pNirImg->dataLen = iImgLenNir; |
||||
|
detInfo.pNirImg->format = CW_IMAGE_BINARY; // 这里读取后都是3通道的bgr图
|
||||
|
|
||||
|
// 可见光图片数据
|
||||
|
detInfo.pVisImg = new cw_nirliv_img_t(); |
||||
|
detInfo.pVisImg->data = szImg; |
||||
|
detInfo.pVisImg->dataLen = iImgLen; |
||||
|
detInfo.pVisImg->format = CW_IMAGE_BINARY; // 这里读取后都是3通道的bgr图
|
||||
|
|
||||
|
detInfo.pVisInfo = new cw_nirliv_face_param_t(); // 可见光人脸信息
|
||||
|
detInfo.pVisInfo->pKeypoints = faceBuffersVis[0].keypt.points; |
||||
|
detInfo.pVisInfo->fKeyScore = faceBuffersVis[0].keypt.keyptScore; // 质量分
|
||||
|
detInfo.pVisInfo->fSkinScore = faceBuffersVis[0].quality.scores[6]; // 肤色分
|
||||
|
|
||||
|
detInfo.pNirInfo = new cw_nirliv_face_param_t(); // 红外人脸信息
|
||||
|
detInfo.pNirInfo->pKeypoints = faceBuffersNis[0].keypt.points; |
||||
|
detInfo.pNirInfo->fKeyScore = faceBuffersNis[0].keypt.keyptScore; // 质量分
|
||||
|
detInfo.pNirInfo->fSkinScore = faceBuffersNis[0].quality.scores[6]; // 肤色分
|
||||
|
|
||||
|
cw_nirliv_res_t nisLivenessRes; |
||||
|
errNis = cwFaceNirLivenessDet(pNisLiveness, &detInfo, &nisLivenessRes); |
||||
|
if (errNis == CW_NIRLIV_OK) |
||||
|
{ |
||||
|
cout << "state: " << nisLivenessRes.livRst << " score: " << nisLivenessRes.score << endl; |
||||
|
} |
||||
|
else |
||||
|
{ |
||||
|
cout << "Face NisLiveness Error: " << errNis << endl; |
||||
|
} |
||||
|
|
||||
|
delete[] szImg; |
||||
|
delete[] szImgNir; |
||||
|
delete[] faceBuffersVis; |
||||
|
delete[] faceBuffersNis; |
||||
|
delete detInfo.pNirImg; |
||||
|
delete detInfo.pVisImg; |
||||
|
delete detInfo.pVisInfo; |
||||
|
delete detInfo.pNirInfo; |
||||
|
|
||||
|
cout << "\nFace NisLiveness Completely" << endl; |
||||
|
|
||||
|
return RetPause(0, pDetHandle, NULL, NULL, pNisLiveness); |
||||
|
|
||||
|
#endif |
||||
|
|
||||
|
|
||||
|
} |
||||
Binary file not shown.
@ -0,0 +1,18 @@ |
|||||
|
<?xml version="1.0"?> |
||||
|
<configuration> |
||||
|
<appSettings> |
||||
|
<!--比对阈值--> |
||||
|
<add key="Shrelhod" value="70"/> |
||||
|
<!--摄像头配置,有n个摄像头,可配置为0到n-1,分别调用不同的摄像头--> |
||||
|
<add key="CameraIndex" value="0"/> |
||||
|
<!-- 服务器地址--> |
||||
|
<add key="HttpUrl" value="http://192.168.1.181:8009"/> |
||||
|
<add key="KioskUrl" value="http://192.168.1.181:8010"/> |
||||
|
<add key="websocketUrl" value="ws://192.168.1.128:7180"/> |
||||
|
<add key="websocketForFace" value="ws://192.168.1.128:7179"/> |
||||
|
<add key="websocketForLive" value="ws://192.168.1.128:7188"/> |
||||
|
</appSettings> |
||||
|
<startup> |
||||
|
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.6"/> |
||||
|
</startup> |
||||
|
</configuration> |
||||
@ -0,0 +1,8 @@ |
|||||
|
<Application x:Class="DemoUI.App" |
||||
|
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" |
||||
|
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" |
||||
|
Startup="Application_Startup"> |
||||
|
<Application.Resources> |
||||
|
|
||||
|
</Application.Resources> |
||||
|
</Application> |
||||
@ -0,0 +1,54 @@ |
|||||
|
using DemoUI.Common; |
||||
|
using System; |
||||
|
using System.Collections.Generic; |
||||
|
using System.Configuration; |
||||
|
using System.Data; |
||||
|
using System.Linq; |
||||
|
using System.Threading.Tasks; |
||||
|
using System.Windows; |
||||
|
|
||||
|
namespace DemoUI |
||||
|
{ |
||||
|
/// <summary>
|
||||
|
/// App.xaml 的交互逻辑
|
||||
|
/// </summary>
|
||||
|
public partial class App : Application |
||||
|
{ |
||||
|
QMLog log = new QMLog(); |
||||
|
private void Application_Startup(object sender, StartupEventArgs e) |
||||
|
{ |
||||
|
|
||||
|
try |
||||
|
{ |
||||
|
log.WriteLogFile("正常启动", "start"); |
||||
|
AppDomain.CurrentDomain.UnhandledException += new UnhandledExceptionEventHandler(CurrentDomain_UnhandledException); |
||||
|
Application.Current.DispatcherUnhandledException += new System.Windows.Threading.DispatcherUnhandledExceptionEventHandler(Current_DispatcherUnhandledException); |
||||
|
AppDomain.CurrentDomain.ProcessExit += new EventHandler(CurrentDomain_ProcessExit); |
||||
|
MainWindow win = new MainWindow(); |
||||
|
win.Show(); |
||||
|
} |
||||
|
catch (Exception ex) |
||||
|
{ |
||||
|
log.WriteLogFile(ex.ToString(), "StartupError"); |
||||
|
MessageBox.Show("程序启动失败"); |
||||
|
} |
||||
|
} |
||||
|
private void Current_DispatcherUnhandledException(object sender, System.Windows.Threading.DispatcherUnhandledExceptionEventArgs e) |
||||
|
{ |
||||
|
log.WriteLogFile(e.Exception.Message + e.Exception.StackTrace, "APPError"); |
||||
|
} |
||||
|
|
||||
|
private void CurrentDomain_UnhandledException(object sender, UnhandledExceptionEventArgs e) |
||||
|
{ |
||||
|
Exception ex = (Exception)e.ExceptionObject; |
||||
|
log.WriteLogFile(ex.Message + ex.StackTrace, "APPError"); |
||||
|
} |
||||
|
|
||||
|
private void CurrentDomain_ProcessExit(object sender, EventArgs e) |
||||
|
{ |
||||
|
log.WriteLogFile("程序关闭", "start"); |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
|
||||
|
} |
||||
@ -0,0 +1,218 @@ |
|||||
|
|
||||
|
|
||||
|
using DemoUI.SDK; |
||||
|
using Emgu.CV; |
||||
|
using Fleck; |
||||
|
using Newtonsoft.Json; |
||||
|
using System; |
||||
|
using System.Collections.Concurrent; |
||||
|
using System.Collections.Generic; |
||||
|
using System.Configuration; |
||||
|
using System.Runtime.InteropServices; |
||||
|
|
||||
|
namespace DemoUI.Common |
||||
|
{ |
||||
|
|
||||
|
public class ChatWebSocketMiddleware |
||||
|
{ |
||||
|
public static List<IWebSocketConnection> allSockets = new List<IWebSocketConnection>(); |
||||
|
//public static List<IWebSocketConnection> allSocketsForTest = new List<IWebSocketConnection>();
|
||||
|
public static List<IWebSocketConnection> allSocketsForLive = new List<IWebSocketConnection>(); |
||||
|
public static List<IWebSocketConnection> faceSockets = new List<IWebSocketConnection>(); |
||||
|
public static string CurFaceID = string.Empty; |
||||
|
public static Mat CurFaceImage = null; |
||||
|
public static cw_face_res_t? CurFaceModel = null; |
||||
|
public static object NoFaceModel = new { faceID = "", isValid = false, beautyScore = 0, faceImage = "", genderMale = "" }; |
||||
|
public static bool isLive = false; |
||||
|
//public static bool isTestLive = false;
|
||||
|
private QMLog log = new QMLog(); |
||||
|
public void openSocket() |
||||
|
{ |
||||
|
FleckLog.Level = LogLevel.Debug; |
||||
|
var ws = ConfigurationManager.AppSettings["websocketUrl"]; |
||||
|
log.WriteLogFile(ConfigurationManager.AppSettings["websocketUrl"],"222"); |
||||
|
var server = new WebSocketServer(ws); |
||||
|
server.Start(socket => |
||||
|
{ |
||||
|
socket.OnOpen = () => //当建立Socket链接时执行此方法
|
||||
|
{ |
||||
|
//var data = socket.ConnectionInfo; //通过data可以获得这个链接传递过来的Cookie信息,用来区分各个链接和用户之间的关系(如果需要后台主动推送信息到某个客户的时候,可以使用Cookie)
|
||||
|
allSockets.Add(socket); |
||||
|
log.WriteLogFile("======"+ allSockets.Count, "222"); |
||||
|
if (!string.IsNullOrEmpty(CurFaceID)) { |
||||
|
socket.Send(CurFaceID); |
||||
|
} |
||||
|
}; |
||||
|
|
||||
|
socket.OnClose = () =>// 当关闭Socket链接十执行此方法
|
||||
|
{ |
||||
|
//Console.WriteLine("Close!");
|
||||
|
allSockets.Remove(socket); |
||||
|
log.WriteLogFile("====11==" + allSockets.Count, "222"); |
||||
|
}; |
||||
|
|
||||
|
socket.OnMessage = message =>// 接收客户端发送过来的信息
|
||||
|
{ |
||||
|
if (message == "face") |
||||
|
{ |
||||
|
if (!string.IsNullOrEmpty(CurFaceID)) |
||||
|
{ |
||||
|
Dictionary<string, Object> dicData = JsonConvert.DeserializeObject<Dictionary<string, Object>>(CurFaceID); |
||||
|
var faceData = new { faceID = dicData["faceID"], isValid = true, beautyScore = dicData["beautyScore"], faceImage = dicData["faceImage"], genderMale = dicData["genderMale"] }; |
||||
|
socket.Send(JsonConvert.SerializeObject(faceData)); |
||||
|
} |
||||
|
|
||||
|
//if (CurFaceImage != null && CurFaceModel.HasValue)
|
||||
|
// SendFaceForKiosk(CurFaceImage, CurFaceModel.Value, socket);
|
||||
|
} |
||||
|
else if (message == "openlive") |
||||
|
{ |
||||
|
isLive = true; |
||||
|
} |
||||
|
else if (message == "closelive") |
||||
|
{ |
||||
|
log.WriteLogFile("进来了", "2222222222222"); |
||||
|
ChatWebSocketMiddleware.isLive = false; |
||||
|
} |
||||
|
|
||||
|
//Console.WriteLine(message);
|
||||
|
//socket.Send("Echo: " + message);
|
||||
|
//allSockets.ToList().ForEach(s => s.Send("Echo: " + message));
|
||||
|
}; |
||||
|
}); |
||||
|
|
||||
|
} |
||||
|
|
||||
|
//public void openSocketForTest()
|
||||
|
//{
|
||||
|
// FleckLog.Level = LogLevel.Debug;
|
||||
|
// var ws = "ws://192.168.1.128:7189";
|
||||
|
// var server = new WebSocketServer(ws);
|
||||
|
// server.Start(socket =>
|
||||
|
// {
|
||||
|
// socket.OnOpen = () => //当建立Socket链接时执行此方法
|
||||
|
// {
|
||||
|
// //var data = socket.ConnectionInfo; //通过data可以获得这个链接传递过来的Cookie信息,用来区分各个链接和用户之间的关系(如果需要后台主动推送信息到某个客户的时候,可以使用Cookie)
|
||||
|
// allSocketsForTest.Add(socket);
|
||||
|
// };
|
||||
|
|
||||
|
// socket.OnClose = () =>// 当关闭Socket链接十执行此方法
|
||||
|
// {
|
||||
|
// //Console.WriteLine("Close!");
|
||||
|
// allSocketsForTest.Remove(socket);
|
||||
|
// };
|
||||
|
|
||||
|
// socket.OnMessage = message =>// 接收客户端发送过来的信息
|
||||
|
// {
|
||||
|
// if (message == "openlive")
|
||||
|
// {
|
||||
|
// isTestLive = true;
|
||||
|
// }
|
||||
|
// else if (message == "closelive")
|
||||
|
// {
|
||||
|
// ChatWebSocketMiddleware.isTestLive = false;
|
||||
|
// }
|
||||
|
|
||||
|
// //Console.WriteLine(message);
|
||||
|
// //socket.Send("Echo: " + message);
|
||||
|
// //allSockets.ToList().ForEach(s => s.Send("Echo: " + message));
|
||||
|
// };
|
||||
|
// });
|
||||
|
|
||||
|
//}
|
||||
|
|
||||
|
public void openSocketForLive() |
||||
|
{ |
||||
|
FleckLog.Level = LogLevel.Debug; |
||||
|
var ws = ConfigurationManager.AppSettings["websocketForLive"]; |
||||
|
var server = new WebSocketServer(ws); |
||||
|
server.Start(socket => |
||||
|
{ |
||||
|
socket.OnOpen = () => //当建立Socket链接时执行此方法
|
||||
|
{ |
||||
|
ChatWebSocketMiddleware.isLive = true; |
||||
|
//var data = socket.ConnectionInfo; //通过data可以获得这个链接传递过来的Cookie信息,用来区分各个链接和用户之间的关系(如果需要后台主动推送信息到某个客户的时候,可以使用Cookie)
|
||||
|
allSocketsForLive.Add(socket); |
||||
|
}; |
||||
|
|
||||
|
socket.OnClose = () =>// 当关闭Socket链接十执行此方法
|
||||
|
{ |
||||
|
ChatWebSocketMiddleware.isLive = false; |
||||
|
//Console.WriteLine("Close!");
|
||||
|
allSocketsForLive.Remove(socket); |
||||
|
}; |
||||
|
|
||||
|
socket.OnMessage = message =>// 接收客户端发送过来的信息
|
||||
|
{ |
||||
|
//if (message == "openlive")
|
||||
|
//{
|
||||
|
// ChatWebSocketMiddleware.isLive = true;
|
||||
|
//}
|
||||
|
//else if (message == "closelive")
|
||||
|
//{
|
||||
|
// ChatWebSocketMiddleware.isLive = false;
|
||||
|
//}
|
||||
|
//Console.WriteLine(message);
|
||||
|
//socket.Send("Echo: " + message);
|
||||
|
//allSockets.ToList().ForEach(s => s.Send("Echo: " + message));
|
||||
|
}; |
||||
|
}); |
||||
|
|
||||
|
} |
||||
|
|
||||
|
|
||||
|
public void openSocketForFace() |
||||
|
{ |
||||
|
FleckLog.Level = LogLevel.Debug; |
||||
|
var ws = ConfigurationManager.AppSettings["websocketForFace"]; |
||||
|
var server = new WebSocketServer(ws); |
||||
|
server.Start(socket => |
||||
|
{ |
||||
|
socket.OnOpen = () => //当建立Socket链接时执行此方法
|
||||
|
{ |
||||
|
log.WriteLogFile("屏保socket111111","face"); |
||||
|
var data = socket.ConnectionInfo; //通过data可以获得这个链接传递过来的Cookie信息,用来区分各个链接和用户之间的关系(如果需要后台主动推送信息到某个客户的时候,可以使用Cookie)
|
||||
|
Console.WriteLine("Open!"); |
||||
|
faceSockets.Add(socket); |
||||
|
}; |
||||
|
|
||||
|
socket.OnClose = () =>// 当关闭Socket链接十执行此方法
|
||||
|
{ |
||||
|
|
||||
|
Console.WriteLine("Close!"); |
||||
|
faceSockets.Remove(socket); |
||||
|
}; |
||||
|
|
||||
|
socket.OnMessage = message =>// 接收客户端发送过来的信息
|
||||
|
{ |
||||
|
log.WriteLogFile(message, "face"); |
||||
|
|
||||
|
if (message.IndexOf("导航") >= 0) |
||||
|
{ |
||||
|
var faceData = new |
||||
|
{ |
||||
|
faceID = "-1", |
||||
|
faceImage = message.Replace("导航", "") |
||||
|
}; |
||||
|
faceSockets.ForEach(s => s.Send(JsonConvert.SerializeObject(faceData))); |
||||
|
} |
||||
|
else if (message.IndexOf("首页") >= 0) |
||||
|
{ |
||||
|
var faceData = new |
||||
|
{ |
||||
|
faceID = "-1", |
||||
|
faceImage = message |
||||
|
}; |
||||
|
faceSockets.ForEach(s => s.Send(JsonConvert.SerializeObject(faceData))); |
||||
|
} |
||||
|
//log.WriteLogFile(message,"人脸点击");
|
||||
|
//allSockets.ForEach(s => s.Send("Echo: " + message));
|
||||
|
//Console.WriteLine(message);
|
||||
|
//socket.Send("Echo: " + message);
|
||||
|
//allSockets.ToList().ForEach(s => s.Send("Echo: " + message));
|
||||
|
}; |
||||
|
}); |
||||
|
|
||||
|
} |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,176 @@ |
|||||
|
using System; |
||||
|
using System.Collections.Generic; |
||||
|
using System.IO; |
||||
|
using System.Linq; |
||||
|
using System.Text; |
||||
|
|
||||
|
namespace DemoUI.Common |
||||
|
{ |
||||
|
public class QMLog |
||||
|
{ |
||||
|
/**/ |
||||
|
/// <summary>
|
||||
|
/// 写入日志文件
|
||||
|
/// </summary>
|
||||
|
/// <param name="input"></param>
|
||||
|
public void WriteLogFile(string input, string strfileName = "Errlog") |
||||
|
{ |
||||
|
try |
||||
|
{ |
||||
|
/**/ |
||||
|
///指定日志文件的目录
|
||||
|
strfileName = strfileName + DateTime.Now.ToString("yyyy-MM-dd"); |
||||
|
string fpath = Directory.GetCurrentDirectory() + "\\log\\" + DateTime.Now.ToString("yyyy-MM-dd") + "\\"; |
||||
|
if (!Directory.Exists(fpath)) |
||||
|
{ |
||||
|
DirectoryInfo directoryInfo = new DirectoryInfo(fpath); |
||||
|
directoryInfo.Create(); |
||||
|
} |
||||
|
|
||||
|
string fname = Directory.GetCurrentDirectory() + "\\log\\" + DateTime.Now.ToString("yyyy-MM-dd") + "\\" + strfileName + ".txt"; |
||||
|
|
||||
|
/**/ |
||||
|
///定义文件信息对象
|
||||
|
///
|
||||
|
FileInfo finfo = new FileInfo(fname); |
||||
|
if (!finfo.Exists) |
||||
|
{ |
||||
|
FileStream fs = new FileStream(fname, FileMode.Create, FileAccess.Write); |
||||
|
//fs = File.Create(fname);
|
||||
|
fs.Close(); |
||||
|
finfo = new FileInfo(fname); |
||||
|
} |
||||
|
/**/ |
||||
|
///判断文件是否存在以及是否大于2K
|
||||
|
if (finfo.Length > 1024 * 1024 * 10) |
||||
|
{ |
||||
|
/**/ |
||||
|
///文件超过10MB则重命名
|
||||
|
File.Move(Directory.GetCurrentDirectory() + "\\LogFile.txt", Directory.GetCurrentDirectory() + DateTime.Now.TimeOfDay + "\\LogFile.txt"); |
||||
|
/**/ |
||||
|
///删除该文件
|
||||
|
//finfo.Delete();
|
||||
|
} |
||||
|
//finfo.AppendText();
|
||||
|
/**/ |
||||
|
///创建只写文件流
|
||||
|
|
||||
|
using (FileStream fs = finfo.OpenWrite()) |
||||
|
{ |
||||
|
/**/ |
||||
|
///根据上面创建的文件流创建写数据流
|
||||
|
StreamWriter w = new StreamWriter(fs); |
||||
|
|
||||
|
/**/ |
||||
|
///设置写数据流的起始位置为文件流的末尾
|
||||
|
w.BaseStream.Seek(0, SeekOrigin.End); |
||||
|
/**/ |
||||
|
///写入“Log Entry : ”
|
||||
|
w.Write("\n\rLog Entry : "); |
||||
|
/**/ |
||||
|
///写入当前系统时间并换行
|
||||
|
w.Write("{0} {1} \n\r", DateTime.Now.ToLongTimeString(), |
||||
|
DateTime.Now.ToLongDateString()); |
||||
|
/**/ |
||||
|
///写入日志内容并换行
|
||||
|
w.Write(input + "\n\r"); |
||||
|
/**/ |
||||
|
///写入------------------------------------“并换行
|
||||
|
w.Write("------------------------------------\n\r"); |
||||
|
/**/ |
||||
|
///清空缓冲区内容,并把缓冲区内容写入基础流
|
||||
|
w.Flush(); |
||||
|
/**/ |
||||
|
///关闭写数据流
|
||||
|
w.Close(); |
||||
|
} |
||||
|
} |
||||
|
catch { } |
||||
|
|
||||
|
} |
||||
|
|
||||
|
/// <summary>
|
||||
|
/// 删除 month 个月之前的 strFileName日志
|
||||
|
/// </summary>
|
||||
|
/// <param name="strFileName"></param>
|
||||
|
/// <param name="month"></param>
|
||||
|
public static void DeleteLogFile(string strFileName = "ErrLog", int month = 1) |
||||
|
{ |
||||
|
try |
||||
|
{ |
||||
|
string logPath = Directory.GetCurrentDirectory() + "\\log\\" + strFileName; |
||||
|
if (!Directory.Exists(logPath))//若文件夹不存在则返回
|
||||
|
return; |
||||
|
else |
||||
|
logPath += "\\"; |
||||
|
DirectoryInfo theFolder = new DirectoryInfo(@logPath); |
||||
|
FileInfo[] fileInfo = theFolder.GetFiles(); |
||||
|
foreach (FileInfo NextFile in fileInfo) //遍历文件
|
||||
|
{ |
||||
|
DateTime dt1 = Convert.ToDateTime(NextFile.Name.Substring(strFileName.Length, NextFile.Name.Length - strFileName.Length - 4) + " 00:00:00"); |
||||
|
DateTime dt2 = DateTime.Now.AddMonths(-month); |
||||
|
if (dt1 < dt2) |
||||
|
{ |
||||
|
NextFile.Delete(); |
||||
|
} |
||||
|
} |
||||
|
} |
||||
|
catch |
||||
|
{ |
||||
|
} |
||||
|
|
||||
|
|
||||
|
} |
||||
|
|
||||
|
public void DeleteFiles(string fileName = "") |
||||
|
{ |
||||
|
try |
||||
|
{ |
||||
|
if (string.IsNullOrEmpty(fileName)) |
||||
|
fileName = Directory.GetCurrentDirectory() + "\\log"; |
||||
|
if (!Directory.Exists(fileName))//若文件夹不存在则返回
|
||||
|
return; |
||||
|
DirectoryInfo dir = new DirectoryInfo(fileName);//new DirectoryInfo(Directory.GetCurrentDirectory() + "\\log");
|
||||
|
//不是目录
|
||||
|
|
||||
|
if (dir == null) |
||||
|
return; |
||||
|
//DateTime DT = dir.CreationTime;
|
||||
|
|
||||
|
FileSystemInfo[] files = dir.GetFileSystemInfos(); |
||||
|
for (int i = 0; i < files.Length; i++) |
||||
|
{ |
||||
|
FileInfo file = files[i] as FileInfo; |
||||
|
//是文件
|
||||
|
if (file != null) |
||||
|
{ |
||||
|
DateTime DT = file.CreationTime; |
||||
|
if (DateTime.Now.Month - DT.Month >= 1) |
||||
|
{ |
||||
|
file.Delete(); |
||||
|
} |
||||
|
} |
||||
|
else |
||||
|
{ |
||||
|
DirectoryInfo dir1 = files[i] as DirectoryInfo; |
||||
|
if (dir1 != null) |
||||
|
{ |
||||
|
DateTime DT = dir1.CreationTime; |
||||
|
if (DateTime.Now.Month - DT.Month >= 1) |
||||
|
{ |
||||
|
//dir1.Delete();
|
||||
|
System.IO.Directory.Delete(fileName + "\\" + dir1.Name, true); |
||||
|
} |
||||
|
} |
||||
|
} |
||||
|
} |
||||
|
} |
||||
|
catch |
||||
|
{ |
||||
|
} |
||||
|
|
||||
|
} |
||||
|
|
||||
|
|
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,236 @@ |
|||||
|
<?xml version="1.0" encoding="utf-8"?> |
||||
|
<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> |
||||
|
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" /> |
||||
|
<PropertyGroup> |
||||
|
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration> |
||||
|
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform> |
||||
|
<ProjectGuid>{4BE25B21-AF00-4BDC-BC24-3A423FB9C87C}</ProjectGuid> |
||||
|
<OutputType>WinExe</OutputType> |
||||
|
<AppDesignerFolder>Properties</AppDesignerFolder> |
||||
|
<RootNamespace>DemoUI</RootNamespace> |
||||
|
<AssemblyName>DemoUI</AssemblyName> |
||||
|
<TargetFrameworkVersion>v4.6</TargetFrameworkVersion> |
||||
|
<FileAlignment>512</FileAlignment> |
||||
|
<ProjectTypeGuids>{60dc8134-eba5-43b8-bcc9-bb4bc16c2548};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids> |
||||
|
<WarningLevel>4</WarningLevel> |
||||
|
<TargetFrameworkProfile /> |
||||
|
<PublishUrl>publish\</PublishUrl> |
||||
|
<Install>true</Install> |
||||
|
<InstallFrom>Disk</InstallFrom> |
||||
|
<UpdateEnabled>false</UpdateEnabled> |
||||
|
<UpdateMode>Foreground</UpdateMode> |
||||
|
<UpdateInterval>7</UpdateInterval> |
||||
|
<UpdateIntervalUnits>Days</UpdateIntervalUnits> |
||||
|
<UpdatePeriodically>false</UpdatePeriodically> |
||||
|
<UpdateRequired>false</UpdateRequired> |
||||
|
<MapFileExtensions>true</MapFileExtensions> |
||||
|
<ApplicationRevision>0</ApplicationRevision> |
||||
|
<ApplicationVersion>1.0.0.%2a</ApplicationVersion> |
||||
|
<IsWebBootstrapper>false</IsWebBootstrapper> |
||||
|
<UseApplicationTrust>false</UseApplicationTrust> |
||||
|
<BootstrapperEnabled>true</BootstrapperEnabled> |
||||
|
</PropertyGroup> |
||||
|
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' "> |
||||
|
<PlatformTarget>x86</PlatformTarget> |
||||
|
<DebugSymbols>true</DebugSymbols> |
||||
|
<DebugType>full</DebugType> |
||||
|
<Optimize>false</Optimize> |
||||
|
<OutputPath>..\build_32\bin\</OutputPath> |
||||
|
<DefineConstants>DEBUG;TRACE</DefineConstants> |
||||
|
<ErrorReport>prompt</ErrorReport> |
||||
|
<WarningLevel>4</WarningLevel> |
||||
|
<Prefer32Bit>false</Prefer32Bit> |
||||
|
</PropertyGroup> |
||||
|
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' "> |
||||
|
<PlatformTarget>x86</PlatformTarget> |
||||
|
<DebugType>pdbonly</DebugType> |
||||
|
<Optimize>true</Optimize> |
||||
|
<OutputPath>..\build_32\bin\</OutputPath> |
||||
|
<DefineConstants>TRACE</DefineConstants> |
||||
|
<ErrorReport>prompt</ErrorReport> |
||||
|
<WarningLevel>4</WarningLevel> |
||||
|
<Prefer32Bit>false</Prefer32Bit> |
||||
|
</PropertyGroup> |
||||
|
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|x86'"> |
||||
|
<DebugSymbols>true</DebugSymbols> |
||||
|
<OutputPath>..\build_32\bin\</OutputPath> |
||||
|
<DefineConstants>DEBUG;TRACE</DefineConstants> |
||||
|
<DebugType>full</DebugType> |
||||
|
<PlatformTarget>x86</PlatformTarget> |
||||
|
<ErrorReport>prompt</ErrorReport> |
||||
|
<CodeAnalysisRuleSet>MinimumRecommendedRules.ruleset</CodeAnalysisRuleSet> |
||||
|
<Prefer32Bit>true</Prefer32Bit> |
||||
|
</PropertyGroup> |
||||
|
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Release|x86'"> |
||||
|
<OutputPath>..\build_32\bin\</OutputPath> |
||||
|
<DefineConstants>TRACE</DefineConstants> |
||||
|
<Optimize>true</Optimize> |
||||
|
<DebugType>pdbonly</DebugType> |
||||
|
<PlatformTarget>x86</PlatformTarget> |
||||
|
<ErrorReport>prompt</ErrorReport> |
||||
|
<CodeAnalysisRuleSet>MinimumRecommendedRules.ruleset</CodeAnalysisRuleSet> |
||||
|
<Prefer32Bit>true</Prefer32Bit> |
||||
|
</PropertyGroup> |
||||
|
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|x64'"> |
||||
|
<DebugSymbols>true</DebugSymbols> |
||||
|
<OutputPath>..\build_64\bin\</OutputPath> |
||||
|
<DefineConstants>DEBUG;TRACE</DefineConstants> |
||||
|
<DebugType>full</DebugType> |
||||
|
<PlatformTarget>x64</PlatformTarget> |
||||
|
<ErrorReport>prompt</ErrorReport> |
||||
|
<CodeAnalysisRuleSet>MinimumRecommendedRules.ruleset</CodeAnalysisRuleSet> |
||||
|
<Prefer32Bit>true</Prefer32Bit> |
||||
|
</PropertyGroup> |
||||
|
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Release|x64'"> |
||||
|
<OutputPath>..\build_64\bin\</OutputPath> |
||||
|
<DefineConstants>TRACE</DefineConstants> |
||||
|
<Optimize>true</Optimize> |
||||
|
<DebugType>pdbonly</DebugType> |
||||
|
<PlatformTarget>x64</PlatformTarget> |
||||
|
<ErrorReport>prompt</ErrorReport> |
||||
|
<CodeAnalysisRuleSet>MinimumRecommendedRules.ruleset</CodeAnalysisRuleSet> |
||||
|
<Prefer32Bit>true</Prefer32Bit> |
||||
|
</PropertyGroup> |
||||
|
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Release_XP|AnyCPU'"> |
||||
|
<OutputPath>bin\Release_XP\</OutputPath> |
||||
|
<DefineConstants>TRACE</DefineConstants> |
||||
|
<Optimize>true</Optimize> |
||||
|
<DebugType>pdbonly</DebugType> |
||||
|
<PlatformTarget>x86</PlatformTarget> |
||||
|
<ErrorReport>prompt</ErrorReport> |
||||
|
<CodeAnalysisRuleSet>MinimumRecommendedRules.ruleset</CodeAnalysisRuleSet> |
||||
|
<Prefer32Bit>false</Prefer32Bit> |
||||
|
</PropertyGroup> |
||||
|
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Release_XP|x86'"> |
||||
|
<OutputPath>..\build_xp\bin\</OutputPath> |
||||
|
<DefineConstants>TRACE</DefineConstants> |
||||
|
<DebugType>pdbonly</DebugType> |
||||
|
<PlatformTarget>x86</PlatformTarget> |
||||
|
<ErrorReport>prompt</ErrorReport> |
||||
|
<CodeAnalysisRuleSet>MinimumRecommendedRules.ruleset</CodeAnalysisRuleSet> |
||||
|
<Prefer32Bit>true</Prefer32Bit> |
||||
|
</PropertyGroup> |
||||
|
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Release_XP|x64'"> |
||||
|
<OutputPath>bin\x64\Release_XP\</OutputPath> |
||||
|
<DefineConstants>TRACE</DefineConstants> |
||||
|
<Optimize>true</Optimize> |
||||
|
<DebugType>pdbonly</DebugType> |
||||
|
<PlatformTarget>x64</PlatformTarget> |
||||
|
<ErrorReport>prompt</ErrorReport> |
||||
|
<CodeAnalysisRuleSet>MinimumRecommendedRules.ruleset</CodeAnalysisRuleSet> |
||||
|
<Prefer32Bit>true</Prefer32Bit> |
||||
|
</PropertyGroup> |
||||
|
<ItemGroup> |
||||
|
<Reference Include="Emgu.CV"> |
||||
|
<HintPath>emgu\Emgu.CV.dll</HintPath> |
||||
|
</Reference> |
||||
|
<Reference Include="Emgu.Util"> |
||||
|
<HintPath>emgu\Emgu.Util.dll</HintPath> |
||||
|
</Reference> |
||||
|
<Reference Include="Fleck, Version=1.1.0.0, Culture=neutral, processorArchitecture=MSIL"> |
||||
|
<HintPath>packages\Fleck.1.1.0\lib\net40\Fleck.dll</HintPath> |
||||
|
</Reference> |
||||
|
<Reference Include="Newtonsoft.Json, Version=12.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL"> |
||||
|
<HintPath>packages\Newtonsoft.Json.12.0.2\lib\net40\Newtonsoft.Json.dll</HintPath> |
||||
|
</Reference> |
||||
|
<Reference Include="System" /> |
||||
|
<Reference Include="System.configuration" /> |
||||
|
<Reference Include="System.Data" /> |
||||
|
<Reference Include="System.Drawing" /> |
||||
|
<Reference Include="System.Net" /> |
||||
|
<Reference Include="System.Net.WebSockets, Version=4.0.1.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL"> |
||||
|
<HintPath>packages\System.Net.WebSockets.4.3.0\lib\net46\System.Net.WebSockets.dll</HintPath> |
||||
|
</Reference> |
||||
|
<Reference Include="System.Windows.Forms" /> |
||||
|
<Reference Include="System.Xml" /> |
||||
|
<Reference Include="Microsoft.CSharp" /> |
||||
|
<Reference Include="System.Core" /> |
||||
|
<Reference Include="System.Xml.Linq" /> |
||||
|
<Reference Include="System.Data.DataSetExtensions" /> |
||||
|
<Reference Include="System.Xaml"> |
||||
|
<RequiredTargetFramework>4.0</RequiredTargetFramework> |
||||
|
</Reference> |
||||
|
<Reference Include="WindowsBase" /> |
||||
|
<Reference Include="PresentationCore" /> |
||||
|
<Reference Include="PresentationFramework" /> |
||||
|
<Reference Include="WindowsFormsIntegration" /> |
||||
|
</ItemGroup> |
||||
|
<ItemGroup> |
||||
|
<ApplicationDefinition Include="App.xaml"> |
||||
|
<Generator>MSBuild:Compile</Generator> |
||||
|
<SubType>Designer</SubType> |
||||
|
</ApplicationDefinition> |
||||
|
<Compile Include="Common\ChatWebSocketMiddleware.cs" /> |
||||
|
<Compile Include="Common\QMLog.cs" /> |
||||
|
<Compile Include="SDK\NativeCWFaceAttribute.cs" /> |
||||
|
<Compile Include="SDK\NativeCWFaceConfig.cs" /> |
||||
|
<Compile Include="SDK\NativeCWFaceDetection.cs" /> |
||||
|
<Compile Include="SDK\NativeCWFaceNISLiveness.cs" /> |
||||
|
<Compile Include="SDK\NativeCWFaceRecognition.cs" /> |
||||
|
<Compile Include="SDK\NativeCWFaceVersion.cs" /> |
||||
|
<Compile Include="Window1.xaml.cs"> |
||||
|
<DependentUpon>Window1.xaml</DependentUpon> |
||||
|
</Compile> |
||||
|
<Page Include="MainWindow.xaml"> |
||||
|
<Generator>MSBuild:Compile</Generator> |
||||
|
<SubType>Designer</SubType> |
||||
|
</Page> |
||||
|
<Compile Include="App.xaml.cs"> |
||||
|
<DependentUpon>App.xaml</DependentUpon> |
||||
|
<SubType>Code</SubType> |
||||
|
</Compile> |
||||
|
<Compile Include="MainWindow.xaml.cs"> |
||||
|
<DependentUpon>MainWindow.xaml</DependentUpon> |
||||
|
<SubType>Code</SubType> |
||||
|
</Compile> |
||||
|
<Page Include="Window1.xaml"> |
||||
|
<SubType>Designer</SubType> |
||||
|
<Generator>MSBuild:Compile</Generator> |
||||
|
</Page> |
||||
|
</ItemGroup> |
||||
|
<ItemGroup> |
||||
|
<Compile Include="Properties\AssemblyInfo.cs"> |
||||
|
<SubType>Code</SubType> |
||||
|
</Compile> |
||||
|
<Compile Include="Properties\Resources.Designer.cs"> |
||||
|
<AutoGen>True</AutoGen> |
||||
|
<DesignTime>True</DesignTime> |
||||
|
<DependentUpon>Resources.resx</DependentUpon> |
||||
|
</Compile> |
||||
|
<Compile Include="Properties\Settings.Designer.cs"> |
||||
|
<AutoGen>True</AutoGen> |
||||
|
<DependentUpon>Settings.settings</DependentUpon> |
||||
|
<DesignTimeSharedInput>True</DesignTimeSharedInput> |
||||
|
</Compile> |
||||
|
<EmbeddedResource Include="Properties\Resources.resx"> |
||||
|
<Generator>ResXFileCodeGenerator</Generator> |
||||
|
<LastGenOutput>Resources.Designer.cs</LastGenOutput> |
||||
|
</EmbeddedResource> |
||||
|
<None Include="packages.config" /> |
||||
|
<None Include="Properties\Settings.settings"> |
||||
|
<Generator>SettingsSingleFileGenerator</Generator> |
||||
|
<LastGenOutput>Settings.Designer.cs</LastGenOutput> |
||||
|
</None> |
||||
|
<AppDesigner Include="Properties\" /> |
||||
|
</ItemGroup> |
||||
|
<ItemGroup> |
||||
|
<None Include="App.config"> |
||||
|
<SubType>Designer</SubType> |
||||
|
</None> |
||||
|
</ItemGroup> |
||||
|
<ItemGroup> |
||||
|
<BootstrapperPackage Include="Microsoft.Net.Framework.3.5.SP1"> |
||||
|
<Visible>False</Visible> |
||||
|
<ProductName>.NET Framework 3.5 SP1</ProductName> |
||||
|
<Install>false</Install> |
||||
|
</BootstrapperPackage> |
||||
|
</ItemGroup> |
||||
|
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" /> |
||||
|
<!-- To modify your build process, add your task inside one of the targets below and uncomment it. |
||||
|
Other similar extension points exist, see Microsoft.Common.targets. |
||||
|
<Target Name="BeforeBuild"> |
||||
|
</Target> |
||||
|
<Target Name="AfterBuild"> |
||||
|
</Target> |
||||
|
--> |
||||
|
</Project> |
||||
@ -0,0 +1,32 @@ |
|||||
|
|
||||
|
Microsoft Visual Studio Solution File, Format Version 12.00 |
||||
|
# Visual Studio 2012 |
||||
|
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DemoUI", "DemoUI.csproj", "{4BE25B21-AF00-4BDC-BC24-3A423FB9C87C}" |
||||
|
EndProject |
||||
|
Global |
||||
|
GlobalSection(SolutionConfigurationPlatforms) = preSolution |
||||
|
Debug|Any CPU = Debug|Any CPU |
||||
|
Debug|x64 = Debug|x64 |
||||
|
Debug|x86 = Debug|x86 |
||||
|
Release|Any CPU = Release|Any CPU |
||||
|
Release|x64 = Release|x64 |
||||
|
Release|x86 = Release|x86 |
||||
|
EndGlobalSection |
||||
|
GlobalSection(ProjectConfigurationPlatforms) = postSolution |
||||
|
{4BE25B21-AF00-4BDC-BC24-3A423FB9C87C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU |
||||
|
{4BE25B21-AF00-4BDC-BC24-3A423FB9C87C}.Debug|Any CPU.Build.0 = Debug|Any CPU |
||||
|
{4BE25B21-AF00-4BDC-BC24-3A423FB9C87C}.Debug|x64.ActiveCfg = Debug|x64 |
||||
|
{4BE25B21-AF00-4BDC-BC24-3A423FB9C87C}.Debug|x64.Build.0 = Debug|x64 |
||||
|
{4BE25B21-AF00-4BDC-BC24-3A423FB9C87C}.Debug|x86.ActiveCfg = Debug|x86 |
||||
|
{4BE25B21-AF00-4BDC-BC24-3A423FB9C87C}.Debug|x86.Build.0 = Debug|x86 |
||||
|
{4BE25B21-AF00-4BDC-BC24-3A423FB9C87C}.Release|Any CPU.ActiveCfg = Release|Any CPU |
||||
|
{4BE25B21-AF00-4BDC-BC24-3A423FB9C87C}.Release|Any CPU.Build.0 = Release|Any CPU |
||||
|
{4BE25B21-AF00-4BDC-BC24-3A423FB9C87C}.Release|x64.ActiveCfg = Release|x64 |
||||
|
{4BE25B21-AF00-4BDC-BC24-3A423FB9C87C}.Release|x64.Build.0 = Release|x64 |
||||
|
{4BE25B21-AF00-4BDC-BC24-3A423FB9C87C}.Release|x86.ActiveCfg = Release|x86 |
||||
|
{4BE25B21-AF00-4BDC-BC24-3A423FB9C87C}.Release|x86.Build.0 = Release|x86 |
||||
|
EndGlobalSection |
||||
|
GlobalSection(SolutionProperties) = preSolution |
||||
|
HideSolutionNode = FALSE |
||||
|
EndGlobalSection |
||||
|
EndGlobal |
||||
@ -0,0 +1,12 @@ |
|||||
|
<Window x:Class="DemoUI.MainWindow" |
||||
|
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" |
||||
|
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" |
||||
|
xmlns:wf="clr-namespace:System.Windows.Forms;assembly=System.Windows.Forms" |
||||
|
Title="DemoCSharp" Height="700" Width="1000" WindowStartupLocation="CenterScreen" Closed="Window_Closed" WindowState="Minimized"> |
||||
|
<Grid> |
||||
|
<Border Background="Black"> |
||||
|
<Image Name="video" Stretch="Fill" VerticalAlignment="Top" HorizontalAlignment="Left"/> |
||||
|
</Border> |
||||
|
</Grid> |
||||
|
|
||||
|
</Window> |
||||
File diff suppressed because it is too large
@ -0,0 +1,55 @@ |
|||||
|
using System.Reflection; |
||||
|
using System.Resources; |
||||
|
using System.Runtime.CompilerServices; |
||||
|
using System.Runtime.InteropServices; |
||||
|
using System.Windows; |
||||
|
|
||||
|
// 有关程序集的常规信息通过以下
|
||||
|
// 特性集控制。更改这些特性值可修改
|
||||
|
// 与程序集关联的信息。
|
||||
|
[assembly: AssemblyTitle("DemoUI")] |
||||
|
[assembly: AssemblyDescription("")] |
||||
|
[assembly: AssemblyConfiguration("")] |
||||
|
[assembly: AssemblyCompany("")] |
||||
|
[assembly: AssemblyProduct("DemoUI")] |
||||
|
[assembly: AssemblyCopyright("Copyright © 2016")] |
||||
|
[assembly: AssemblyTrademark("")] |
||||
|
[assembly: AssemblyCulture("")] |
||||
|
|
||||
|
// 将 ComVisible 设置为 false 使此程序集中的类型
|
||||
|
// 对 COM 组件不可见。如果需要从 COM 访问此程序集中的类型,
|
||||
|
// 则将该类型上的 ComVisible 特性设置为 true。
|
||||
|
[assembly: ComVisible(false)] |
||||
|
|
||||
|
//若要开始生成可本地化的应用程序,请在
|
||||
|
//<PropertyGroup> 中的 .csproj 文件中
|
||||
|
//设置 <UICulture>CultureYouAreCodingWith</UICulture>。例如,如果您在源文件中
|
||||
|
//使用的是美国英语,请将 <UICulture> 设置为 en-US。然后取消
|
||||
|
//对以下 NeutralResourceLanguage 特性的注释。更新
|
||||
|
//以下行中的“en-US”以匹配项目文件中的 UICulture 设置。
|
||||
|
|
||||
|
//[assembly: NeutralResourcesLanguage("en-US", UltimateResourceFallbackLocation.Satellite)]
|
||||
|
|
||||
|
|
||||
|
[assembly: ThemeInfo( |
||||
|
ResourceDictionaryLocation.None, //主题特定资源词典所处位置
|
||||
|
//(在页面或应用程序资源词典中
|
||||
|
// 未找到某个资源的情况下使用)
|
||||
|
ResourceDictionaryLocation.SourceAssembly //常规资源词典所处位置
|
||||
|
//(在页面、应用程序或任何主题特定资源词典中
|
||||
|
// 未找到某个资源的情况下使用)
|
||||
|
)] |
||||
|
|
||||
|
|
||||
|
// 程序集的版本信息由下面四个值组成:
|
||||
|
//
|
||||
|
// 主版本
|
||||
|
// 次版本
|
||||
|
// 生成号
|
||||
|
// 修订号
|
||||
|
//
|
||||
|
// 可以指定所有这些值,也可以使用“生成号”和“修订号”的默认值,
|
||||
|
// 方法是按如下所示使用“*”:
|
||||
|
// [assembly: AssemblyVersion("1.0.*")]
|
||||
|
[assembly: AssemblyVersion("1.0.0.0")] |
||||
|
[assembly: AssemblyFileVersion("1.0.0.0")] |
||||
@ -0,0 +1,63 @@ |
|||||
|
//------------------------------------------------------------------------------
|
||||
|
// <auto-generated>
|
||||
|
// 此代码由工具生成。
|
||||
|
// 运行时版本:4.0.30319.42000
|
||||
|
//
|
||||
|
// 对此文件的更改可能会导致不正确的行为,并且如果
|
||||
|
// 重新生成代码,这些更改将会丢失。
|
||||
|
// </auto-generated>
|
||||
|
//------------------------------------------------------------------------------
|
||||
|
|
||||
|
namespace DemoUI.Properties { |
||||
|
using System; |
||||
|
|
||||
|
|
||||
|
/// <summary>
|
||||
|
/// 一个强类型的资源类,用于查找本地化的字符串等。
|
||||
|
/// </summary>
|
||||
|
// 此类是由 StronglyTypedResourceBuilder
|
||||
|
// 类通过类似于 ResGen 或 Visual Studio 的工具自动生成的。
|
||||
|
// 若要添加或移除成员,请编辑 .ResX 文件,然后重新运行 ResGen
|
||||
|
// (以 /str 作为命令选项),或重新生成 VS 项目。
|
||||
|
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "15.0.0.0")] |
||||
|
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()] |
||||
|
[global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] |
||||
|
internal class Resources { |
||||
|
|
||||
|
private static global::System.Resources.ResourceManager resourceMan; |
||||
|
|
||||
|
private static global::System.Globalization.CultureInfo resourceCulture; |
||||
|
|
||||
|
[global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] |
||||
|
internal Resources() { |
||||
|
} |
||||
|
|
||||
|
/// <summary>
|
||||
|
/// 返回此类使用的缓存的 ResourceManager 实例。
|
||||
|
/// </summary>
|
||||
|
[global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] |
||||
|
internal static global::System.Resources.ResourceManager ResourceManager { |
||||
|
get { |
||||
|
if (object.ReferenceEquals(resourceMan, null)) { |
||||
|
global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("DemoUI.Properties.Resources", typeof(Resources).Assembly); |
||||
|
resourceMan = temp; |
||||
|
} |
||||
|
return resourceMan; |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
/// <summary>
|
||||
|
/// 重写当前线程的 CurrentUICulture 属性
|
||||
|
/// 重写当前线程的 CurrentUICulture 属性。
|
||||
|
/// </summary>
|
||||
|
[global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] |
||||
|
internal static global::System.Globalization.CultureInfo Culture { |
||||
|
get { |
||||
|
return resourceCulture; |
||||
|
} |
||||
|
set { |
||||
|
resourceCulture = value; |
||||
|
} |
||||
|
} |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,117 @@ |
|||||
|
<?xml version="1.0" encoding="utf-8"?> |
||||
|
<root> |
||||
|
<!-- |
||||
|
Microsoft ResX Schema |
||||
|
|
||||
|
Version 2.0 |
||||
|
|
||||
|
The primary goals of this format is to allow a simple XML format |
||||
|
that is mostly human readable. The generation and parsing of the |
||||
|
various data types are done through the TypeConverter classes |
||||
|
associated with the data types. |
||||
|
|
||||
|
Example: |
||||
|
|
||||
|
... ado.net/XML headers & schema ... |
||||
|
<resheader name="resmimetype">text/microsoft-resx</resheader> |
||||
|
<resheader name="version">2.0</resheader> |
||||
|
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader> |
||||
|
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader> |
||||
|
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data> |
||||
|
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data> |
||||
|
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64"> |
||||
|
<value>[base64 mime encoded serialized .NET Framework object]</value> |
||||
|
</data> |
||||
|
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64"> |
||||
|
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value> |
||||
|
<comment>This is a comment</comment> |
||||
|
</data> |
||||
|
|
||||
|
There are any number of "resheader" rows that contain simple |
||||
|
name/value pairs. |
||||
|
|
||||
|
Each data row contains a name, and value. The row also contains a |
||||
|
type or mimetype. Type corresponds to a .NET class that support |
||||
|
text/value conversion through the TypeConverter architecture. |
||||
|
Classes that don't support this are serialized and stored with the |
||||
|
mimetype set. |
||||
|
|
||||
|
The mimetype is used for serialized objects, and tells the |
||||
|
ResXResourceReader how to depersist the object. This is currently not |
||||
|
extensible. For a given mimetype the value must be set accordingly: |
||||
|
|
||||
|
Note - application/x-microsoft.net.object.binary.base64 is the format |
||||
|
that the ResXResourceWriter will generate, however the reader can |
||||
|
read any of the formats listed below. |
||||
|
|
||||
|
mimetype: application/x-microsoft.net.object.binary.base64 |
||||
|
value : The object must be serialized with |
||||
|
: System.Serialization.Formatters.Binary.BinaryFormatter |
||||
|
: and then encoded with base64 encoding. |
||||
|
|
||||
|
mimetype: application/x-microsoft.net.object.soap.base64 |
||||
|
value : The object must be serialized with |
||||
|
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter |
||||
|
: and then encoded with base64 encoding. |
||||
|
|
||||
|
mimetype: application/x-microsoft.net.object.bytearray.base64 |
||||
|
value : The object must be serialized into a byte array |
||||
|
: using a System.ComponentModel.TypeConverter |
||||
|
: and then encoded with base64 encoding. |
||||
|
--> |
||||
|
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata"> |
||||
|
<xsd:element name="root" msdata:IsDataSet="true"> |
||||
|
<xsd:complexType> |
||||
|
<xsd:choice maxOccurs="unbounded"> |
||||
|
<xsd:element name="metadata"> |
||||
|
<xsd:complexType> |
||||
|
<xsd:sequence> |
||||
|
<xsd:element name="value" type="xsd:string" minOccurs="0" /> |
||||
|
</xsd:sequence> |
||||
|
<xsd:attribute name="name" type="xsd:string" /> |
||||
|
<xsd:attribute name="type" type="xsd:string" /> |
||||
|
<xsd:attribute name="mimetype" type="xsd:string" /> |
||||
|
</xsd:complexType> |
||||
|
</xsd:element> |
||||
|
<xsd:element name="assembly"> |
||||
|
<xsd:complexType> |
||||
|
<xsd:attribute name="alias" type="xsd:string" /> |
||||
|
<xsd:attribute name="name" type="xsd:string" /> |
||||
|
</xsd:complexType> |
||||
|
</xsd:element> |
||||
|
<xsd:element name="data"> |
||||
|
<xsd:complexType> |
||||
|
<xsd:sequence> |
||||
|
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" /> |
||||
|
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" /> |
||||
|
</xsd:sequence> |
||||
|
<xsd:attribute name="name" type="xsd:string" msdata:Ordinal="1" /> |
||||
|
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" /> |
||||
|
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" /> |
||||
|
</xsd:complexType> |
||||
|
</xsd:element> |
||||
|
<xsd:element name="resheader"> |
||||
|
<xsd:complexType> |
||||
|
<xsd:sequence> |
||||
|
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" /> |
||||
|
</xsd:sequence> |
||||
|
<xsd:attribute name="name" type="xsd:string" use="required" /> |
||||
|
</xsd:complexType> |
||||
|
</xsd:element> |
||||
|
</xsd:choice> |
||||
|
</xsd:complexType> |
||||
|
</xsd:element> |
||||
|
</xsd:schema> |
||||
|
<resheader name="resmimetype"> |
||||
|
<value>text/microsoft-resx</value> |
||||
|
</resheader> |
||||
|
<resheader name="version"> |
||||
|
<value>2.0</value> |
||||
|
</resheader> |
||||
|
<resheader name="reader"> |
||||
|
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value> |
||||
|
</resheader> |
||||
|
<resheader name="writer"> |
||||
|
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value> |
||||
|
</resheader> |
||||
|
</root> |
||||
@ -0,0 +1,26 @@ |
|||||
|
//------------------------------------------------------------------------------
|
||||
|
// <auto-generated>
|
||||
|
// 此代码由工具生成。
|
||||
|
// 运行时版本:4.0.30319.42000
|
||||
|
//
|
||||
|
// 对此文件的更改可能会导致不正确的行为,并且如果
|
||||
|
// 重新生成代码,这些更改将会丢失。
|
||||
|
// </auto-generated>
|
||||
|
//------------------------------------------------------------------------------
|
||||
|
|
||||
|
namespace DemoUI.Properties { |
||||
|
|
||||
|
|
||||
|
[global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] |
||||
|
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "15.9.0.0")] |
||||
|
internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase { |
||||
|
|
||||
|
private static Settings defaultInstance = ((Settings)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Settings()))); |
||||
|
|
||||
|
public static Settings Default { |
||||
|
get { |
||||
|
return defaultInstance; |
||||
|
} |
||||
|
} |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,7 @@ |
|||||
|
<?xml version='1.0' encoding='utf-8'?> |
||||
|
<SettingsFile xmlns="uri:settings" CurrentProfile="(Default)"> |
||||
|
<Profiles> |
||||
|
<Profile Name="(Default)" /> |
||||
|
</Profiles> |
||||
|
<Settings /> |
||||
|
</SettingsFile> |
||||
@ -0,0 +1,13 @@ |
|||||
|
using System; |
||||
|
using System.Collections.Generic; |
||||
|
using System.Linq; |
||||
|
using System.Text; |
||||
|
using System.Threading.Tasks; |
||||
|
|
||||
|
namespace DemoUI.SDK |
||||
|
{ |
||||
|
class FaceApi |
||||
|
{ |
||||
|
private const string CloudWalkSDKDll = "FaceApi.dll"; |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,54 @@ |
|||||
|
using System.Collections.Generic; |
||||
|
using System.Runtime.InteropServices; |
||||
|
using System.Text; |
||||
|
using System; |
||||
|
|
||||
|
namespace DemoUI.SDK |
||||
|
{ |
||||
|
/// <summary>
|
||||
|
/// 可见光单目活体接口
|
||||
|
/// </summary>
|
||||
|
public class CWFaceAttLiveness |
||||
|
{ |
||||
|
private const string CloudWalkSDKDll = "CWFaceSDK.dll"; |
||||
|
|
||||
|
/// <summary>
|
||||
|
/// 创建可见光单目活体句柄
|
||||
|
/// </summary>
|
||||
|
/// <param name="errCode">输出错误码</param>
|
||||
|
/// <param name="attDetType">单目活体检测模式</param>
|
||||
|
/// <param name="pModelPath">单目活体检测器模型文件夹路径</param>
|
||||
|
/// <param name="pLicence">授权码</param>
|
||||
|
/// <returns>如果创建成功,返回单目活体句柄,否则返回空</returns>
|
||||
|
[DllImport(CloudWalkSDKDll, EntryPoint = "cwCreateAttLivenessHandle", CallingConvention = CallingConvention.Cdecl)] |
||||
|
public static extern IntPtr cwCreateAttLivenessHandle(out cw_attliveness_err_t errCode, cw_attliv_mode_t attDetType, string pModelPath, string pLicence); |
||||
|
|
||||
|
|
||||
|
/// <summary>
|
||||
|
/// 释放单目活体检测句柄
|
||||
|
/// </summary>
|
||||
|
/// <param name="pHandle">单目活体句柄</param>
|
||||
|
[DllImport(CloudWalkSDKDll, EntryPoint = "cwReleaseAttLivenessHandle", CallingConvention = CallingConvention.Cdecl)] |
||||
|
public static extern void cwReleaseAttLivenessHandle(IntPtr pHandle); |
||||
|
|
||||
|
|
||||
|
/// <summary>
|
||||
|
/// 可见光单目活体检测接口
|
||||
|
/// </summary>
|
||||
|
/// <param name="pHandle">单目活体句柄</param>
|
||||
|
/// <param name="pAttDetInfo">输入的图片及关键点等信息</param>
|
||||
|
/// <param name="pAttackType">攻击类型</param>
|
||||
|
/// <returns></returns>
|
||||
|
[DllImport(CloudWalkSDKDll, EntryPoint = "cwFaceAttLivenessDet", CallingConvention = CallingConvention.Cdecl)] |
||||
|
public static extern cw_attliveness_err_t cwFaceAttLivenessDet(IntPtr pHandle, ref cw_att_liv_detinfo_t pAttDetInfo, out cw_attliv_det_rst_t pAttackType); |
||||
|
|
||||
|
|
||||
|
/// <summary>
|
||||
|
/// 重置活体检测器状态
|
||||
|
/// </summary>
|
||||
|
/// <param name="pHandle">单目活体句柄</param>
|
||||
|
/// <returns></returns>
|
||||
|
[DllImport(CloudWalkSDKDll, EntryPoint = "cwFaceAttLivenessReset", CallingConvention = CallingConvention.Cdecl)] |
||||
|
public static extern cw_attliveness_err_t cwFaceAttLivenessReset(IntPtr pHandle); |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,67 @@ |
|||||
|
using System.Collections.Generic; |
||||
|
using System.Runtime.InteropServices; |
||||
|
using System.Text; |
||||
|
using System; |
||||
|
|
||||
|
namespace DemoUI.SDK |
||||
|
{ |
||||
|
/// <summary>
|
||||
|
/// 人脸检测
|
||||
|
/// </summary>
|
||||
|
public class NativeCWFaceAttribute |
||||
|
{ |
||||
|
private const string CloudWalkSDKDll = "CWFaceSDK.dll"; |
||||
|
|
||||
|
/// <summary>
|
||||
|
/// 创建属性句柄
|
||||
|
/// </summary>
|
||||
|
/// <param name="pConfigFile">模型参数配置文件</param>
|
||||
|
/// <param name="pLicence">授权码
|
||||
|
/// <returns>如果创建成功,返回Attribute句柄,否则返回空</returns>
|
||||
|
[DllImport(CloudWalkSDKDll, EntryPoint = "cwCreateAttributeHandle", CallingConvention = CallingConvention.Cdecl)] |
||||
|
public static extern IntPtr cwCreateAttributeHandle(out cw_errcode_t errCode, string pConfigFile, string pLicence); |
||||
|
|
||||
|
|
||||
|
/// <summary>
|
||||
|
/// 释放属性句柄
|
||||
|
/// </summary>
|
||||
|
/// <param name="pAttributeHandle"></param>
|
||||
|
[DllImport(CloudWalkSDKDll, EntryPoint = "cwReleaseAttributeHandle", CallingConvention = CallingConvention.Cdecl)] |
||||
|
public static extern void cwReleaseAttributeHandle(IntPtr pAttributeHandle); |
||||
|
|
||||
|
|
||||
|
/// <summary>
|
||||
|
/// 年龄段估计
|
||||
|
/// </summary>
|
||||
|
/// <param name="pAttributeHandle"></param>
|
||||
|
/// <param name="alignedFace">对齐人脸</param>
|
||||
|
/// <param name="pAge">年龄段估计值,0 小孩 1 成年人 2 老人</param>
|
||||
|
/// <param name="confidence">置信分数 0-1之间的一个值,置信度越高</param>
|
||||
|
/// <returns></returns>
|
||||
|
[DllImport(CloudWalkSDKDll, EntryPoint = "cwGetAgeEval", CallingConvention = CallingConvention.Cdecl)] |
||||
|
public static extern cw_errcode_t cwGetAgeEval(IntPtr pAttributeHandle, ref cw_aligned_face_t alignedFace, out int pAge); |
||||
|
|
||||
|
|
||||
|
/// <summary>
|
||||
|
/// 性别估计
|
||||
|
/// </summary>
|
||||
|
/// <param name="pAttributeHandle"></param>
|
||||
|
/// <param name="alignedFace">对齐人脸</param>
|
||||
|
/// <param name="pGender">性别估计值,0 女性, 1 男性</param>
|
||||
|
/// <returns></returns>
|
||||
|
[DllImport(CloudWalkSDKDll, EntryPoint = "cwGetGenderEval", CallingConvention = CallingConvention.Cdecl)] |
||||
|
public static extern cw_errcode_t cwGetGenderEval(IntPtr pAttributeHandle, ref cw_aligned_face_t alignedFace, out int pGender, out float confidence); |
||||
|
|
||||
|
|
||||
|
/// <summary>
|
||||
|
/// 人种估计
|
||||
|
/// </summary>
|
||||
|
/// <param name="pAttributeHandle"></param>
|
||||
|
/// <param name="alignedFace">对齐人脸</param>
|
||||
|
/// <param nem="pRace">人种估计值,0 黑人 1 白人 2 黄人</param>
|
||||
|
/// <returns></returns>
|
||||
|
[DllImport(CloudWalkSDKDll, EntryPoint = "cwGetRaceEval", CallingConvention = CallingConvention.Cdecl)] |
||||
|
public static extern cw_errcode_t cwGetRaceEval(IntPtr pAttributeHandle, ref cw_aligned_face_t alignedFace, out int pRace, out float confidence); |
||||
|
|
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,360 @@ |
|||||
|
using System; |
||||
|
using System.Collections.Generic; |
||||
|
using System.Linq; |
||||
|
using System.Runtime.InteropServices; |
||||
|
using System.Text; |
||||
|
using System.Threading.Tasks; |
||||
|
|
||||
|
namespace DemoUI.SDK |
||||
|
{ |
||||
|
/// <summary>
|
||||
|
/// 检测功能开关选项
|
||||
|
/// </summary>
|
||||
|
public enum DetectTrackOperationType |
||||
|
{ |
||||
|
/// <summary>
|
||||
|
/// 进行人脸检测,并返回人脸矩形位置,默认开启
|
||||
|
/// </summary>
|
||||
|
CW_OP_DET = 0, |
||||
|
/// <summary>
|
||||
|
/// 进行人脸跟踪,并返回人脸跟踪的ID
|
||||
|
/// </summary>
|
||||
|
CW_OP_TRACK = 2, |
||||
|
/// <summary>
|
||||
|
/// 进行人脸关键点检测开关
|
||||
|
/// </summary>
|
||||
|
CW_OP_KEYPT = 4, |
||||
|
/// <summary>
|
||||
|
/// 进行人脸图像对齐,并返回对齐后的人脸图像,用来提取特征
|
||||
|
/// </summary>
|
||||
|
CW_OP_ALIGN = 8, |
||||
|
/// <summary>
|
||||
|
/// 人脸质量评估开关(质量分子项开关在配置文件中配置)
|
||||
|
/// </summary>
|
||||
|
CW_OP_QUALITY = 16, |
||||
|
/// <summary>
|
||||
|
/// (所有开关综合)总开关
|
||||
|
/// </summary>
|
||||
|
CW_OP_ALL = 30, |
||||
|
}; |
||||
|
|
||||
|
/// <summary>
|
||||
|
/// 通用错误码
|
||||
|
/// </summary>
|
||||
|
public enum cw_errcode_t |
||||
|
{ |
||||
|
CW_OK = 0, // 成功 or 合法
|
||||
|
|
||||
|
CW_UNKNOWN_ERR = 20000, // 未知错误
|
||||
|
CW_DETECT_INIT_ERR, // 初始化人脸检测器失败:如加载模型失败等
|
||||
|
CW_KEYPT_INIT_ERR, // 初始化关键点检测器失败:如加载模型失败等
|
||||
|
CW_QUALITY_INIT_ERR, // 初始化跟踪器失败:如加载模型失败等
|
||||
|
|
||||
|
CW_DET_ERR, // 检测失败
|
||||
|
CW_TRACK_ERR, // 跟踪失败
|
||||
|
CW_KEYPT_ERR, // 提取关键点失败
|
||||
|
CW_ALIGN_ERR, // 对齐人脸失败
|
||||
|
CW_QUALITY_ERR, // 质量评估失败
|
||||
|
|
||||
|
CW_EMPTY_FRAME_ERR, // 空图像
|
||||
|
CW_UNSUPPORT_FORMAT_ERR, // 图像格式不支持
|
||||
|
CW_ROI_ERR, // ROI设置失败
|
||||
|
CW_UNINITIALIZED_ERR, // 尚未初始化
|
||||
|
CW_MINMAX_ERR, // 最小最大人脸设置失败
|
||||
|
CW_OUTOF_RANGE_ERR, // 数据范围错误
|
||||
|
CW_UNAUTHORIZED_ERR, // 未授权
|
||||
|
CW_METHOD_UNAVAILABLE, // 方法无效
|
||||
|
CW_PARAM_INVALID, // 参数无效
|
||||
|
CW_BUFFER_EMPTY, // 缓冲区空
|
||||
|
|
||||
|
CW_FILE_UNAVAILABLE, // 文件不存在:如加载的模型不存在等.
|
||||
|
CW_DEVICE_UNAVAILABLE, // 设备不存在
|
||||
|
CW_DEVICE_ID_UNAVAILABLE, // 设备id不存在
|
||||
|
CW_EXCEEDMAXHANDLE_ERR, // 超过授权最大句柄数
|
||||
|
|
||||
|
CW_RECOG_FEATURE_MODEL_ERR, // 加载特征识别模型失败
|
||||
|
CW_RECOG_ALIGNEDFACE_ERR, // 对齐图片数据错误
|
||||
|
CW_RECOG_MALLOCMEMORY_ERR, // 预分配特征空间不足
|
||||
|
|
||||
|
CW_RECOG_FEATUREDATA_ERR, // 特征数据错误
|
||||
|
CW_RECOG_EXCEEDMAXFEASPEED, // 超过授权最大提特征速度
|
||||
|
CW_RECOG_EXCEEDMAXCOMSPEED, // 超过授权最大比对速度
|
||||
|
CW_RECOG_GROUPSIZE_ERR, // 特征比对特征数N超过最大授权数
|
||||
|
CW_RECOG_CONVERT_ERR, // 特征转换失败
|
||||
|
CW_RECOG_NOFACEDET, // 未检测到人脸
|
||||
|
|
||||
|
CW_LICENCE_JSON_CREATE_ERR, // Json操作失败
|
||||
|
CW_LICENCE_DECRYPT_ERR, // 加密失败
|
||||
|
CW_LICENCE_HTTP_ERROR, // HTTP失败
|
||||
|
CW_LICENCE_MALLOCMEMORY_ERR, // 授权内存分配不足
|
||||
|
CW_LICENCE_KEY_DEVICE_ERR, // 获取设备文件错误
|
||||
|
CW_LICENCE_KEY_LICENSE_ERR, // 获取授权文件错误
|
||||
|
CW_LICENCE_KEY_INSTALL_ERR, // 安装授权文件错误
|
||||
|
|
||||
|
CW_ATTRI_AGEGENDER_MODEL_ERR, //加载年龄性别模型失败
|
||||
|
CW_ATTRI_EVAL_AGE_ERR, //年龄识别失败
|
||||
|
CW_ATTRI_EVAL_GENDER_ERR, //性别识别失败
|
||||
|
CW_ATTRI_EVAL_RACE_ERR, //种族识别失败
|
||||
|
} |
||||
|
|
||||
|
/// <summary>
|
||||
|
/// 质量分检测错误码
|
||||
|
/// </summary>
|
||||
|
public enum cw_quality_errcode_t |
||||
|
{ |
||||
|
CW_QUALITY_OK = 0, // 质量分数据有效
|
||||
|
CW_QUALITY_NO_DATA = 20150, // 质量分数据无效,原因:尚未检测
|
||||
|
CW_QUALITY_ERROR_UNKNOWN, // 未知错误
|
||||
|
} |
||||
|
|
||||
|
/// <summary>
|
||||
|
/// 接口功能参数
|
||||
|
/// </summary>
|
||||
|
[StructLayoutAttribute(LayoutKind.Sequential)] |
||||
|
public struct cw_det_param_t |
||||
|
{ |
||||
|
public int roiX; // roi, 默认整帧图像0, 0, 0, 0 若设置为异常值检测阶段将恢复默认
|
||||
|
public int roiY; |
||||
|
public int roiWidth; |
||||
|
public int roiHeight; |
||||
|
|
||||
|
public int minSize; // 检测人脸尺寸范围: pc端默认[48,600];移动端默认[100,400]
|
||||
|
public int maxSize; |
||||
|
|
||||
|
public string pConfigFile; // 内部参数配置文件路径,此参数只能设置(set);从句柄内部获取出来的一律无效-------
|
||||
|
} |
||||
|
|
||||
|
/// <summary>
|
||||
|
/// 图像旋转角度(逆时针)
|
||||
|
/// </summary>
|
||||
|
public enum cw_img_angle_t |
||||
|
{ |
||||
|
CW_IMAGE_ANGLE_0 = 0, |
||||
|
CW_IMAGE_ANGLE_90, |
||||
|
CW_IMAGE_ANGLE_180, |
||||
|
CW_IMAGE_ANGLE_270 |
||||
|
} |
||||
|
|
||||
|
/// <summary>
|
||||
|
/// 图像镜像
|
||||
|
/// </summary>
|
||||
|
public enum cw_img_mirror_t |
||||
|
{ |
||||
|
CW_IMAGE_MIRROR_NONE = 0, // 不镜像
|
||||
|
CW_IMAGE_MIRROR_HOR, // 水平镜像
|
||||
|
CW_IMAGE_MIRROR_VER, // 垂直镜像
|
||||
|
CW_IMAGE_MIRROR_HV // 垂直和水平镜像
|
||||
|
} |
||||
|
|
||||
|
/// <summary>
|
||||
|
/// 图像格式
|
||||
|
/// </summary>
|
||||
|
public enum cw_img_form_t |
||||
|
{ |
||||
|
CW_IMAGE_GRAY8 = 0, |
||||
|
CW_IMAGE_BGR888, |
||||
|
CW_IMAGE_BGRA8888, |
||||
|
CW_IMAGE_RGB888, |
||||
|
CW_IMAGE_RGBA8888, |
||||
|
CW_IMAGE_YUV420P, |
||||
|
CW_IMAGE_YV12, |
||||
|
CW_IMAGE_NV12, |
||||
|
CW_IMAGE_NV21, |
||||
|
CW_IMAGE_BINARY, |
||||
|
} |
||||
|
|
||||
|
/*************** |
||||
|
* 关键点信息 |
||||
|
*/ |
||||
|
public struct cw_point |
||||
|
{ |
||||
|
public float keypoint_x; |
||||
|
public float keypoint_y; |
||||
|
} |
||||
|
|
||||
|
[StructLayoutAttribute(LayoutKind.Sequential)] |
||||
|
public struct cw_keypt |
||||
|
{ |
||||
|
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 68)] |
||||
|
public cw_point[] points; // 关键点
|
||||
|
public int nkeypt; // 关键点个数
|
||||
|
public float keyptScore; // 关键点得分,推荐阈值为0.7
|
||||
|
} |
||||
|
|
||||
|
/// <summary>
|
||||
|
/// 图像
|
||||
|
/// </summary>
|
||||
|
public struct cw_img_t |
||||
|
{ |
||||
|
public Int64 frameId; // 帧号
|
||||
|
public IntPtr data; // 图像数据(必须预分配足够的空间)
|
||||
|
public int dataLen; // 数据长度,CW_IMAGE_BINARY格式必须设置,其他格式可不设
|
||||
|
public int width; // 宽,CW_IMAGE_BINARY格式可不设,其他格式必须设置
|
||||
|
public int height; // 高,CW_IMAGE_BINARY格式可不设,其他格式必须设置
|
||||
|
public cw_img_form_t format; // 图像格式
|
||||
|
public cw_img_angle_t angle; // 旋转角度
|
||||
|
public cw_img_mirror_t mirror; // 镜像
|
||||
|
} |
||||
|
|
||||
|
/// <summary>
|
||||
|
/// 人脸框
|
||||
|
/// </summary>
|
||||
|
public struct cw_facepos_rect_t |
||||
|
{ |
||||
|
public int x; |
||||
|
public int y; |
||||
|
public int width; |
||||
|
public int height; |
||||
|
} |
||||
|
|
||||
|
/// <summary>
|
||||
|
/// 对齐人脸
|
||||
|
/// </summary>
|
||||
|
public struct cw_aligned_face_t |
||||
|
{ |
||||
|
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 128 * 128)] |
||||
|
public byte[] data; //图像数据,固定大小128 * 128
|
||||
|
public int width; //宽
|
||||
|
public int height; //高
|
||||
|
public int nChannels; //图像通道
|
||||
|
} |
||||
|
|
||||
|
/// <summary>
|
||||
|
/// 人脸质量分
|
||||
|
/// </summary>
|
||||
|
public struct cw_quality_t |
||||
|
{ |
||||
|
public cw_quality_errcode_t errcode; // 质量分析错误码
|
||||
|
|
||||
|
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 20)] |
||||
|
public float[] scores; |
||||
|
/* 质量分分数项,具体含义(根据数据下标顺序): |
||||
|
* 0 - 人脸质量总分,0.72 |
||||
|
* 1 - 清晰度,越大表示越清晰,推荐范围0.65-1.0(在启用第16个项mog分数的总分时,此分数为常数1.0,请忽略) |
||||
|
* 2 - 亮度,越大表示越亮,推荐范围0.2-0.8 |
||||
|
* 3 - 人脸角度,左转为正,右转为负 |
||||
|
* 4 - 人脸角度,抬头为正,低头为负 |
||||
|
* 5 - 人脸角度,顺时针为正,逆时针为负 |
||||
|
* 6 - 左右转程度,越大表示角度越正,推荐范围0.5-1.0 |
||||
|
* 7 - 抬低头程度,越大表示角度越正,推荐范围0.5-1.0 |
||||
|
* 8 - 肤色接近真人肤色程度,越大表示越真实,推荐范围0.5-1.0 |
||||
|
* 9 - 张嘴分数, 越大表示越可能张嘴,推荐范围0.0-0.5 |
||||
|
* 10 - 左眼睁眼分数, 越大表示左眼越可能是睁眼,推荐范围0.5-1.0 |
||||
|
* 11 - 右眼睁眼分数, 越大表示右眼越可能是睁眼,推荐范围0.5-1.0 |
||||
|
* 12 - 戴黑框眼镜置信度,越大表示戴黑框眼镜的可能性越大,推荐范围0.0-0.5 |
||||
|
* 13 - 戴墨镜的置信分,越大表示戴墨镜的可能性越大,推荐范围0.0-0.5 |
||||
|
* 14 - 左眼眼睛被遮挡的置信度,越大表示眼镜越可能被遮挡,目前只在睁眼分小于0.5时有意义,推荐范围0.0-0.5 |
||||
|
* 15 - 右眼眼睛被遮挡的置信度,越大表示眼镜越可能被遮挡,目前只在睁眼分小于0.5时有意义,推荐范围0.0-0.5 |
||||
|
* 16 - mog清晰度,返回0.0~1.0的分数,越大越清晰,阈值建议0.100001 |
||||
|
* 17 - 口罩分,0.0~1.0,越大表示越不可能带口罩,建议阈值0.44左右.(注意要用支持口罩检测的检测模型)*/ |
||||
|
} |
||||
|
|
||||
|
/// <summary>
|
||||
|
/// 人脸综合信息
|
||||
|
/// </summary>
|
||||
|
[StructLayoutAttribute(LayoutKind.Sequential)] |
||||
|
public struct cw_face_res_t |
||||
|
{ |
||||
|
public Int64 frameId; // 人脸所在帧号
|
||||
|
|
||||
|
public int detected; // 0: 跟踪到的人脸; 1: 检测到的人脸; 2:检测到但不会被进行后续计算(关键点)的人脸;
|
||||
|
// 3: 可能是静态误检框;4:大角度人脸; 5:关键点错误; 6:不需再处理的人脸(只有标记为1的人脸,关键点、
|
||||
|
// 对齐、质量分才有效;但除0之外其他都可能有口罩分)7:被估计为低质量人脸
|
||||
|
|
||||
|
public int trackId; // 人脸ID(ID<0表示没有进入跟踪)
|
||||
|
|
||||
|
public cw_facepos_rect_t faceRect; // 人脸框
|
||||
|
|
||||
|
public cw_keypt keypt; // 关键点
|
||||
|
|
||||
|
public cw_aligned_face_t faceAligned; // 对齐人脸
|
||||
|
|
||||
|
public cw_quality_t quality; // 人脸质量
|
||||
|
} |
||||
|
|
||||
|
public enum cw_recog_pattern_t |
||||
|
{ |
||||
|
CW_FEATURE_EXTRACT = 0, // 特征提取
|
||||
|
CW_RECOGNITION = 1 // 识 别
|
||||
|
} |
||||
|
|
||||
|
|
||||
|
[StructLayoutAttribute(LayoutKind.Sequential)] |
||||
|
public struct cwFaceAttr |
||||
|
{ |
||||
|
public int sex; |
||||
|
|
||||
|
public string age; |
||||
|
public string faceid; |
||||
|
|
||||
|
} |
||||
|
|
||||
|
//////////////////////////////////////////////////////////////////////////红外活体
|
||||
|
|
||||
|
/*************** |
||||
|
* 红外活体检测结果返回值 |
||||
|
*/ |
||||
|
public enum cw_nirliv_det_rst_t |
||||
|
{ |
||||
|
CW_NIR_LIV_DET_LIVE = 0, // 以阈值0.5判断为活体
|
||||
|
CW_NIR_LIV_DET_UNLIVE, // 以阈值0.5判断为非活体
|
||||
|
CW_NIR_LIV_DET_DIST_FAILED, // 人脸距离检测未通过
|
||||
|
CW_NIR_LIV_DET_SKIN_FAILED, // 人脸肤色检测未通过
|
||||
|
CW_NIR_LIV_DET_NO_PAIR_FACE, // 未匹配到人脸
|
||||
|
CW_NIR_LIV_DET_IS_INIT // 红外活体检测结果初始值
|
||||
|
} |
||||
|
|
||||
|
/*************** |
||||
|
* 红外活体检测错误码 |
||||
|
*/ |
||||
|
public enum cw_nirliveness_err_t |
||||
|
{ |
||||
|
CW_NIRLIV_OK = 0, // 成功返回
|
||||
|
CW_NIRLIV_ERR_CREATE_HANDLE = 26000, // 创建红外活体检测句柄失败
|
||||
|
CW_NIRLIV_ERR_FREE_HANDLE, // 释放红外活体检测句柄失败
|
||||
|
CW_NIRLIV_ERR_FACE_PAIR, // 人脸匹配初始化失败
|
||||
|
CW_NIRLIV_ERR_CREAT_LOG_DIR, // 创建日志路径失败
|
||||
|
CW_NIRLIV_ERR_MODEL_NOTEXIST, // 输入模型不存在
|
||||
|
CW_NIRLIV_ERR_MODEL_FAILED, // 输入模型初始化失败
|
||||
|
CW_NIRLIV_ERR_INPUT_UNINIT, // 输入未初始化
|
||||
|
CW_NIRLIV_ERR_NIR_NO_FACE, // 输入红外图片没有人脸
|
||||
|
CW_NIRLIV_ERR_VIS_NO_FACE, // 输入可见光图片没有人脸
|
||||
|
CW_NIRLIV_ERR_NO_PAIR_FACE, // 输入可见光和红外图片人脸未能匹配
|
||||
|
CW_NIRLIV_ERR_PUSH_DATA, // 输入数据失败
|
||||
|
CW_NIRLIV_ERR_NUM_LANDMARKS, // 输入可见光图片和红外图片关键点个数不等
|
||||
|
CW_NIRLIV_ERR_NO_LANDMARKS, // 输入红外图片没有人脸关键点
|
||||
|
CW_NIRLIV_ERR_INPUT_IMAGE, // 输入红外图片或者可见光图片不是多通道
|
||||
|
CW_NIRLIV_ERR_UNAUTHORIZED, // 没有license(未授权)
|
||||
|
CW_NIRLIV_ERR_FACE_NUM_ERR, // 未开启人脸匹配开关时,可见光或红外图像人脸大于1
|
||||
|
CW_NIRLIV_ERR_CAM_UNCW, // 非云从定制摄像头
|
||||
|
CW_NIRLIV_ERR_UNKNOWN, // 未知结果
|
||||
|
CW_NIRLIV_ERR_MAXHANDLE, // 超过最大红外活体最大授权句柄数
|
||||
|
CW_NIRLIV_ERR_NIRIMAGE, // 输入红外图片数据错误
|
||||
|
CW_NIRLIV_ERR_VISIMAGE, // 输入可见光图片数据错误
|
||||
|
} |
||||
|
|
||||
|
/*************** |
||||
|
* 红外活体检测结果 |
||||
|
*/ |
||||
|
public struct cw_nirliv_res_t |
||||
|
{ |
||||
|
public cw_nirliv_det_rst_t livRst; // 输出红外活体检测结果返回值
|
||||
|
public float score; // 输出红外活体检测得分,非活体的时候为0
|
||||
|
} |
||||
|
|
||||
|
public class FaceDataModel |
||||
|
{ |
||||
|
public string GenderMale { get; set; } |
||||
|
|
||||
|
public string Age { get; set; } |
||||
|
|
||||
|
public int StopTime { get; set; } |
||||
|
|
||||
|
public DateTime BeginTime { get; set; } |
||||
|
|
||||
|
public DateTime EndTime { get; set; } |
||||
|
|
||||
|
public string IP { get; set; } |
||||
|
} |
||||
|
|
||||
|
} |
||||
@ -0,0 +1,78 @@ |
|||||
|
using System.Collections.Generic; |
||||
|
using System.Runtime.InteropServices; |
||||
|
using System.Text; |
||||
|
using System; |
||||
|
|
||||
|
namespace DemoUI.SDK |
||||
|
{ |
||||
|
/// <summary>
|
||||
|
/// 人脸检测
|
||||
|
/// </summary>
|
||||
|
public class NativeCWFaceDetection |
||||
|
{ |
||||
|
private const string CloudWalkSDKDll = "CWFaceSDK.dll"; |
||||
|
|
||||
|
/// <summary>
|
||||
|
/// 创建检测器句柄
|
||||
|
/// </summary>
|
||||
|
/// <param name="pConfigFile">模型参数配置文件</param>
|
||||
|
/// <param name="pLicence">授权码(仅用于安卓平台,PC端传空即可)</param>
|
||||
|
/// <returns>如果创建成功,返回detector句柄,否则返回空</returns>
|
||||
|
[DllImport(CloudWalkSDKDll, EntryPoint = "cwCreateDetHandle", CallingConvention = CallingConvention.Cdecl)] |
||||
|
public static extern IntPtr cwCreateDetHandle(out cw_errcode_t errCode, string pConfigFile, string pLicence); |
||||
|
|
||||
|
|
||||
|
/// <summary>
|
||||
|
/// 释放创建的检测器
|
||||
|
/// </summary>
|
||||
|
/// <param name="pDetector"></param>
|
||||
|
[DllImport(CloudWalkSDKDll, EntryPoint = "cwReleaseDetHandle", CallingConvention = CallingConvention.Cdecl)] |
||||
|
public static extern void cwReleaseDetHandle(IntPtr pDetector); |
||||
|
|
||||
|
|
||||
|
/// <summary>
|
||||
|
/// 获取检测器参数
|
||||
|
/// </summary>
|
||||
|
/// <param name="pDetector"></param>
|
||||
|
/// <param name="param"></param>
|
||||
|
/// <returns></returns>
|
||||
|
[DllImport(CloudWalkSDKDll, EntryPoint = "cwGetFaceParam", CallingConvention = CallingConvention.Cdecl)] |
||||
|
public static extern cw_errcode_t cwGetFaceParam(IntPtr pDetector, out cw_det_param_t param); |
||||
|
|
||||
|
|
||||
|
/// <summary>
|
||||
|
/// 设置检测器参数(必须先调用cwGetFaceParam再使用此函数)
|
||||
|
/// </summary>
|
||||
|
/// <param name="pDetector"></param>
|
||||
|
/// <param name="param"></param>
|
||||
|
/// <returns></returns>
|
||||
|
[DllImport(CloudWalkSDKDll, EntryPoint = "cwSetFaceParam", CallingConvention = CallingConvention.Cdecl)] |
||||
|
public static extern cw_errcode_t cwSetFaceParam(IntPtr pDetector, ref cw_det_param_t param); |
||||
|
|
||||
|
|
||||
|
|
||||
|
|
||||
|
/// <summary>
|
||||
|
/// 人脸检测跟踪接口
|
||||
|
/// </summary>
|
||||
|
/// <param name="pDetector"></param>
|
||||
|
/// <param name="pFrameImg">被检测图像. 如果传入的数据只有bgr,则nImageChannel 固定为3,如果pimageData为其他格式,则还应有一个参数来表示图像格式</param>
|
||||
|
/// <param name="pFaceBuffer">检测到的人脸,该缓冲区初始化必须足够大</param>
|
||||
|
/// <param name="iBuffLen">最大检测到人脸个数,主要定义了pFaceBuffer的初始化大小;如果实际人脸个数多于此值则只能返回nMaxFaceNumber个人脸.</param>
|
||||
|
/// <param name="nFaceNum">实际检测到的人脸个数</param>
|
||||
|
/// <param name="iOp">人脸检测接口可以进行的操作(POS是默认操作,其他项可选;返回结果和操作选项是对应的),具体参考DET_OP定义.</param>
|
||||
|
/// <returns></returns>
|
||||
|
[DllImport(CloudWalkSDKDll, EntryPoint = "cwFaceDetection", CallingConvention = CallingConvention.Cdecl)] |
||||
|
public static extern cw_errcode_t cwFaceDetection(IntPtr pDetector, ref cw_img_t pFrameImg, IntPtr pFaceBuffer, int iBuffLen, ref int nFaceNum, int iOp); |
||||
|
|
||||
|
|
||||
|
/// <summary>
|
||||
|
/// 清除检测跟踪状态信息函数
|
||||
|
/// </summary>
|
||||
|
/// <param name="pDetector">检测器句柄</param>
|
||||
|
/// <returns>成功返回CW_OK,失败返回其他</returns>
|
||||
|
[DllImport(CloudWalkSDKDll, EntryPoint = "cwResetDetTrackState", CallingConvention = CallingConvention.Cdecl)] |
||||
|
public static extern cw_errcode_t cwResetDetTrackState(IntPtr pDetector); |
||||
|
|
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,49 @@ |
|||||
|
using System.Collections.Generic; |
||||
|
using System.Runtime.InteropServices; |
||||
|
using System.Text; |
||||
|
using System; |
||||
|
|
||||
|
namespace DemoUI.SDK |
||||
|
{ |
||||
|
/// <summary>
|
||||
|
/// 人脸检测
|
||||
|
/// </summary>
|
||||
|
public class CWFaceNisLiveness |
||||
|
{ |
||||
|
private const string CloudWalkSDKDll = "CWFaceSDK.dll"; |
||||
|
|
||||
|
/// <summary>
|
||||
|
/// 创建活体检测句柄
|
||||
|
/// </summary>
|
||||
|
/// <param name="pNirModelPath">红外活体检测器模型文件</param>
|
||||
|
/// <param name="pRecogModelPath">红外活体识别比对模型文件</param>
|
||||
|
/// <param name="pPairFilePath">匹配文件路径</param>
|
||||
|
/// <param name="skinThresh">肤色阈值(根据不同的前端版本设置)</param>
|
||||
|
/// <param name="pLicence">授权码
|
||||
|
/// <returns>如果创建成功,返回Attribute句柄,否则返回空</returns>
|
||||
|
[DllImport(CloudWalkSDKDll, EntryPoint = "cwCreateNirLivenessHandle", CallingConvention = CallingConvention.Cdecl)] |
||||
|
public static extern IntPtr cwCreateNirLivenessHandle(out cw_nirliveness_err_t errCode, string pNirModelPath, string pRecogModelPath, string pPairFilePath, string pLogPath, float skinThresh, string pLicence); |
||||
|
|
||||
|
|
||||
|
/// <summary>
|
||||
|
/// 释放活体检测句柄
|
||||
|
/// </summary>
|
||||
|
/// <param name="pHandle">红外活体句柄</param>
|
||||
|
[DllImport(CloudWalkSDKDll, EntryPoint = "cwReleaseNirLivenessHandle", CallingConvention = CallingConvention.Cdecl)] |
||||
|
public static extern void cwReleaseNirLivenessHandle(IntPtr pHandle); |
||||
|
|
||||
|
|
||||
|
/// <summary>
|
||||
|
/// 红外活体检测接口
|
||||
|
/// </summary>
|
||||
|
/// <param name="pDetector">人脸检测句柄</param>
|
||||
|
/// <param name="pNirHandle">红外活体句柄</param>
|
||||
|
/// <param name="pImgVis">输入可见光图片数据</param>
|
||||
|
/// <param name="pImgNir">输入红外光图片数据</param>
|
||||
|
/// <param name="pNirLivRes">存放红外活体检测结果,需事先分配内存</param>
|
||||
|
/// <returns></returns>
|
||||
|
[DllImport(CloudWalkSDKDll, EntryPoint = "cwFaceNirByImageData", CallingConvention = CallingConvention.Cdecl)] |
||||
|
public static extern cw_nirliveness_err_t cwFaceNirByImageData(IntPtr pDetector, IntPtr pNirHandle, ref cw_img_t pImgVis, ref cw_img_t pImgNir, out cw_nirliv_res_t pNirLivRes); |
||||
|
|
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,84 @@ |
|||||
|
using System; |
||||
|
using System.Collections.Generic; |
||||
|
using System.Linq; |
||||
|
using System.Runtime.InteropServices; |
||||
|
using System.Text; |
||||
|
using System.Threading.Tasks; |
||||
|
|
||||
|
namespace DemoUI.SDK |
||||
|
{ |
||||
|
/// <summary>
|
||||
|
///
|
||||
|
/// </summary>
|
||||
|
public class NativeCWFaceRecognition |
||||
|
{ |
||||
|
private const string CloudWalkSDKDll = "CWFaceSDK.dll"; |
||||
|
|
||||
|
/// <summary>
|
||||
|
///功能:创建识别句柄
|
||||
|
/// </summary>
|
||||
|
/// <param name="pRecogHandle">创建的识别句柄</param>
|
||||
|
/// <param name="configure_path">配置文件路径</param>
|
||||
|
/// <param name="recog_pattern">创建的句柄类型</param>
|
||||
|
/// <returns></returns>
|
||||
|
[DllImport(CloudWalkSDKDll, EntryPoint = "cwCreateRecogHandle", CallingConvention = CallingConvention.Cdecl)] |
||||
|
public static extern IntPtr cwCreateRecogHandle(out cw_errcode_t errCode, string pConfigurePath, string pLicence, cw_recog_pattern_t emRecogPattern); |
||||
|
|
||||
|
|
||||
|
/// <summary>
|
||||
|
/// 释放通道
|
||||
|
/// </summary>
|
||||
|
/// <param name="pRecogHandle">识别句柄</param>
|
||||
|
/// <returns></returns>
|
||||
|
[DllImport(CloudWalkSDKDll, EntryPoint = "cwReleaseRecogHandle", CallingConvention = CallingConvention.Cdecl)] |
||||
|
public static extern void cwReleaseRecogHandle(IntPtr pRecogHandle); |
||||
|
|
||||
|
|
||||
|
/// <summary>
|
||||
|
/// 功能:获取特征值长度
|
||||
|
/// </summary>
|
||||
|
/// <param name="pRecogHandle">识别句柄</param>
|
||||
|
/// <returns></returns>
|
||||
|
[DllImport(CloudWalkSDKDll, EntryPoint = "cwGetFeatureLength", CallingConvention = CallingConvention.Cdecl)] |
||||
|
public static extern int cwGetFeatureLength(IntPtr pRecogHandle); |
||||
|
|
||||
|
|
||||
|
/// <summary>
|
||||
|
/// 功能:提取人脸特征值
|
||||
|
/// </summary>
|
||||
|
/// <param name="pRecogHandle">识别句柄</param>
|
||||
|
/// <param name="alignedFace">对齐人脸数据指针</param>
|
||||
|
/// <param name="featueData">返回的特征数,需要预先分配足够空间</param>
|
||||
|
/// <returns></returns>
|
||||
|
[DllImport(CloudWalkSDKDll, EntryPoint = "cwGetFaceFeature", CallingConvention = CallingConvention.Cdecl)] |
||||
|
public static extern cw_errcode_t cwGetFaceFeature(IntPtr pRecogHandle, ref cw_aligned_face_t alignedFace, byte[] featueData); |
||||
|
|
||||
|
|
||||
|
|
||||
|
/// <summary>
|
||||
|
/// 功能:计算2个特征与N个特征的相似度,返回的相似度scores的个数为N个
|
||||
|
/// </summary>
|
||||
|
/// <param name="pRecogHandle">识别句柄</param>
|
||||
|
/// <param name="pFea1">特征1,只能是一个特征</param>
|
||||
|
/// <param name="pFea2">特征2,可以是N个特征</param>
|
||||
|
/// <param name="pFea2Num">特征2的个数</param>
|
||||
|
/// <param name="scores">返回的相似度分数数组,长度为Fea2num,需要预先分配空间 </param>
|
||||
|
/// <returns></returns>
|
||||
|
[DllImport(CloudWalkSDKDll, EntryPoint = "cwComputeMatchScore", CallingConvention = CallingConvention.Cdecl)] |
||||
|
public static extern cw_errcode_t cwComputeMatchScore(IntPtr pRecogHandle, byte[] pFea1, byte[] pFea2, int Fea2Num, float[] scores); |
||||
|
|
||||
|
|
||||
|
/// <summary>
|
||||
|
/// 功能:比对两个人脸图片中最大人脸特征,获取相似度
|
||||
|
/// </summary>
|
||||
|
/// <param name="pDetector">检测句柄</param>
|
||||
|
/// <param name="pRecogHandle">识别句柄</param>
|
||||
|
/// <param name="pFrameImg1">图片1数据</param>
|
||||
|
/// <param name="pFrameImg2">图片2数据</param>
|
||||
|
/// <param name="scores">比对分数</param>
|
||||
|
/// <returns></returns>
|
||||
|
[DllImport(CloudWalkSDKDll, EntryPoint = "cwVerifyImageData", CallingConvention = CallingConvention.Cdecl)] |
||||
|
public static extern cw_errcode_t cwVerifyImageData(IntPtr pDetector, IntPtr pRecogHandle, cw_img_t[] pFrameImg1, cw_img_t[] pFrameImg2, float[] scores); |
||||
|
|
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,47 @@ |
|||||
|
using System.Collections.Generic; |
||||
|
using System.Runtime.InteropServices; |
||||
|
using System.Text; |
||||
|
using System; |
||||
|
|
||||
|
namespace DemoUI.SDK |
||||
|
{ |
||||
|
/// <summary>
|
||||
|
/// 人脸检测
|
||||
|
/// </summary>
|
||||
|
public class NativeCWFaceVersion |
||||
|
{ |
||||
|
private const string CloudWalkSDKDll = "CWFaceSDK.dll"; |
||||
|
|
||||
|
/// <summary>
|
||||
|
/// 功能:获取SDK版本信息
|
||||
|
/// </summary>
|
||||
|
/// <param name="pVersion">版本信息,需事先分配内存</param>
|
||||
|
/// <param name="iBuffLen">输出buf分配字节长度</param>>
|
||||
|
/// <returns>成功返回CW_OK,失败返回其他</returns>
|
||||
|
[DllImport(CloudWalkSDKDll, EntryPoint = "cwGetSDKVersion", CallingConvention = CallingConvention.Cdecl)] |
||||
|
public static extern cw_errcode_t cwGetSDKVersion(StringBuilder pVersion, int iBuffLen); |
||||
|
|
||||
|
|
||||
|
/// <summary>
|
||||
|
/// 功能:获取设备码
|
||||
|
/// </summary>
|
||||
|
/// <param name="pDeviceInfo">设备唯一码,需事先分配内存,不低于160字节</param>
|
||||
|
/// <param name="iBuffLen">输出buf分配字节长度,不低于160字节</param>
|
||||
|
/// <param name="iUseLen">输出的设备码的长度</param>
|
||||
|
/// <returns>成功返回CW_OK,失败返回其他</returns>
|
||||
|
[DllImport(CloudWalkSDKDll, EntryPoint = "cwGetDeviceInfo", CallingConvention = CallingConvention.Cdecl)] |
||||
|
public static extern cw_errcode_t cwGetDeviceInfo(StringBuilder pDeviceInfo, int iBuffLen, ref int iUseLen); |
||||
|
|
||||
|
|
||||
|
|
||||
|
/// <summary>
|
||||
|
/// 功能:安装授权
|
||||
|
/// </summary>
|
||||
|
/// <param name="sAppKey">授权AppKey,需从云从科技获取</param>
|
||||
|
/// <param name="sProductId">授权ProductId,需从云从科技获取</param>
|
||||
|
/// <param name="sAppSecret">授权sAppSecret,需从云从科技获取</param>
|
||||
|
/// <returns>授权并发数</returns>
|
||||
|
[DllImport(CloudWalkSDKDll, EntryPoint = "cwInstallLicence", CallingConvention = CallingConvention.Cdecl)] |
||||
|
public static extern cw_errcode_t cwInstallLicence(string sAppKey, string sAppSecret, string sProductId); |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,235 @@ |
|||||
|
<Window x:Class="DemoUI.Window1" |
||||
|
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" |
||||
|
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" |
||||
|
xmlns:wf="clr-namespace:System.Windows.Forms;assembly=System.Windows.Forms" |
||||
|
Title="DemoCSharp" Height="800" Width="980" WindowStartupLocation="CenterScreen" Closed="Window_Closed"> |
||||
|
<Grid> |
||||
|
<Grid.ColumnDefinitions> |
||||
|
<ColumnDefinition Width="60*"/> |
||||
|
<ColumnDefinition Width="100*"/> |
||||
|
</Grid.ColumnDefinitions> |
||||
|
<Grid Grid.Column="0"> |
||||
|
<Grid.RowDefinitions> |
||||
|
<RowDefinition Height="340*"/> |
||||
|
<RowDefinition Height="340*"/> |
||||
|
<RowDefinition Height="170*"/> |
||||
|
<RowDefinition Height="170*"/> |
||||
|
</Grid.RowDefinitions> |
||||
|
|
||||
|
|
||||
|
<Grid Grid.Row="0" Margin="0,0,0,38"> |
||||
|
<Grid.ColumnDefinitions> |
||||
|
|
||||
|
<ColumnDefinition Width="360*"/> |
||||
|
<ColumnDefinition Width="10*"/> |
||||
|
</Grid.ColumnDefinitions> |
||||
|
<Border Grid.Column="0" Background="Black" Width="300" Height="300"> |
||||
|
<Image Name="video1" Stretch="Fill" VerticalAlignment="Top" HorizontalAlignment="Left"/> |
||||
|
</Border> |
||||
|
</Grid> |
||||
|
<Grid Grid.Row="1" Margin="0,0,0,38"> |
||||
|
<Grid.ColumnDefinitions> |
||||
|
|
||||
|
<ColumnDefinition Width="360*"/> |
||||
|
<ColumnDefinition Width="10*"/> |
||||
|
</Grid.ColumnDefinitions> |
||||
|
<Border Grid.Column="0" Background="Black" Width="300" Height="300"> |
||||
|
<Image Name="video2" Stretch="Fill" VerticalAlignment="Top" HorizontalAlignment="Left"/> |
||||
|
</Border> |
||||
|
</Grid> |
||||
|
<TextBlock Grid.Row="2" Text="" x:Name="txtFace" FontSize="18" VerticalAlignment="Center" HorizontalAlignment="Left"/> |
||||
|
<TextBlock Grid.Row="3" Text="" x:Name="txtFaceLive" FontSize="18" VerticalAlignment="Center" HorizontalAlignment="Left"/> |
||||
|
</Grid> |
||||
|
<Grid Grid.Column="1"> |
||||
|
<Grid.RowDefinitions> |
||||
|
<RowDefinition Height="35*"/> |
||||
|
<RowDefinition Height="9*"/> |
||||
|
<RowDefinition Height="340*"/> |
||||
|
<RowDefinition Height="0*"/> |
||||
|
<RowDefinition Height="170*"/> |
||||
|
<RowDefinition Height="170*"/> |
||||
|
</Grid.RowDefinitions> |
||||
|
<Grid Grid.Row="0"> |
||||
|
<Grid.ColumnDefinitions> |
||||
|
<ColumnDefinition Width="5*"/> |
||||
|
<ColumnDefinition Width="50*"/> |
||||
|
<ColumnDefinition Width="20*"/> |
||||
|
<ColumnDefinition Width="46*"/> |
||||
|
<ColumnDefinition Width="2*"/> |
||||
|
<ColumnDefinition Width="150*"/> |
||||
|
<ColumnDefinition Width="5*"/> |
||||
|
</Grid.ColumnDefinitions> |
||||
|
<Button Grid.Column="1" Click="OnBtnInit" Margin="0,6,0,2" Background="Green"> |
||||
|
<TextBlock Text="初始化" FontSize="18" Foreground="White"/> |
||||
|
</Button> |
||||
|
<TextBlock Grid.Column="3" Text="SDK版本号:" FontSize="16" Foreground="Blue" VerticalAlignment="Center" HorizontalAlignment="Center"/> |
||||
|
<TextBlock Grid.Column="5" x:Name="tbSDKVersion" FontSize="16" Foreground="Blue" VerticalAlignment="Center" HorizontalAlignment="Right"/> |
||||
|
</Grid> |
||||
|
<Grid Grid.Row="2" Margin="0,0,0,38"> |
||||
|
<Grid.ColumnDefinitions> |
||||
|
<ColumnDefinition Width="3*"/> |
||||
|
<ColumnDefinition Width="360*"/> |
||||
|
<ColumnDefinition Width="3*"/> |
||||
|
<ColumnDefinition Width="150*"/> |
||||
|
<ColumnDefinition Width="3*"/> |
||||
|
<ColumnDefinition Width="150*"/> |
||||
|
<ColumnDefinition Width="3*"/> |
||||
|
</Grid.ColumnDefinitions> |
||||
|
<Border Grid.Column="1" Background="Black"> |
||||
|
<Image Name="video" Stretch="Fill" VerticalAlignment="Top" HorizontalAlignment="Left"/> |
||||
|
</Border> |
||||
|
<Grid Grid.Column="3"> |
||||
|
<Grid.RowDefinitions> |
||||
|
<RowDefinition Height="5*"/> |
||||
|
<RowDefinition Height="25*"/> |
||||
|
<RowDefinition Height="25*"/> |
||||
|
<RowDefinition Height="5*"/> |
||||
|
</Grid.RowDefinitions> |
||||
|
<Button Grid.Row="0" Margin="10,0,10,0" Background="Blue" Click="OnBtnOpenUsb"> |
||||
|
<TextBlock Text="开启摄像头" FontSize="16" Foreground="White"/> |
||||
|
</Button> |
||||
|
<Grid Grid.Row="1"> |
||||
|
<Grid.ColumnDefinitions> |
||||
|
<ColumnDefinition Width="200*"/> |
||||
|
<ColumnDefinition Width="150*"/> |
||||
|
</Grid.ColumnDefinitions> |
||||
|
<Border x:Name="Bd_Pic1" Margin="0,13,0,5" BorderThickness="2" BorderBrush="Gray"/> |
||||
|
<Grid Grid.Column="1"> |
||||
|
<Grid.RowDefinitions> |
||||
|
<RowDefinition Height="1*"/> |
||||
|
<RowDefinition Height="1*"/> |
||||
|
<RowDefinition Height="1*"/> |
||||
|
<RowDefinition Height="1*"/> |
||||
|
<RowDefinition Height="1*"/> |
||||
|
</Grid.RowDefinitions> |
||||
|
<Button Grid.Row="1" Margin="6,0,0,0" Click="OnBtnCamera1" Background="Green"> |
||||
|
<TextBlock Text="拍照" FontSize="16" Foreground="White"/> |
||||
|
</Button> |
||||
|
<Button Grid.Row="3" Margin="6,0,0,0" Click="OnBtnLoad1" Background="Green"> |
||||
|
<TextBlock Text="导入" FontSize="16" Foreground="White"/> |
||||
|
</Button> |
||||
|
</Grid> |
||||
|
</Grid> |
||||
|
<Grid Grid.Row="2"> |
||||
|
<Grid.ColumnDefinitions> |
||||
|
<ColumnDefinition Width="200*"/> |
||||
|
<ColumnDefinition Width="150*"/> |
||||
|
</Grid.ColumnDefinitions> |
||||
|
<Border Grid.Column="0" x:Name="Bd_Pic2" Margin="0,5,0,10" BorderThickness="2" BorderBrush="Gray"/> |
||||
|
<Grid Grid.Column="1"> |
||||
|
<Grid.RowDefinitions> |
||||
|
<RowDefinition Height="1*"/> |
||||
|
<RowDefinition Height="1*"/> |
||||
|
<RowDefinition Height="1*"/> |
||||
|
<RowDefinition Height="1*"/> |
||||
|
<RowDefinition Height="1*"/> |
||||
|
</Grid.RowDefinitions> |
||||
|
<Button Grid.Row="1" Margin="6,0,0,0" Click="OnBtnCamera2" Background="Green"> |
||||
|
<TextBlock Text="拍照" FontSize="16" Foreground="White"/> |
||||
|
</Button> |
||||
|
<Button Grid.Row="3" Margin="6,0,0,0" Click="OnBtnLoad2" Background="Green"> |
||||
|
<TextBlock Text="导入" FontSize="16" Foreground="White"/> |
||||
|
</Button> |
||||
|
</Grid> |
||||
|
</Grid> |
||||
|
<Grid Grid.Row="3"> |
||||
|
<Grid.ColumnDefinitions> |
||||
|
<ColumnDefinition Width="30*"/> |
||||
|
<ColumnDefinition Width="10"/> |
||||
|
<ColumnDefinition Width="30*"/> |
||||
|
</Grid.ColumnDefinitions> |
||||
|
<!--<Button Grid.Column="0" Margin="0,0,0,0" Background="Blue" Click="OnBtnVerify" VerticalAlignment="Center"> |
||||
|
<TextBlock Text="人脸比对" FontSize="13" Foreground="White" Height="26"/> |
||||
|
</Button>--> |
||||
|
<Button Grid.Column="0" Margin="0,0,0,0" Background="Blue" Click="OnBtnOpenNirLiveness" VerticalAlignment="Center"> |
||||
|
<TextBlock Text="开启活体检测" FontSize="13" Foreground="White" Height="26" x:Name="txtOpenLive"/> |
||||
|
</Button> |
||||
|
<Button Grid.Column="2" Margin="0,0,0,0" Background="Blue" Click="OnBtnNirLiveness" VerticalAlignment="Center"> |
||||
|
<TextBlock Text="红外活体" FontSize="13" Foreground="White" Height="26"/> |
||||
|
</Button> |
||||
|
</Grid> |
||||
|
</Grid> |
||||
|
<Grid Grid.Column="5"> |
||||
|
<Grid.RowDefinitions> |
||||
|
<RowDefinition Height="25*"/> |
||||
|
<RowDefinition Height="5*"/> |
||||
|
</Grid.RowDefinitions> |
||||
|
<Grid Grid.Row="0"> |
||||
|
<Border x:Name="Bd_Attri_Pic" Margin="0,25,0,0" BorderThickness="2" BorderBrush="Gray"/> |
||||
|
</Grid> |
||||
|
<Grid Grid.Row="1"> |
||||
|
<Grid.ColumnDefinitions> |
||||
|
<ColumnDefinition Width="2*"/> |
||||
|
<ColumnDefinition Width="50*"/> |
||||
|
<ColumnDefinition Width="10*"/> |
||||
|
<ColumnDefinition Width="50*"/> |
||||
|
<ColumnDefinition Width="2*"/> |
||||
|
</Grid.ColumnDefinitions> |
||||
|
<Grid Grid.Column="1"> |
||||
|
<Button Grid.Column="1" Margin="6,10,10,10" Click="OnBtnLoad" Background="Green"> |
||||
|
<TextBlock Text="导入" FontSize="18" Foreground="White"/> |
||||
|
</Button> |
||||
|
</Grid> |
||||
|
<Grid Grid.Column="3"> |
||||
|
<Button Grid.Column="1" Margin="2,10,10,10" Click="OnBtnAttribute" Background="Green"> |
||||
|
<TextBlock Text="属性" FontSize="18" Foreground="White"/> |
||||
|
</Button> |
||||
|
</Grid> |
||||
|
</Grid> |
||||
|
</Grid> |
||||
|
</Grid> |
||||
|
<Grid Grid.Row="4" Margin="10,10,0,10" Width="600"> |
||||
|
<Grid.ColumnDefinitions> |
||||
|
<ColumnDefinition Width="200*"/> |
||||
|
<ColumnDefinition Width="10*"/> |
||||
|
<ColumnDefinition Width="200*"/> |
||||
|
</Grid.ColumnDefinitions> |
||||
|
<Grid Grid.Column="0"> |
||||
|
<Grid.ColumnDefinitions> |
||||
|
<ColumnDefinition Width="50*"/> |
||||
|
<ColumnDefinition Width="260*"/> |
||||
|
</Grid.ColumnDefinitions> |
||||
|
<Grid.RowDefinitions> |
||||
|
<RowDefinition Height="1*"/> |
||||
|
<RowDefinition Height="1*"/> |
||||
|
<RowDefinition Height="1*"/> |
||||
|
</Grid.RowDefinitions> |
||||
|
<TextBlock Grid.Row="0" Grid.Column="0" Text="分数: " FontSize="18" VerticalAlignment="Center" HorizontalAlignment="Left"/> |
||||
|
<TextBlock Grid.Row="1" Grid.Column="0" Text="结果: " FontSize="18" VerticalAlignment="Center" HorizontalAlignment="Left"/> |
||||
|
<TextBlock Grid.Row="2" Grid.Column="0" Text="时间: " FontSize="18" VerticalAlignment="Center" HorizontalAlignment="Left"/> |
||||
|
<TextBlock Grid.Row="0" Grid.Column="1" x:Name="Tb_Score" FontSize="18" VerticalAlignment="Center" HorizontalAlignment="Left"/> |
||||
|
<TextBlock Grid.Row="1" Grid.Column="1" x:Name="Tb_Result" FontSize="15" VerticalAlignment="Center" HorizontalAlignment="Left"/> |
||||
|
<TextBlock Grid.Row="2" Grid.Column="1" x:Name="Tb_Time" FontSize="18" VerticalAlignment="Center" HorizontalAlignment="Left"/> |
||||
|
</Grid> |
||||
|
<Grid Grid.Column="2"> |
||||
|
<Grid.RowDefinitions> |
||||
|
<RowDefinition/> |
||||
|
<RowDefinition/> |
||||
|
<RowDefinition /> |
||||
|
<RowDefinition/> |
||||
|
</Grid.RowDefinitions> |
||||
|
<Grid.ColumnDefinitions> |
||||
|
<ColumnDefinition Width="80*"/> |
||||
|
<ColumnDefinition Width="80*"/> |
||||
|
<ColumnDefinition Width="80*"/> |
||||
|
</Grid.ColumnDefinitions> |
||||
|
<TextBlock Grid.Row="0" Grid.Column="0" Text=" " FontSize="20" VerticalAlignment="Center" HorizontalAlignment="Left"/> |
||||
|
<TextBlock Grid.Row="1" Grid.Column="0" Text="年龄估计 " FontSize="18" VerticalAlignment="Center" HorizontalAlignment="Center"/> |
||||
|
<TextBlock Grid.Row="2" Grid.Column="0" Text="性别估计 " FontSize="18" VerticalAlignment="Center" HorizontalAlignment="Center"/> |
||||
|
<TextBlock Grid.Row="3" Grid.Column="0" Text="人种估计 " FontSize="18" VerticalAlignment="Center" HorizontalAlignment="Center"/> |
||||
|
|
||||
|
<TextBlock Grid.Row="0" Grid.Column="1" Text="属性" FontSize="18" VerticalAlignment="Center" HorizontalAlignment="Center"/> |
||||
|
<TextBlock Grid.Row="0" Grid.Column="2" Text="置信分数" FontSize="18" VerticalAlignment="Center" HorizontalAlignment="Center" /> |
||||
|
|
||||
|
<TextBlock Grid.Row="1" Grid.Column="1" x:Name="Attr_Age" FontSize="18" VerticalAlignment="Center" HorizontalAlignment="Center"/> |
||||
|
<TextBlock Grid.Row="2" Grid.Column="1" x:Name="Attr_Gender" FontSize="18" VerticalAlignment="Center" HorizontalAlignment="Center"/> |
||||
|
<TextBlock Grid.Row="3" Grid.Column="1" x:Name="Attr_Race" FontSize="18" VerticalAlignment="Center" HorizontalAlignment="Center"/> |
||||
|
|
||||
|
<TextBlock Grid.Row="1" Grid.Column="2" x:Name="Conf_Age" FontSize="18" VerticalAlignment="Center" HorizontalAlignment="Center" /> |
||||
|
<TextBlock Grid.Row="2" Grid.Column="2" x:Name="Conf_Gender" FontSize="18" VerticalAlignment="Center" HorizontalAlignment="Center" /> |
||||
|
<TextBlock Grid.Row="3" Grid.Column="2" x:Name="Conf_Race" FontSize="18" VerticalAlignment="Center" HorizontalAlignment="Center"/> |
||||
|
</Grid> |
||||
|
</Grid> |
||||
|
</Grid> |
||||
|
</Grid> |
||||
|
</Window> |
||||
File diff suppressed because it is too large
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -0,0 +1,6 @@ |
|||||
|
<?xml version="1.0" encoding="utf-8"?> |
||||
|
<packages> |
||||
|
<package id="Fleck" version="1.1.0" targetFramework="net40" requireReinstallation="true" /> |
||||
|
<package id="Newtonsoft.Json" version="12.0.2" targetFramework="net40" requireReinstallation="true" /> |
||||
|
<package id="System.Net.WebSockets" version="4.3.0" targetFramework="net46" /> |
||||
|
</packages> |
||||
@ -0,0 +1,4 @@ |
|||||
|
1. 建议采取Release配置编译该Demo,因SDK只提供Release版本。 |
||||
|
2. 该Demo使用第三方库emgu,主要用于视频解码,使用时需要将“cvextern.dll”拷贝到运行程序目录。如果编译32位SDK,拷贝“Demo_CSharp/emgu/x86”中的库,如果编译64位SDK,拷贝“Demo_CSharp/emgu/x64”中的库。 |
||||
|
3. SDK算法由VS2012开发,建议客户采取VS2012进行开发。如果无法采用VS2012,也需要安装vc2012运行库。 |
||||
|
4. emgu库“cvextern.dll依赖vc2013,需要安装vc2013运行库。 |
||||
@ -0,0 +1,6 @@ |
|||||
|
<?xml version="1.0" encoding="UTF-8"?> |
||||
|
<classpath> |
||||
|
<classpathentry kind="src" path="src"/> |
||||
|
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8"/> |
||||
|
<classpathentry kind="output" path="bin"/> |
||||
|
</classpath> |
||||
@ -0,0 +1 @@ |
|||||
|
/bin/ |
||||
@ -0,0 +1,17 @@ |
|||||
|
<?xml version="1.0" encoding="UTF-8"?> |
||||
|
<projectDescription> |
||||
|
<name>DemoJava</name> |
||||
|
<comment></comment> |
||||
|
<projects> |
||||
|
</projects> |
||||
|
<buildSpec> |
||||
|
<buildCommand> |
||||
|
<name>org.eclipse.jdt.core.javabuilder</name> |
||||
|
<arguments> |
||||
|
</arguments> |
||||
|
</buildCommand> |
||||
|
</buildSpec> |
||||
|
<natures> |
||||
|
<nature>org.eclipse.jdt.core.javanature</nature> |
||||
|
</natures> |
||||
|
</projectDescription> |
||||
@ -0,0 +1,2 @@ |
|||||
|
eclipse.preferences.version=1 |
||||
|
encoding/<project>=UTF-8 |
||||
@ -0,0 +1,12 @@ |
|||||
|
eclipse.preferences.version=1 |
||||
|
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled |
||||
|
org.eclipse.jdt.core.compiler.codegen.methodParameters=do not generate |
||||
|
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8 |
||||
|
org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve |
||||
|
org.eclipse.jdt.core.compiler.compliance=1.8 |
||||
|
org.eclipse.jdt.core.compiler.debug.lineNumber=generate |
||||
|
org.eclipse.jdt.core.compiler.debug.localVariable=generate |
||||
|
org.eclipse.jdt.core.compiler.debug.sourceFile=generate |
||||
|
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error |
||||
|
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error |
||||
|
org.eclipse.jdt.core.compiler.source=1.8 |
||||
@ -0,0 +1,24 @@ |
|||||
|
package CWSDK; |
||||
|
|
||||
|
|
||||
|
public class FaceAttrRet { |
||||
|
|
||||
|
/* * |
||||
|
* 年龄段 |
||||
|
* 0为小孩,1为成年人 2为老人 |
||||
|
* |
||||
|
* 性别 |
||||
|
* 0为女士,1为男士 |
||||
|
* |
||||
|
* |
||||
|
* 普遍意义上的人种 黑、白、黄 |
||||
|
* 0 黑种人 1 白种人 2 黄种人 |
||||
|
* */ |
||||
|
public int m_iValue = 0; |
||||
|
|
||||
|
/* * |
||||
|
* 置信分数 |
||||
|
* 为0--1之间的数字,置信分数越高,估值越可靠 |
||||
|
* */ |
||||
|
public float m_fConfidence = 0.0f; |
||||
|
} |
||||
@ -0,0 +1,35 @@ |
|||||
|
package CWSDK; |
||||
|
|
||||
|
|
||||
|
|
||||
|
public class FaceAttribute { |
||||
|
|
||||
|
static FaceAttribute attri = null; |
||||
|
|
||||
|
public FaceAttribute() { |
||||
|
FaceCommon.loadLibrarys(); |
||||
|
} |
||||
|
|
||||
|
public static FaceAttribute getInstance() { |
||||
|
|
||||
|
if (null == attri) { |
||||
|
attri = new FaceAttribute(); |
||||
|
} |
||||
|
return attri; |
||||
|
} |
||||
|
|
||||
|
|
||||
|
static public native int cwCreateAttributeHandle(String pConfigurePath, String pLicence); |
||||
|
|
||||
|
static public native int cwReleaseAttributeHandle(int pAttributeHandle); |
||||
|
|
||||
|
// 返回年龄
|
||||
|
static public native int cwGetAgeEval(int pAttributeHandle, byte[] dataAlign, int iWidth, int iHeight, int iChannels); |
||||
|
|
||||
|
static public native int cwGetGenderEval(int pAttributeHandle, byte[] dataAlign, int iWidth, int iHeight, int iChannels, |
||||
|
FaceAttrRet attr); |
||||
|
|
||||
|
static public native int cwGetRaceEval(int pAttributeHandle, byte[] dataAlign, int iWidth, int iHeight, int iChannels, |
||||
|
FaceAttrRet attr); |
||||
|
|
||||
|
} |
||||
@ -0,0 +1,18 @@ |
|||||
|
package CWSDK; |
||||
|
|
||||
|
public class FaceCommon { |
||||
|
|
||||
|
private static void loadLibrary(String libraryName) { |
||||
|
System.loadLibrary(libraryName); |
||||
|
} |
||||
|
|
||||
|
public static void loadLibrarys() { |
||||
|
// TODO Auto-generated method stub
|
||||
|
loadLibrary("DeepNet"); |
||||
|
loadLibrary("CWFaceDetTrack_CPU_GPU"); |
||||
|
loadLibrary("CwNirLivDet"); |
||||
|
loadLibrary("CloudWalkRecog"); |
||||
|
loadLibrary("CWFaceSDK"); |
||||
|
loadLibrary("CWFaceSDKJni"); |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,42 @@ |
|||||
|
package CWSDK; |
||||
|
|
||||
|
|
||||
|
|
||||
|
public class FaceDetTrack { |
||||
|
|
||||
|
static FaceDetTrack sCJNI = null; |
||||
|
|
||||
|
public FaceDetTrack() { |
||||
|
FaceCommon.loadLibrarys(); |
||||
|
} |
||||
|
|
||||
|
public static FaceDetTrack getInstance() { |
||||
|
|
||||
|
if (null == sCJNI) { |
||||
|
sCJNI = new FaceDetTrack(); |
||||
|
} |
||||
|
return sCJNI; |
||||
|
} |
||||
|
|
||||
|
|
||||
|
// 浜鸿劯妫�娴婼DK
|
||||
|
static public native int cwCreateDetHandle(String pConfigFile, String pLicence); |
||||
|
|
||||
|
static public native int cwReleaseDetHandle(int pDetector); |
||||
|
|
||||
|
static public native int cwGetFaceParam(int pDetector, FaceParam param); |
||||
|
|
||||
|
static public native int cwSetFaceParam(int pDetector, FaceParam param, String pConfigFile); |
||||
|
|
||||
|
static public native int cwFaceDetection(int pDetector, byte[] pFrameImg, |
||||
|
int iWidth, |
||||
|
int iHeight, |
||||
|
int iFormat, |
||||
|
int iAngle, |
||||
|
int iMirror, |
||||
|
int iOp, |
||||
|
FaceInfo[] pFaceBuffer); |
||||
|
|
||||
|
static public native int cwResetDetTrackState(int pDetector); |
||||
|
|
||||
|
} |
||||
@ -0,0 +1,50 @@ |
|||||
|
package CWSDK; |
||||
|
|
||||
|
|
||||
|
|
||||
|
public class FaceInfo { |
||||
|
public FaceInfo() |
||||
|
{ |
||||
|
|
||||
|
} |
||||
|
|
||||
|
public int detected; // 0: 跟踪到的人脸; 1: 检测到的人脸; 2:检测到但不会被进行后续计算(关键点)的人脸;
|
||||
|
// 3: 可能是静态误检框;4:大角度人脸; 5:关键点错误; 6:不需再处理的人脸(只有标记为1的人脸,关键点、
|
||||
|
// 对齐、质量分才有效;但除0之外其他都可能有口罩分)7:被估计为低质量人脸
|
||||
|
|
||||
|
public int trackId; // 人脸ID(ID<0表示没有进入跟踪)
|
||||
|
|
||||
|
// face rect
|
||||
|
public int x; // 人脸框
|
||||
|
public int y; |
||||
|
public int width; |
||||
|
public int height; |
||||
|
|
||||
|
// face_point关键点,最多68个关键点,目前使用9点关键点模型
|
||||
|
public float[] keypt_x; // 关键点x坐标
|
||||
|
public float[] keypt_y; // 关键点y坐标
|
||||
|
public float keyptScore; // 关键点得分
|
||||
|
//肤色
|
||||
|
|
||||
|
// face_aligned
|
||||
|
public byte[] alignedData; // 对齐人脸数据,用来提特征
|
||||
|
public int alignedW; |
||||
|
public int alignedH; |
||||
|
public int nChannels; |
||||
|
|
||||
|
// face_quality
|
||||
|
public int errcode; // 质量分析错误码
|
||||
|
public float[] scores; // 质量分分数项,具体含义(根据数据下标顺序):
|
||||
|
/* 0 - 人脸质量总分,0.65-1.0 |
||||
|
* 1 - 清晰度,越大表示越清晰,推荐范围0.65-1.0 |
||||
|
* 2 - 亮度,越大表示越亮,推荐范围0.2-0.8 |
||||
|
* 3 - 人脸角度,左转为正,右转为负 |
||||
|
* 4 - 人脸角度,抬头为正,低头为负 |
||||
|
* 5 - 人脸角度,顺时针为正,逆时针为负 |
||||
|
* 6 - 肤色接近真人肤色程度,越大表示越真实,推荐范围0.5-1.0 |
||||
|
* 7 - 戴黑框眼镜置信度,越大表示戴黑框眼镜的可能性越大,推荐范围0.0-0.5 |
||||
|
* 8 - 戴墨镜的置信分,越大表示戴墨镜的可能性越大,推荐范围0.0-0.5 |
||||
|
*/ |
||||
|
} |
||||
|
|
||||
|
|
||||
@ -0,0 +1,153 @@ |
|||||
|
package CWSDK; |
||||
|
|
||||
|
|
||||
|
|
||||
|
public interface FaceInterface { |
||||
|
|
||||
|
// 图像格式
|
||||
|
interface cw_img_form_t extends FaceInterface { |
||||
|
int CW_IMAGE_GRAY8 = 0; |
||||
|
int CW_IMAGE_BGR888 = 1; |
||||
|
int CW_IMAGE_BGRA8888 = 2; |
||||
|
int CW_IMAGE_RGB888 = 3; |
||||
|
int CW_IMAGE_RGBA8888 = 4; |
||||
|
int CW_IMAGE_YUV420P = 5; |
||||
|
int CW_IMAGE_YV12 = 6; |
||||
|
int CW_IMAGE_NV12 = 7; |
||||
|
int CW_IMAGE_NV21 = 8; |
||||
|
int CW_IMAGE_BINARY = 9; |
||||
|
} |
||||
|
|
||||
|
// 图像旋转角度(逆时针)
|
||||
|
interface cw_img_angle_t extends FaceInterface { |
||||
|
int CW_IMAGE_ANGLE_0 = 0; |
||||
|
int CW_IMAGE_ANGLE_90 = 1; |
||||
|
int CW_IMAGE_ANGLE_180 = 2; |
||||
|
int CW_IMAGE_ANGLE_270 = 3; |
||||
|
} |
||||
|
|
||||
|
// 图像镜像
|
||||
|
interface cw_img_mirror_t extends FaceInterface { |
||||
|
int CW_IMAGE_MIRROR_NONE = 0; // 不镜像
|
||||
|
int CW_IMAGE_MIRROR_HOR = 1; // 水平镜像
|
||||
|
int CW_IMAGE_MIRROR_VER = 2; // 垂直镜像
|
||||
|
int CW_IMAGE_MIRROR_HV = 3; // 垂直和水平镜像
|
||||
|
} |
||||
|
|
||||
|
|
||||
|
// 检测开关选项
|
||||
|
interface cw_op_t extends FaceInterface { |
||||
|
int CW_OP_DET = 0; // (1 << 0) 进行人脸检测,并返回人脸矩形位置
|
||||
|
int CW_OP_TRACK = 2; // (1 << 1)进行人脸跟踪,并返回人脸跟踪的ID
|
||||
|
int CW_OP_KEYPT = 4; // (1 << 2)进行人脸关键点检测,并返回人脸上的关键点坐标信息
|
||||
|
int CW_OP_ALIGN = 8; // (1 << 3)进行人脸图像对齐,并返回对齐人脸数据,用来提特征
|
||||
|
int CW_OP_QUALITY = 16; // (1 << 4)人脸质量分(质量分子项开关在配置文件中配置)
|
||||
|
int CW_OP_ALL = 30; // (所有开关综合)总开关
|
||||
|
} |
||||
|
|
||||
|
// 特征句柄功能
|
||||
|
interface cw_recog_pattern_t extends FaceInterface { |
||||
|
int CW_FEATURE_EXTRACT = 0; |
||||
|
int CW_RECOGNITION = 1; |
||||
|
} |
||||
|
|
||||
|
// 通用错误码
|
||||
|
interface cw_errcode_t extends FaceInterface { |
||||
|
int CW_SDKLIT_OK = 0; // 成功
|
||||
|
|
||||
|
int CW_UNKNOWN_ERR = 20000; // 未知错误
|
||||
|
int CW_DETECT_INIT_ERR = 20001; // 初始化人脸检测器失败:如加载模型失败等
|
||||
|
int CW_KEYPT_INIT_ERR = 20002; // 初始化关键点检测器失败:如加载模型失败等
|
||||
|
int CW_QUALITY_INIT_ERR = 20003; // 初始化跟踪器失败:如加载模型失败等
|
||||
|
|
||||
|
int CW_DET_ERR = 20004; // 检测失败
|
||||
|
int CW_TRACK_ERR = 20005; // 跟踪失败
|
||||
|
int CW_KEYPT_ERR = 20006; // 提取关键点失败
|
||||
|
int CW_ALIGN_ERR = 20007; // 对齐人脸失败
|
||||
|
int CW_QUALITY_ERR = 20008; // 质量评估失败
|
||||
|
|
||||
|
int CW_EMPTY_FRAME_ERR = 20009; // 空图像
|
||||
|
int CW_UNSUPPORT_FORMAT_ERR = 20010; // 图像格式不支持
|
||||
|
int CW_ROI_ERR = 20011; // ROI设置失败
|
||||
|
int CW_UNINITIALIZED_ERR = 20012; // 尚未初始化
|
||||
|
int CW_MINMAX_ERR = 20013; // 最小最大人脸设置失败
|
||||
|
int CW_OUTOF_RANGE_ERR = 20014; // 数据范围错误
|
||||
|
int CW_UNAUTHORIZED_ERR = 20015; // 未授权
|
||||
|
int CW_METHOD_UNAVAILABLE = 20016; // 方法无效
|
||||
|
int CW_PARAM_INVALID = 20017; // 参数无效
|
||||
|
int CW_BUFFER_EMPTY = 20018; // 缓冲区空
|
||||
|
|
||||
|
int CW_FILE_UNAVAILABLE = 20019; // 文件不存在:如加载的模型不存在等.
|
||||
|
int CW_DEVICE_UNAVAILABLE = 20020; // 设备不存在:如GPU等.
|
||||
|
int CW_DEVICE_ID_UNAVAILABLE = 20021; // 设备id不存在:如GPU id等
|
||||
|
int CW_EXCEEDMAXHANDLE_ERR = 20022; // 超过授权最大句柄数
|
||||
|
|
||||
|
int CW_RECOG_FEATURE_MODEL_ERR = 20023; // 加载特征识别模型失败
|
||||
|
int CW_RECOG_ALIGNEDFACE_ERR = 20024; // 对齐图片数据错误
|
||||
|
int CW_RECOG_MALLOCMEMORY_ERR = 20025; // 预分配特征空间不足
|
||||
|
|
||||
|
int CW_RECOG_FEATUREDATA_ERR = 20026; // 特征数据错误
|
||||
|
int CW_RECOG_EXCEEDMAXFEASPEED = 20027; // 超过授权最大提特征速度
|
||||
|
int CW_RECOG_EXCEEDMAXCOMSPEED = 20028; // 超过授权最大比对速度
|
||||
|
int CW_RECOG_GROUPSIZE_ERR = 20029; // 特征比对特征数N超过最大授权数
|
||||
|
int CW_RECOG_CONVERT_ERR = 20030; // 特征转换失败
|
||||
|
int CW_RECOG_NOFACEDET = 20031; // 未检测到人脸
|
||||
|
|
||||
|
int CW_LICENCE_JSON_CREATE_ERR = 20032; // Json操作失败
|
||||
|
int CW_LICENCE_DECRYPT_ERR = 20033; // 加密失败
|
||||
|
int CW_LICENCE_HTTP_ERROR = 20034; // HTTP失败
|
||||
|
int CW_LICENCE_MALLOCMEMORY_ERR = 20035; // 授权内存分配不足
|
||||
|
int CW_LICENCE_KEY_DEVICE_ERR = 20036; // 获取设备文件错误
|
||||
|
int CW_LICENCE_KEY_LICENSE_ERR = 20037; // 获取授权文件错误
|
||||
|
int CW_LICENCE_KEY_INSTALL_ERR = 20038; // 安装授权文件错误
|
||||
|
|
||||
|
int CW_ATTRI_AGEGENDER_MODEL_ERR=20039; //加载年龄性别模型失败
|
||||
|
int CW_ATTRI_EVAL_AGE_ERR=20040; //年龄识别失败
|
||||
|
int CW_ATTRI_EVAL_GENDER_ERR=20041; //性别识别失败
|
||||
|
int CW_ATTRI_EVAL_RACE_ERR=20042; //种族识别失败
|
||||
|
|
||||
|
} |
||||
|
|
||||
|
// 质量分检测错误码
|
||||
|
interface cw_quality_errcode_t extends FaceInterface { |
||||
|
int CW_QUALITY_OK = 0; // 质量分数据有效
|
||||
|
int CW_QUALITY_NO_DATA = 20150; // 质量分数据无效,原因:尚未检测
|
||||
|
int CW_QUALITY_ERROR_UNKNOWN = 20151; // 未知错误
|
||||
|
} |
||||
|
// 红外活体检测结果返回值
|
||||
|
interface cw_nirliv_det_rst_t extends FaceInterface { |
||||
|
int CW_NIR_LIV_DET_LIVE = 0; // 以阈值0.5判断为活体
|
||||
|
int CW_NIR_LIV_DET_UNLIVE = 1; // 以阈值0.5判断为非活体
|
||||
|
int CW_NIR_LIV_DET_DIST_FAILED = 2; // 人脸距离检测未通过
|
||||
|
int CW_NIR_LIV_DET_SKIN_FAILED = 3; // 人脸肤色检测未通过
|
||||
|
int CW_NIR_LIV_DET_NO_PAIR_FACE = 4; // 未匹配到人脸
|
||||
|
int CW_NIR_LIV_DET_IS_INIT = 5; // 红外活体检测结果初始值
|
||||
|
} |
||||
|
|
||||
|
// 红外活体检测错误码
|
||||
|
interface cw_nirliveness_err_t extends FaceInterface { |
||||
|
int CW_NIRLIV_OK = 0; // 红外检测成功
|
||||
|
|
||||
|
int CW_NIRLIV_ERR_CREATE_HANDLE = 26000; // 创建红外活体检测句柄失败
|
||||
|
int CW_NIRLIV_ERR_FREE_HANDLE = 26001; // 释放红外活体检测句柄失败
|
||||
|
int CW_NIRLIV_ERR_FACE_PAIR = 26002; // 人脸匹配初始化失败
|
||||
|
int CW_NIRLIV_ERR_CREAT_LOG_DIR = 26003; // 创建日志路径失败
|
||||
|
int CW_NIRLIV_ERR_MODEL_NOTEXIST = 26004; // 输入模型不存在
|
||||
|
int CW_NIRLIV_ERR_MODEL_FAILED = 26005; // 输入模型初始化失败
|
||||
|
int CW_NIRLIV_ERR_INPUT_UNINIT = 26006; // 输入未初始化
|
||||
|
int CW_NIRLIV_ERR_NIR_NO_FACE = 26007; // 输入红外图片没有人脸
|
||||
|
int CW_NIRLIV_ERR_VIS_NO_FACE = 26008; // 输入可见光图片没有人脸
|
||||
|
int CW_NIRLIV_ERR_NO_PAIR_FACE = 26009; // 输入可见光和红外图片人脸未能匹配
|
||||
|
int CW_NIRLIV_ERR_PUSH_DATA = 26010; // 输入数据失败
|
||||
|
int CW_NIRLIV_ERR_NUM_LANDMARKS = 26011; // 输入可见光图片和红外图片关键点个数不等
|
||||
|
int CW_NIRLIV_ERR_NO_LANDMARKS = 26012; // 输入红外图片没有人脸关键点
|
||||
|
int CW_NIRLIV_ERR_INPUT_IMAGE = 26013; // 输入红外图片或者可见光图片不是多通道
|
||||
|
int CW_NIRLIV_ERR_UNAUTHORIZED = 26014; // 没有license(未授权)
|
||||
|
int CW_NIRLIV_ERR_FACE_NUM_ERR = 26015; // 未开启人脸匹配开关时,可见光或红外图像人脸大于1
|
||||
|
int CW_NIRLIV_ERR_CAM_UNCW = 26016; // 非云从定制摄像头
|
||||
|
int CW_NIRLIV_ERR_UNKNOWN = 26017; // 未知结果
|
||||
|
int CW_NIRLIV_ERR_MAXHANDLE = 26018; // 超过最大红外活体最大授权句柄数
|
||||
|
int CW_NIRLIV_ERR_NIRIMAGE = 26019; // 输入红外图片数据错误
|
||||
|
int CW_NIRLIV_ERR_VISIMAGE = 26020; // 输入可见光图片数据错误
|
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,16 @@ |
|||||
|
package CWSDK; |
||||
|
|
||||
|
|
||||
|
// 红外检测输入人脸图片参数
|
||||
|
public class FaceNisLiveParam { |
||||
|
|
||||
|
public int nLandmarks; // 人脸的关键点个数
|
||||
|
public int nirWidth; // 输入NIR图像宽
|
||||
|
public int nirHeight; // 输入NIR图像高
|
||||
|
public int nirFormat; // 输入NIR红外图像格式
|
||||
|
|
||||
|
public int visWidth; // 输入VIS图像宽
|
||||
|
public int visHeight; // 输入VIS图像高
|
||||
|
public int visFormat; // 输入VIS可见光图像格式
|
||||
|
|
||||
|
} |
||||
@ -0,0 +1,14 @@ |
|||||
|
package CWSDK; |
||||
|
|
||||
|
|
||||
|
// 人脸红外检测输出的可见光人脸活体信息
|
||||
|
public class FaceNisLiveResInfo { |
||||
|
public FaceNisLiveResInfo() |
||||
|
{ |
||||
|
|
||||
|
} |
||||
|
|
||||
|
public int livRst; // 是否为活体或检测过程中的相关错误码
|
||||
|
|
||||
|
public float score; // 红外活体检测得分
|
||||
|
} |
||||
@ -0,0 +1,34 @@ |
|||||
|
package CWSDK; |
||||
|
|
||||
|
public class FaceNisLiveness { |
||||
|
|
||||
|
static FaceNisLiveness nirLive = null; |
||||
|
|
||||
|
public FaceNisLiveness() { |
||||
|
FaceCommon.loadLibrarys(); |
||||
|
} |
||||
|
|
||||
|
public static FaceNisLiveness getInstance() { |
||||
|
|
||||
|
if (null == nirLive) { |
||||
|
nirLive = new FaceNisLiveness(); |
||||
|
} |
||||
|
return nirLive; |
||||
|
} |
||||
|
|
||||
|
// 人脸红外检测SDK原始接口
|
||||
|
static public native int cwCreateNirLivenessHandle(String pNirModelPath, |
||||
|
String pRecogModelPath, |
||||
|
String pPairFilePath, |
||||
|
String pLogPath, |
||||
|
float fSkinThresh, |
||||
|
String pLicence); |
||||
|
|
||||
|
static public native int cwReleaseNirLivenessHandle(int pHandle); |
||||
|
|
||||
|
static public native int cwFaceNirLivenessDet(int pHandle, FaceNisLiveParam pLivenessDetInfo, |
||||
|
byte[] pVisData, float visSkinScore, float visKeyPtScore, float[] visKeypt_x, float[] visKeypt_y, |
||||
|
byte[] pNirData, float nirSkinScore, float nirKeyPtScore,float[] nirKeypt_x, float[] nirKeypt_y, |
||||
|
FaceNisLiveResInfo pNirLivenessRes); |
||||
|
|
||||
|
} |
||||
@ -0,0 +1,21 @@ |
|||||
|
package CWSDK; |
||||
|
|
||||
|
|
||||
|
public class FaceParam { |
||||
|
/** |
||||
|
* roi区域设置, 默认整帧图像 |
||||
|
**/ |
||||
|
public int roiX; |
||||
|
public int roiY; |
||||
|
public int roiWidth; |
||||
|
public int roiHeight; |
||||
|
/** |
||||
|
* 人脸尺寸范围-最小尺寸,默认100 |
||||
|
**/ |
||||
|
public int minSize; |
||||
|
/** |
||||
|
* 人脸尺寸范围-最大尺寸,默认400 |
||||
|
**/ |
||||
|
public int maxSize; |
||||
|
|
||||
|
} |
||||
@ -0,0 +1,35 @@ |
|||||
|
package CWSDK; |
||||
|
|
||||
|
|
||||
|
|
||||
|
public class FaceRecog { |
||||
|
|
||||
|
static FaceRecog recog = null; |
||||
|
|
||||
|
public FaceRecog() { |
||||
|
FaceCommon.loadLibrarys(); |
||||
|
} |
||||
|
|
||||
|
public static FaceRecog getInstance() { |
||||
|
|
||||
|
if (null == recog) { |
||||
|
recog = new FaceRecog(); |
||||
|
} |
||||
|
return recog; |
||||
|
} |
||||
|
|
||||
|
|
||||
|
// 人脸特征识别SDK
|
||||
|
static public native int cwCreateRecogHandle(String pConfigurePath, |
||||
|
String pLicence, |
||||
|
int emRecogPattern); |
||||
|
|
||||
|
static public native int cwReleaseRecogHandle(int pRecogHandle); |
||||
|
|
||||
|
static public native int cwGetFeatureLength(int pRecogHandle); |
||||
|
|
||||
|
static public native int cwGetFaceFeature(int pRecogHandle, byte[] dataAlign, int iWidth, int iHeight, int iChannels, byte[] pFeatureData); |
||||
|
|
||||
|
static public native int cwComputeMatchScore(int pRecogHandle, byte[] pFeaProbe, byte[] pFeaFiled, int iFeaFiledNum, float[] pScores); |
||||
|
|
||||
|
} |
||||
@ -0,0 +1,27 @@ |
|||||
|
package CWSDK; |
||||
|
|
||||
|
|
||||
|
|
||||
|
public class FaceVersion { |
||||
|
|
||||
|
static FaceVersion version = null; |
||||
|
|
||||
|
public FaceVersion() { |
||||
|
FaceCommon.loadLibrarys(); |
||||
|
} |
||||
|
|
||||
|
public static FaceVersion getInstance() { |
||||
|
|
||||
|
if (null == version) { |
||||
|
version = new FaceVersion(); |
||||
|
} |
||||
|
return version; |
||||
|
} |
||||
|
|
||||
|
static public native String cwGetSDKVersion(); |
||||
|
|
||||
|
static public native String cwGetDeviceInfo(); |
||||
|
|
||||
|
static public native int cwInstallLicence(String sAppKey, String sSecret, String sProductId); |
||||
|
|
||||
|
} |
||||
@ -0,0 +1,637 @@ |
|||||
|
package SDKDemo; |
||||
|
|
||||
|
import java.awt.List; |
||||
|
import java.io.File; |
||||
|
import java.io.FileInputStream; |
||||
|
import java.io.FileNotFoundException; |
||||
|
import java.io.IOException; |
||||
|
import java.io.InputStream; |
||||
|
import java.util.Scanner; |
||||
|
|
||||
|
import javax.lang.model.element.NestingKind; |
||||
|
|
||||
|
import CWSDK.FaceAttrRet; |
||||
|
import CWSDK.FaceAttribute; |
||||
|
import CWSDK.FaceVersion; |
||||
|
import CWSDK.FaceDetTrack; |
||||
|
import CWSDK.FaceRecog; |
||||
|
import CWSDK.FaceInterface; |
||||
|
import CWSDK.FaceParam; |
||||
|
import CWSDK.FaceInfo; |
||||
|
import CWSDK.FaceNisLiveParam; |
||||
|
import CWSDK.FaceNisLiveResInfo; |
||||
|
import CWSDK.FaceNirLivBean; |
||||
|
import CWSDK.NisLiveBean; |
||||
|
import CWSDK.FaceNisLiveness; |
||||
|
|
||||
|
// Lit 20170822
|
||||
|
public class SDKDemo { |
||||
|
|
||||
|
public static final int ERRCODE_MIN = FaceInterface.cw_errcode_t.CW_UNKNOWN_ERR; |
||||
|
public final int MAX_FACE_NUM = 20; |
||||
|
|
||||
|
FaceDetTrack mDet; |
||||
|
FaceRecog mRecog; |
||||
|
FaceVersion mVer; |
||||
|
FaceAttribute mAttri; |
||||
|
FaceNisLiveness mNir; |
||||
|
|
||||
|
int m_detHandle = ERRCODE_MIN; // 检测句柄
|
||||
|
int m_recogHandle = ERRCODE_MIN; // 识别句柄
|
||||
|
|
||||
|
int m_ageHandle = ERRCODE_MIN; // 年龄属性句柄
|
||||
|
int m_genderHandle = ERRCODE_MIN; // 性别属性句柄
|
||||
|
int m_raceHandle = ERRCODE_MIN; // 种族属性句柄
|
||||
|
|
||||
|
int m_NirLivnessHandle = ERRCODE_MIN; // 红外活体检测句柄
|
||||
|
|
||||
|
String m_cwLicence = ""; |
||||
|
|
||||
|
public static void main(String[] args) { |
||||
|
//TODO Auto-generated method stub
|
||||
|
SDKDemo demo = new SDKDemo(); |
||||
|
if (!demo.InitSDK()) { // 创建句柄
|
||||
|
demo.CloseSDK(); |
||||
|
return; |
||||
|
} |
||||
|
|
||||
|
System.out.println("初始化成功"); |
||||
|
|
||||
|
System.out.println("demo type:"); |
||||
|
System.out.println("1 Face Detect"); |
||||
|
System.out.println("2 Face Quality"); |
||||
|
System.out.println("3 Face Verify"); |
||||
|
System.out.println("4 Face Recognition"); |
||||
|
System.out.println("5 Face Attribute"); |
||||
|
System.out.println("6 Face NirLiveness"); |
||||
|
System.out.println("7 Exit"); |
||||
|
|
||||
|
System.out.println("Please Input Type: "); |
||||
|
Scanner scan = new Scanner(System.in); |
||||
|
int iDemoType = scan.nextInt(); |
||||
|
switch (iDemoType) { |
||||
|
case 1: |
||||
|
demo.DemoFaceDet(); |
||||
|
break; |
||||
|
case 2: |
||||
|
demo.DemoFaceQuality(); |
||||
|
break; |
||||
|
case 3: |
||||
|
demo.DemoFaceVevify(); |
||||
|
break; |
||||
|
case 4: |
||||
|
demo.DemoFaceRecog(); |
||||
|
break; |
||||
|
case 5: |
||||
|
demo.DemoFaceAttribute(); |
||||
|
break; |
||||
|
case 6: |
||||
|
demo.DemoFaceNirLiveness(); |
||||
|
default: |
||||
|
break; |
||||
|
} |
||||
|
|
||||
|
demo.CloseSDK(); // 销毁句柄
|
||||
|
System.out.println("\nDemo执行结束"); |
||||
|
} |
||||
|
|
||||
|
@SuppressWarnings("static-access") |
||||
|
private Boolean InitSDK() { |
||||
|
|
||||
|
mDet = FaceDetTrack.getInstance(); |
||||
|
mRecog = FaceRecog.getInstance(); |
||||
|
mVer = FaceVersion.getInstance(); |
||||
|
mAttri = FaceAttribute.getInstance(); |
||||
|
mNir = FaceNisLiveness.getInstance(); |
||||
|
|
||||
|
String sVersion = mVer.cwGetSDKVersion(); |
||||
|
System.out.println("SDK Verison: " + sVersion); |
||||
|
|
||||
|
// 创建检测句柄
|
||||
|
String sModelFolder = getRootPath(); // CWModels文件夹路径
|
||||
|
// 32位和64位检测模型不能共用,64位用_configs_frontend.xml,非64位用_configs_frontend_x86_arm.xml
|
||||
|
String sDetModel = sModelFolder + "/_configs_frontend.xml"; |
||||
|
m_detHandle = mDet.cwCreateDetHandle(sDetModel, m_cwLicence); |
||||
|
if (m_detHandle >= ERRCODE_MIN) { |
||||
|
System.out.println("创建检测句柄失败,错误码:" + m_detHandle); |
||||
|
return false; |
||||
|
} |
||||
|
|
||||
|
// 设置检测参数
|
||||
|
FaceParam mFaceParam = new FaceParam(); |
||||
|
mDet.cwGetFaceParam(m_detHandle,mFaceParam); |
||||
|
mFaceParam.minSize = 48; // 最小人脸
|
||||
|
mFaceParam.maxSize = 600; //最大人脸
|
||||
|
mDet.cwSetFaceParam(m_detHandle, mFaceParam, sDetModel); |
||||
|
|
||||
|
// 创建识别句柄
|
||||
|
m_recogHandle = mRecog.cwCreateRecogHandle(sModelFolder + "/CWR_Config_1_1.xml", m_cwLicence, FaceInterface.cw_recog_pattern_t.CW_FEATURE_EXTRACT); |
||||
|
if (m_recogHandle >= ERRCODE_MIN) { |
||||
|
System.out.println("创建识别句柄失败,错误码:" + m_recogHandle); |
||||
|
return false; |
||||
|
} |
||||
|
|
||||
|
// 创建属性句柄,如不使用属性,不要创建该句柄
|
||||
|
m_ageHandle = mAttri.cwCreateAttributeHandle(sModelFolder + "/attribute/ageGroup/cw_age_group_config.xml", m_cwLicence); |
||||
|
if (m_ageHandle >= ERRCODE_MIN) { |
||||
|
System.out.println("创建年龄属性句柄失败,错误码:" + m_ageHandle); |
||||
|
return false; |
||||
|
} |
||||
|
|
||||
|
m_genderHandle = mAttri.cwCreateAttributeHandle(sModelFolder + "/attribute/faceGender/cw_gender_config.xml", m_cwLicence); |
||||
|
if (m_genderHandle >= ERRCODE_MIN) { |
||||
|
System.out.println("创建性别属性句柄失败,错误码:" + m_genderHandle); |
||||
|
return false; |
||||
|
} |
||||
|
|
||||
|
m_raceHandle = mAttri.cwCreateAttributeHandle(sModelFolder + "/attribute/faceRace/cw_race_config.xml", m_cwLicence); |
||||
|
if (m_raceHandle >= ERRCODE_MIN) { |
||||
|
System.out.println("创建种族属性句柄失败,错误码:" + m_raceHandle); |
||||
|
return false; |
||||
|
} |
||||
|
//创建红外活体检测句柄
|
||||
|
String pNirModelPath = sModelFolder + "/nirLiveness_model_20181102_pc.bin"; |
||||
|
String pRecogModelPath = sModelFolder + "/hd171019.bin"; |
||||
|
String pPairFilePath = sModelFolder + "/matrix_para480x640.xml"; |
||||
|
String pLogPath = "./log"; |
||||
|
float fSkinThresh = 0.35f; |
||||
|
System.out.println("进入SDK\n"); |
||||
|
m_NirLivnessHandle = mNir.cwCreateNirLivenessHandle(pNirModelPath, pRecogModelPath, pPairFilePath,pLogPath,fSkinThresh, m_cwLicence); |
||||
|
if (m_NirLivnessHandle >= ERRCODE_MIN) { |
||||
|
System.out.println("创建红外活体检测句柄失败,错误码:" + m_NirLivnessHandle); |
||||
|
return false; |
||||
|
} |
||||
|
|
||||
|
return true; |
||||
|
} |
||||
|
|
||||
|
private void CloseSDK() { |
||||
|
// 程序退出时,销毁句柄
|
||||
|
if (m_detHandle < ERRCODE_MIN) { |
||||
|
mDet.cwReleaseDetHandle(m_detHandle); |
||||
|
} |
||||
|
|
||||
|
if (m_recogHandle < ERRCODE_MIN) { |
||||
|
mRecog.cwReleaseRecogHandle(m_recogHandle); |
||||
|
} |
||||
|
if (m_ageHandle < ERRCODE_MIN) { |
||||
|
mAttri.cwReleaseAttributeHandle(m_ageHandle); |
||||
|
} |
||||
|
if (m_genderHandle < ERRCODE_MIN) { |
||||
|
mAttri.cwReleaseAttributeHandle(m_genderHandle); |
||||
|
} |
||||
|
if (m_raceHandle < ERRCODE_MIN) { |
||||
|
mAttri.cwReleaseAttributeHandle(m_raceHandle); |
||||
|
} |
||||
|
if (m_NirLivnessHandle < ERRCODE_MIN) { |
||||
|
mNir.cwReleaseNirLivenessHandle(m_NirLivnessHandle); |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
// 人脸检测Demo
|
||||
|
private void DemoFaceDet() { |
||||
|
|
||||
|
System.out.print("Please Input Pic Path: "); |
||||
|
Scanner scan = new Scanner(System.in); |
||||
|
String sPicPath = scan.nextLine(); |
||||
|
System.out.println(sPicPath); |
||||
|
|
||||
|
byte[] imgData = null; |
||||
|
try { |
||||
|
imgData = file2byte(new File(sPicPath)); |
||||
|
} catch (Exception e) { |
||||
|
// e.printStackTrace();
|
||||
|
} |
||||
|
|
||||
|
if (imgData == null || imgData.length < 1) { |
||||
|
System.out.println("图片为空"); |
||||
|
return; |
||||
|
} |
||||
|
|
||||
|
FaceInfo[] faceBuffers = new FaceInfo[MAX_FACE_NUM]; |
||||
|
for (int i = 0; i < MAX_FACE_NUM; i++) { |
||||
|
faceBuffers[i] = new FaceInfo(); |
||||
|
} |
||||
|
// m_detHandle, imgData, 0, 0, FaceInterface.cw_img_form_t.CW_IMAGE_BINARY, 0,
|
||||
|
// 0,
|
||||
|
// FaceInterface.cw_op_t.CW_OP_DET, faceBuffers
|
||||
|
int faceNum = mDet.cwFaceDetection(m_detHandle, imgData, 0, 0, FaceInterface.cw_img_form_t.CW_IMAGE_BINARY, 0, |
||||
|
0, FaceInterface.cw_op_t.CW_OP_DET, faceBuffers); |
||||
|
if (faceNum >= ERRCODE_MIN) { |
||||
|
System.out.println("检测失败,错误码:" + faceNum); // 检测异常
|
||||
|
} else if (faceNum < 1) { |
||||
|
System.out.println("未检测到人脸"); // 未检测到人脸
|
||||
|
} else { |
||||
|
System.out.println("Face Num: " + faceNum); |
||||
|
// 输出人脸位置
|
||||
|
for (int i = 0; i < faceNum; i++) { |
||||
|
System.out.println("Face" + (i + 1) + ": Pos: " + faceBuffers[i].x + "," + faceBuffers[i].y + "," |
||||
|
+ faceBuffers[i].width + "," + faceBuffers[i].height); |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
System.out.println("\nFace Detect Completely"); |
||||
|
} |
||||
|
|
||||
|
// 人脸质量Demo
|
||||
|
private void DemoFaceQuality() { |
||||
|
System.out.print("Please Input Pic Path: "); |
||||
|
Scanner scan = new Scanner(System.in); |
||||
|
String sPicPath = scan.nextLine(); |
||||
|
System.out.println(sPicPath); |
||||
|
|
||||
|
byte[] imgData = null; |
||||
|
try { |
||||
|
imgData = file2byte(new File(sPicPath)); |
||||
|
} catch (Exception e) { |
||||
|
// e.printStackTrace();
|
||||
|
} |
||||
|
|
||||
|
if (imgData == null || imgData.length < 1) { |
||||
|
System.out.println("图片为空"); |
||||
|
return; |
||||
|
} |
||||
|
|
||||
|
FaceInfo[] faceBuffers = new FaceInfo[MAX_FACE_NUM]; |
||||
|
for (int i = 0; i < MAX_FACE_NUM; i++) { |
||||
|
faceBuffers[i] = new FaceInfo(); |
||||
|
} |
||||
|
// 加上质量分开关CW_OP_QUALITY
|
||||
|
int faceNum = mDet.cwFaceDetection(m_detHandle, imgData, 0, 0, FaceInterface.cw_img_form_t.CW_IMAGE_BINARY, 0, |
||||
|
0, FaceInterface.cw_op_t.CW_OP_DET | FaceInterface.cw_op_t.CW_OP_QUALITY, faceBuffers); |
||||
|
if (faceNum >= ERRCODE_MIN) { |
||||
|
System.out.println("检测失败,错误码:" + faceNum); // 检测异常
|
||||
|
} else if (faceNum < 1) { |
||||
|
System.out.println("未检测到人脸"); // 未检测到人脸
|
||||
|
} else { |
||||
|
System.out.println("Face Num: " + faceNum); |
||||
|
// 输出人脸位置
|
||||
|
for (int i = 0; i < faceNum; i++) { |
||||
|
int errQuality = faceBuffers[i].errcode; |
||||
|
if (errQuality == FaceInterface.cw_quality_errcode_t.CW_QUALITY_OK) { |
||||
|
System.out.println("Face" + (i + 1) + ": Pos: " + faceBuffers[i].x + "," + faceBuffers[i].y + "," |
||||
|
+ faceBuffers[i].width + "," + faceBuffers[i].height + " Quality Score: " |
||||
|
+ faceBuffers[i].scores[0]); |
||||
|
} else { |
||||
|
System.out.println("Face" + (i + 1) + ": Pos: " + faceBuffers[i].x + "," + faceBuffers[i].y + "," |
||||
|
+ faceBuffers[i].width + "," + faceBuffers[i].height + " Quality Err: " + errQuality); |
||||
|
} |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
System.out.println("\nFace Quality Completely"); |
||||
|
} |
||||
|
|
||||
|
// 人脸比对Demo(1:1)
|
||||
|
private void DemoFaceVevify() { |
||||
|
System.out.print("Please Input Pic Path1: "); |
||||
|
Scanner scan = new Scanner(System.in); |
||||
|
String sPicPath1 = scan.nextLine(); |
||||
|
|
||||
|
System.out.print("Please Input Pic Path2: "); |
||||
|
String sPicPath2 = scan.nextLine(); |
||||
|
|
||||
|
byte[] feaFace1 = GetFeatureFromPicPath(sPicPath1); |
||||
|
if (feaFace1 == null) { |
||||
|
System.out.println(sPicPath1 + " 提特征失败"); |
||||
|
return; |
||||
|
} |
||||
|
|
||||
|
byte[] feaFace2 = GetFeatureFromPicPath(sPicPath2); |
||||
|
if (feaFace2 == null) { |
||||
|
System.out.println(sPicPath2 + " 提特征失败"); |
||||
|
return; |
||||
|
} |
||||
|
|
||||
|
int iFeaLen = mRecog.cwGetFeatureLength(m_recogHandle); |
||||
|
float[] pScores = new float[1]; |
||||
|
int errCode = mRecog.cwComputeMatchScore(m_recogHandle, feaFace1, feaFace2, 1, pScores); |
||||
|
if (errCode != FaceInterface.cw_errcode_t.CW_SDKLIT_OK) { |
||||
|
System.out.println("Verify Error: " + errCode); |
||||
|
return; |
||||
|
} |
||||
|
|
||||
|
System.out.println("Verify Score: " + pScores[0]); |
||||
|
System.out.println("\nFace Verify Completely"); |
||||
|
} |
||||
|
|
||||
|
// 人脸识别Demo(1:n)
|
||||
|
private void DemoFaceRecog() { |
||||
|
|
||||
|
System.out.print("Please Input Pic Path1: "); |
||||
|
Scanner scan = new Scanner(System.in); |
||||
|
String sPicPath1 = scan.nextLine(); |
||||
|
|
||||
|
System.out.print("Please Input Pic Path2: "); |
||||
|
String sPicPath2 = scan.nextLine(); |
||||
|
|
||||
|
byte[] feaFace1 = GetFeatureFromPicPath(sPicPath1); |
||||
|
if (feaFace1 == null) { |
||||
|
System.out.println(sPicPath1 + " 提特征人脸特征失败"); |
||||
|
return; |
||||
|
} |
||||
|
byte[] feaFace2 = GetFeatureFromPicPath(sPicPath2); |
||||
|
if (feaFace2 == null) { |
||||
|
System.out.println(sPicPath2 + " 提特征Filed失败"); |
||||
|
return; |
||||
|
} |
||||
|
// 将2个filed特征组合到一起
|
||||
|
int iFeaLen = mRecog.cwGetFeatureLength(m_recogHandle); |
||||
|
byte[] feaFiledAll = new byte[2 * iFeaLen]; |
||||
|
System.arraycopy(feaFace1, 0, feaFiledAll, 0, iFeaLen); |
||||
|
System.arraycopy(feaFace2, 0, feaFiledAll, iFeaLen, iFeaLen); |
||||
|
|
||||
|
// 1:2识别
|
||||
|
float[] pScores = new float[2]; |
||||
|
int errCode = mRecog.cwComputeMatchScore(m_recogHandle, feaFace1, feaFiledAll, 2, pScores); |
||||
|
if (errCode != FaceInterface.cw_errcode_t.CW_SDKLIT_OK) { |
||||
|
System.out.println("Recog Error: " + errCode); |
||||
|
return; |
||||
|
} |
||||
|
|
||||
|
System.out.println("Recog Score: \n" + pScores[0] + "\n" + pScores[1]); |
||||
|
System.out.println("\nFace Recognise Completely"); |
||||
|
} |
||||
|
|
||||
|
// 人脸属性识别demo
|
||||
|
private void DemoFaceAttribute() { |
||||
|
System.out.print("Please Input Attribute Pic Path: "); |
||||
|
Scanner scan = new Scanner(System.in); |
||||
|
String sPicPath = scan.nextLine(); |
||||
|
|
||||
|
byte[] imgData = null; |
||||
|
try { |
||||
|
imgData = file2byte(new File(sPicPath)); |
||||
|
} catch (Exception e) { |
||||
|
e.printStackTrace(); |
||||
|
} |
||||
|
|
||||
|
if (imgData == null || imgData.length < 1) { |
||||
|
System.out.println("图片为空"); |
||||
|
return; |
||||
|
} |
||||
|
|
||||
|
FaceInfo[] faceBuffers = new FaceInfo[MAX_FACE_NUM]; |
||||
|
for (int i = 0; i < MAX_FACE_NUM; i++) { |
||||
|
faceBuffers[i] = new FaceInfo(); |
||||
|
} |
||||
|
// 加上人脸对齐开关CW_OP_ALIGN,用对齐数据来提特征
|
||||
|
int faceNum = mDet.cwFaceDetection(m_detHandle, imgData, 0, 0, FaceInterface.cw_img_form_t.CW_IMAGE_BINARY, 0, |
||||
|
0, FaceInterface.cw_op_t.CW_OP_DET | FaceInterface.cw_op_t.CW_OP_ALIGN, faceBuffers); |
||||
|
if (faceNum >= ERRCODE_MIN) { |
||||
|
System.out.println("检测失败,错误码:" + faceNum); // 检测异常
|
||||
|
return; |
||||
|
} else if (faceNum < 1) { |
||||
|
System.out.println("未检测到人脸"); // 未检测到人脸
|
||||
|
return; |
||||
|
} |
||||
|
|
||||
|
int errCode = FaceInterface.cw_errcode_t.CW_SDKLIT_OK; |
||||
|
for (int i = 0; i < faceNum; i++) { |
||||
|
|
||||
|
FaceAttrRet attrAge = new FaceAttrRet(); |
||||
|
int Age = mAttri.cwGetAgeEval(m_ageHandle, faceBuffers[i].alignedData, faceBuffers[i].alignedW, faceBuffers[i].alignedH, faceBuffers[i].nChannels); |
||||
|
System.out.println("Face " + (i + 1) + " Age: " + Age); |
||||
|
|
||||
|
FaceAttrRet attrGen = new FaceAttrRet(); |
||||
|
errCode = mAttri.cwGetGenderEval(m_genderHandle, faceBuffers[i].alignedData, faceBuffers[i].alignedW, |
||||
|
faceBuffers[i].alignedH, faceBuffers[i].nChannels, attrGen); |
||||
|
if (errCode == FaceInterface.cw_errcode_t.CW_SDKLIT_OK) { |
||||
|
System.out.println( |
||||
|
"Face " + (i + 1) + " Gender: " + attrGen.m_iValue + ", GenderConfidence: " + attrGen.m_fConfidence); |
||||
|
} else { |
||||
|
System.out.println("Face " + (i + 1) + " Attribute Error:" + errCode); |
||||
|
return; |
||||
|
} |
||||
|
|
||||
|
FaceAttrRet attrRace = new FaceAttrRet(); |
||||
|
errCode = mAttri.cwGetRaceEval(m_raceHandle, faceBuffers[i].alignedData, faceBuffers[i].alignedW, |
||||
|
faceBuffers[i].alignedH, faceBuffers[i].nChannels, attrRace); |
||||
|
if (errCode == FaceInterface.cw_errcode_t.CW_SDKLIT_OK) { |
||||
|
System.out.println( |
||||
|
"Face " + (i + 1) + " Race: " + attrRace.m_iValue + ", RaceConfidence: " + attrRace.m_fConfidence); |
||||
|
} else { |
||||
|
System.out.println("Face " + (i + 1) + " Attribute Error:" + errCode); |
||||
|
return; |
||||
|
} |
||||
|
System.out.println(""); |
||||
|
} |
||||
|
|
||||
|
System.out.println("\nFace Recognise Completely"); |
||||
|
} |
||||
|
|
||||
|
// 红外活体检测Demo
|
||||
|
private void DemoFaceNirLiveness() { |
||||
|
Scanner scan = new Scanner(System.in); |
||||
|
System.out.print("Please Input Vis Pic Path: "); |
||||
|
String sPicPathVis = scan.nextLine(); |
||||
|
|
||||
|
System.out.print("Please Input Nir Pic Path: "); |
||||
|
String sPicPathNis = scan.nextLine(); |
||||
|
|
||||
|
// 可见光图片
|
||||
|
byte[] imgDataVis = null; |
||||
|
try { |
||||
|
imgDataVis = file2byte(new File(sPicPathVis)); |
||||
|
} catch (Exception e) { |
||||
|
// e.printStackTrace();
|
||||
|
} |
||||
|
if (imgDataVis == null || imgDataVis.length < 1) { |
||||
|
System.out.println("可见光图片为空"); |
||||
|
return; |
||||
|
} |
||||
|
|
||||
|
// 红外图片
|
||||
|
byte[] imgDataNir = null; |
||||
|
try { |
||||
|
imgDataNir = file2byte(new File(sPicPathNis)); |
||||
|
} catch (Exception e) { |
||||
|
// e.printStackTrace();
|
||||
|
} |
||||
|
if (imgDataNir == null || imgDataNir.length < 1) { |
||||
|
System.out.println("红外图片为空"); |
||||
|
return; |
||||
|
} |
||||
|
|
||||
|
NisLiveBean nirRet = new NisLiveBean(); |
||||
|
//可见光人脸照片检测
|
||||
|
FaceInfo nirRetInfo = new FaceInfo(); |
||||
|
FaceNirLivBean detBeanNir = GetFaceInfoByImgData(m_detHandle, imgDataNir); |
||||
|
if (detBeanNir.ret != 0) { |
||||
|
nirRet.ret = detBeanNir.ret; |
||||
|
return; |
||||
|
} else { |
||||
|
if (detBeanNir.faceNum < 1) |
||||
|
{ |
||||
|
nirRet.ret = FaceInterface.cw_nirliveness_err_t.CW_NIRLIV_ERR_NIR_NO_FACE; |
||||
|
System.out.println("可见光检测失败 "); |
||||
|
return; |
||||
|
} |
||||
|
} |
||||
|
//红外人脸照片检测,只取第一个人脸
|
||||
|
int iKeyPtNum = detBeanNir.faceInfos[0].keypt_y.length; |
||||
|
float[] nirKeypt_x = new float[iKeyPtNum]; |
||||
|
float[] nirKeypt_y = new float[iKeyPtNum]; |
||||
|
float nirKeyPtScore = detBeanNir.faceInfos[0].keyptScore; |
||||
|
float nirSkinScore = detBeanNir.faceInfos[0].scores[6]; |
||||
|
System.arraycopy(detBeanNir.faceInfos[0].keypt_x, 0, nirKeypt_x, 0, iKeyPtNum); |
||||
|
System.arraycopy(detBeanNir.faceInfos[0].keypt_y, 0, nirKeypt_y, 0, iKeyPtNum); |
||||
|
|
||||
|
FaceInfo visRetInfo = new FaceInfo(); |
||||
|
FaceNirLivBean detBeanVis = GetFaceInfoByImgData(m_detHandle, imgDataVis); |
||||
|
if (detBeanVis.ret != 0) { |
||||
|
nirRet.ret = detBeanVis.ret; |
||||
|
return; |
||||
|
} else { |
||||
|
if (detBeanVis.faceNum < 1) |
||||
|
{ |
||||
|
nirRet.ret = FaceInterface.cw_nirliveness_err_t.CW_NIRLIV_ERR_NIR_NO_FACE; |
||||
|
System.out.println("可见光检测失败 "); |
||||
|
return ; |
||||
|
} |
||||
|
} |
||||
|
//可见光人脸照片检测,只取第一个人脸
|
||||
|
|
||||
|
float[] visKeypt_x = new float[iKeyPtNum]; |
||||
|
float[] visKeypt_y = new float[iKeyPtNum]; |
||||
|
float visKeyPtScore = detBeanVis.faceInfos[0].keyptScore ; |
||||
|
float visSkinScore = detBeanVis.faceInfos[0].scores[6]; |
||||
|
System.arraycopy(detBeanVis.faceInfos[0].keypt_x, 0, visKeypt_x, 0, iKeyPtNum); |
||||
|
System.arraycopy(detBeanVis.faceInfos[0].keypt_y, 0, visKeypt_y, 0, iKeyPtNum); |
||||
|
|
||||
|
// 红外检测参数赋值
|
||||
|
FaceNisLiveParam nirParam = new FaceNisLiveParam(); |
||||
|
nirParam.nLandmarks = iKeyPtNum; // 关键点个数
|
||||
|
// 可见光图片赋值
|
||||
|
|
||||
|
nirParam.visWidth = detBeanVis.faceInfos[0].width; |
||||
|
nirParam.visHeight = detBeanVis.faceInfos[0].height; |
||||
|
nirParam.visFormat = FaceInterface.cw_img_form_t.CW_IMAGE_BINARY; // 这里读取后都是3通道的bgr图;
|
||||
|
// 红外图片赋值
|
||||
|
nirParam.nirWidth = detBeanNir.faceInfos[0].width ; |
||||
|
nirParam.nirHeight = detBeanNir.faceInfos[0].height; |
||||
|
nirParam.nirFormat = FaceInterface.cw_img_form_t.CW_IMAGE_BINARY; // 这里读取后都是3通道的bgr图;
|
||||
|
nirRet.MemoryFaceNisLive(1); |
||||
|
nirRet.ret = mNir.cwFaceNirLivenessDet(m_NirLivnessHandle, nirParam, |
||||
|
imgDataVis, visSkinScore, visKeyPtScore, visKeypt_x, visKeypt_y, |
||||
|
imgDataNir , nirSkinScore, nirKeyPtScore, nirKeypt_x, nirKeypt_y, |
||||
|
nirRet.nirRetInfo); |
||||
|
if (nirRet.ret == FaceInterface.cw_nirliveness_err_t.CW_NIRLIV_OK) |
||||
|
{ |
||||
|
System.out.println( "ret: " + nirRet.nirRetInfo.livRst + " score: " + nirRet.nirRetInfo.score ); |
||||
|
}else{ |
||||
|
System.out.println( "Face NisLiveness Error: " + nirRet.ret ); |
||||
|
} |
||||
|
System.out.println("\nFace NirLiveness Completely"); |
||||
|
} |
||||
|
|
||||
|
// 输入图片路径,输出特征
|
||||
|
private byte[] GetFeatureFromPicPath(String sPicPath) { |
||||
|
|
||||
|
System.out.println(sPicPath + " 提特征"); |
||||
|
byte[] imgData = null; |
||||
|
try { |
||||
|
imgData = file2byte(new File(sPicPath)); |
||||
|
} catch (Exception e) { |
||||
|
// e.printStackTrace();
|
||||
|
} |
||||
|
|
||||
|
if (imgData == null || imgData.length < 1) { |
||||
|
System.out.println("图片为空"); |
||||
|
return null; |
||||
|
} |
||||
|
|
||||
|
FaceInfo[] faceBuffers = new FaceInfo[MAX_FACE_NUM]; |
||||
|
for (int i = 0; i < MAX_FACE_NUM; i++) { |
||||
|
faceBuffers[i] = new FaceInfo(); |
||||
|
} |
||||
|
// 加上人脸对齐开关CW_OP_ALIGN,用对齐数据来提特征
|
||||
|
int faceNum = mDet.cwFaceDetection(m_detHandle, imgData, 0, 0, FaceInterface.cw_img_form_t.CW_IMAGE_BINARY, 0, |
||||
|
0, FaceInterface.cw_op_t.CW_OP_DET | FaceInterface.cw_op_t.CW_OP_ALIGN, faceBuffers); |
||||
|
if (faceNum >= ERRCODE_MIN) { |
||||
|
System.out.println("检测失败,错误码:" + faceNum); // 检测异常
|
||||
|
return null; |
||||
|
} else if (faceNum < 1) { |
||||
|
System.out.println("未检测到人脸"); // 未检测到人脸
|
||||
|
return null; |
||||
|
} |
||||
|
|
||||
|
if (faceBuffers[0].alignedData == null) { |
||||
|
System.out.println("对齐数据为空,调用检测接口时请加上对齐开关"); // 判断对齐数据
|
||||
|
return null; |
||||
|
} |
||||
|
|
||||
|
int iFeaLen = mRecog.cwGetFeatureLength(m_recogHandle); |
||||
|
byte[] feature = new byte[iFeaLen]; |
||||
|
int errCode = FaceInterface.cw_errcode_t.CW_SDKLIT_OK; // 提特征错误码
|
||||
|
Long startTime = System.currentTimeMillis(); |
||||
|
errCode = mRecog.cwGetFaceFeature(m_recogHandle, faceBuffers[0].alignedData, faceBuffers[0].alignedW, |
||||
|
faceBuffers[0].alignedH, faceBuffers[0].nChannels, feature); |
||||
|
System.out.println("提特征耗时(ms):" + (System.currentTimeMillis() - startTime)); |
||||
|
if (errCode != FaceInterface.cw_errcode_t.CW_SDKLIT_OK) { |
||||
|
System.out.println("提特征错误:" + errCode); |
||||
|
return null; |
||||
|
} |
||||
|
|
||||
|
return feature; |
||||
|
} |
||||
|
|
||||
|
public static String getRootPath() { |
||||
|
try { |
||||
|
String sCurPath = new File("").getCanonicalPath(); |
||||
|
} catch (IOException e) { |
||||
|
e.printStackTrace(); |
||||
|
} |
||||
|
return "../../CWModels"; |
||||
|
} |
||||
|
|
||||
|
public byte[] file2byte(File file) throws IOException { |
||||
|
byte[] bytes = null; |
||||
|
if (file != null) { |
||||
|
InputStream is = new FileInputStream(file); |
||||
|
int length = (int) file.length(); |
||||
|
if (length > Integer.MAX_VALUE) {// 当文件的长度超过了int的最大值
|
||||
|
System.out.println("this file is max "); |
||||
|
is.close(); |
||||
|
return null; |
||||
|
} |
||||
|
bytes = new byte[length]; |
||||
|
int offset = 0; |
||||
|
int numRead = 0; |
||||
|
while (offset < bytes.length && (numRead = is.read(bytes, offset, bytes.length - offset)) >= 0) { |
||||
|
offset += numRead; |
||||
|
} |
||||
|
is.close(); |
||||
|
// 如果得到的字节长度和file实际的长度不一致就可能出错了
|
||||
|
if (offset < bytes.length) { |
||||
|
System.out.println("file length is error"); |
||||
|
return null; |
||||
|
} |
||||
|
} |
||||
|
return bytes; |
||||
|
} |
||||
|
|
||||
|
public FaceNirLivBean GetFaceInfoByImgData(int DetHandle, byte[] ImgData){ |
||||
|
FaceNirLivBean detectBean = new FaceNirLivBean(); |
||||
|
if (DetHandle == -1||ImgData == null || ImgData.length< 1) |
||||
|
{ |
||||
|
detectBean.ret = (int)FaceInterface.cw_errcode_t.CW_UNINITIALIZED_ERR; |
||||
|
return detectBean; |
||||
|
} |
||||
|
int iFaceNum = 0; |
||||
|
// 检测,关键点与质量分
|
||||
|
|
||||
|
int faceNum = mDet.cwFaceDetection(m_detHandle, ImgData, 0, 0, FaceInterface.cw_img_form_t.CW_IMAGE_BINARY, 0, |
||||
|
0, FaceInterface.cw_op_t.CW_OP_DET|FaceInterface.cw_op_t.CW_OP_KEYPT|FaceInterface.cw_op_t.CW_OP_QUALITY , detectBean.faceInfos); |
||||
|
if (faceNum >= ERRCODE_MIN) { |
||||
|
System.out.println("Face Detector Error,Code :" + faceNum); // 检测异常
|
||||
|
detectBean.ret = faceNum; |
||||
|
} else if (faceNum < 1) { |
||||
|
System.out.println("No Face Detected !"); // 未检测到人脸
|
||||
|
detectBean.faceNum = faceNum; |
||||
|
} |
||||
|
detectBean.faceNum = faceNum; |
||||
|
return detectBean; |
||||
|
} |
||||
|
|
||||
|
} |
||||
@ -0,0 +1,4 @@ |
|||||
|
1. 当前目录里的DemoJava为Eclipse工程,使用的JDK版本为“jdk1.8.0”; |
||||
|
2. DemoJava中加载的Dll库为“CWFaceSDKJni.dll”,该版本只支持64位的SDK,该库为jni库,依赖对应SDK的库; |
||||
|
3. 当前目录下“win_x64_jni”中的JNI库,依赖上层目录“build_64\bin”中的SDK库; |
||||
|
4. 若要调用该Demo,需要将以上jni库和SDK库拷贝到一起,设置环境变量;或者全部拷贝到JDK下的“bin”目录中,目的是让java虚拟机能Load这些SDK库。 |
||||
@ -0,0 +1,10 @@ |
|||||
|
@echo off |
||||
|
echo 将所有依赖的dll库拷贝到目标路径,再设置环境变量 |
||||
|
set packsrc=..\ |
||||
|
set packdest=win_x64_jni |
||||
|
|
||||
|
|
||||
|
echo 拷贝Windows库 |
||||
|
XCOPY %packsrc%build_64\bin\*.dll %packdest% /Y/i/s |
||||
|
|
||||
|
pause |
||||
Binary file not shown.
Binary file not shown.
@ -0,0 +1,102 @@ |
|||||
|
|
||||
|
// Demo_MFC.cpp : 定义应用程序的类行为。
|
||||
|
//
|
||||
|
|
||||
|
#include "stdafx.h" |
||||
|
#include "Demo_MFC.h" |
||||
|
#include "Demo_MFCDlg.h" |
||||
|
|
||||
|
#ifdef _DEBUG |
||||
|
#define new DEBUG_NEW |
||||
|
#endif |
||||
|
|
||||
|
|
||||
|
// CDemo_MFCApp
|
||||
|
|
||||
|
BEGIN_MESSAGE_MAP(CDemo_MFCApp, CWinApp) |
||||
|
ON_COMMAND(ID_HELP, &CWinApp::OnHelp) |
||||
|
END_MESSAGE_MAP() |
||||
|
|
||||
|
|
||||
|
// CDemo_MFCApp 构造
|
||||
|
|
||||
|
CDemo_MFCApp::CDemo_MFCApp() |
||||
|
{ |
||||
|
// 支持重新启动管理器
|
||||
|
m_dwRestartManagerSupportFlags = AFX_RESTART_MANAGER_SUPPORT_RESTART; |
||||
|
|
||||
|
// TODO: 在此处添加构造代码,
|
||||
|
// 将所有重要的初始化放置在 InitInstance 中
|
||||
|
} |
||||
|
|
||||
|
|
||||
|
// 唯一的一个 CDemo_MFCApp 对象
|
||||
|
|
||||
|
CDemo_MFCApp theApp; |
||||
|
|
||||
|
|
||||
|
// CDemo_MFCApp 初始化
|
||||
|
|
||||
|
BOOL CDemo_MFCApp::InitInstance() |
||||
|
{ |
||||
|
// 如果一个运行在 Windows XP 上的应用程序清单指定要
|
||||
|
// 使用 ComCtl32.dll 版本 6 或更高版本来启用可视化方式,
|
||||
|
//则需要 InitCommonControlsEx()。否则,将无法创建窗口。
|
||||
|
INITCOMMONCONTROLSEX InitCtrls; |
||||
|
InitCtrls.dwSize = sizeof(InitCtrls); |
||||
|
// 将它设置为包括所有要在应用程序中使用的
|
||||
|
// 公共控件类。
|
||||
|
InitCtrls.dwICC = ICC_WIN95_CLASSES; |
||||
|
InitCommonControlsEx(&InitCtrls); |
||||
|
|
||||
|
CWinApp::InitInstance(); |
||||
|
|
||||
|
|
||||
|
AfxEnableControlContainer(); |
||||
|
|
||||
|
// 创建 shell 管理器,以防对话框包含
|
||||
|
// 任何 shell 树视图控件或 shell 列表视图控件。
|
||||
|
CShellManager *pShellManager = new CShellManager; |
||||
|
|
||||
|
// 激活“Windows Native”视觉管理器,以便在 MFC 控件中启用主题
|
||||
|
CMFCVisualManager::SetDefaultManager(RUNTIME_CLASS(CMFCVisualManagerWindows)); |
||||
|
|
||||
|
// 标准初始化
|
||||
|
// 如果未使用这些功能并希望减小
|
||||
|
// 最终可执行文件的大小,则应移除下列
|
||||
|
// 不需要的特定初始化例程
|
||||
|
// 更改用于存储设置的注册表项
|
||||
|
// TODO: 应适当修改该字符串,
|
||||
|
// 例如修改为公司或组织名
|
||||
|
SetRegistryKey(_T("应用程序向导生成的本地应用程序")); |
||||
|
|
||||
|
CDemo_MFCDlg dlg; |
||||
|
m_pMainWnd = &dlg; |
||||
|
INT_PTR nResponse = dlg.DoModal(); |
||||
|
if (nResponse == IDOK) |
||||
|
{ |
||||
|
// TODO: 在此放置处理何时用
|
||||
|
// “确定”来关闭对话框的代码
|
||||
|
} |
||||
|
else if (nResponse == IDCANCEL) |
||||
|
{ |
||||
|
// TODO: 在此放置处理何时用
|
||||
|
// “取消”来关闭对话框的代码
|
||||
|
} |
||||
|
else if (nResponse == -1) |
||||
|
{ |
||||
|
TRACE(traceAppMsg, 0, "警告: 对话框创建失败,应用程序将意外终止。\n"); |
||||
|
TRACE(traceAppMsg, 0, "警告: 如果您在对话框上使用 MFC 控件,则无法 #define _AFX_NO_MFC_CONTROLS_IN_DIALOGS。\n"); |
||||
|
} |
||||
|
|
||||
|
// 删除上面创建的 shell 管理器。
|
||||
|
if (pShellManager != NULL) |
||||
|
{ |
||||
|
delete pShellManager; |
||||
|
} |
||||
|
|
||||
|
// 由于对话框已关闭,所以将返回 FALSE 以便退出应用程序,
|
||||
|
// 而不是启动应用程序的消息泵。
|
||||
|
return FALSE; |
||||
|
} |
||||
|
|
||||
@ -0,0 +1,32 @@ |
|||||
|
|
||||
|
// Demo_MFC.h : PROJECT_NAME 应用程序的主头文件
|
||||
|
//
|
||||
|
|
||||
|
#pragma once |
||||
|
|
||||
|
#ifndef __AFXWIN_H__ |
||||
|
#error "在包含此文件之前包含“stdafx.h”以生成 PCH 文件" |
||||
|
#endif |
||||
|
|
||||
|
#include "resource.h" // 主符号 |
||||
|
|
||||
|
|
||||
|
// CDemo_MFCApp:
|
||||
|
// 有关此类的实现,请参阅 Demo_MFC.cpp
|
||||
|
//
|
||||
|
|
||||
|
class CDemo_MFCApp : public CWinApp |
||||
|
{ |
||||
|
public: |
||||
|
CDemo_MFCApp(); |
||||
|
|
||||
|
// 重写
|
||||
|
public: |
||||
|
virtual BOOL InitInstance(); |
||||
|
|
||||
|
// 实现
|
||||
|
|
||||
|
DECLARE_MESSAGE_MAP() |
||||
|
}; |
||||
|
|
||||
|
extern CDemo_MFCApp theApp; |
||||
Binary file not shown.
@ -0,0 +1,327 @@ |
|||||
|
<?xml version="1.0" encoding="utf-8"?> |
||||
|
<Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> |
||||
|
<ItemGroup Label="ProjectConfigurations"> |
||||
|
<ProjectConfiguration Include="Debug|Win32"> |
||||
|
<Configuration>Debug</Configuration> |
||||
|
<Platform>Win32</Platform> |
||||
|
</ProjectConfiguration> |
||||
|
<ProjectConfiguration Include="Debug|x64"> |
||||
|
<Configuration>Debug</Configuration> |
||||
|
<Platform>x64</Platform> |
||||
|
</ProjectConfiguration> |
||||
|
<ProjectConfiguration Include="Release_Xp|Win32"> |
||||
|
<Configuration>Release_Xp</Configuration> |
||||
|
<Platform>Win32</Platform> |
||||
|
</ProjectConfiguration> |
||||
|
<ProjectConfiguration Include="Release_Xp|x64"> |
||||
|
<Configuration>Release_Xp</Configuration> |
||||
|
<Platform>x64</Platform> |
||||
|
</ProjectConfiguration> |
||||
|
<ProjectConfiguration Include="Release|Win32"> |
||||
|
<Configuration>Release</Configuration> |
||||
|
<Platform>Win32</Platform> |
||||
|
</ProjectConfiguration> |
||||
|
<ProjectConfiguration Include="Release|x64"> |
||||
|
<Configuration>Release</Configuration> |
||||
|
<Platform>x64</Platform> |
||||
|
</ProjectConfiguration> |
||||
|
</ItemGroup> |
||||
|
<PropertyGroup Label="Globals"> |
||||
|
<ProjectGuid>{D67A3C09-8724-4B0A-8346-8CDEABAEB082}</ProjectGuid> |
||||
|
<RootNamespace>Demo_MFC</RootNamespace> |
||||
|
<Keyword>MFCProj</Keyword> |
||||
|
</PropertyGroup> |
||||
|
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" /> |
||||
|
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration"> |
||||
|
<ConfigurationType>Application</ConfigurationType> |
||||
|
<UseDebugLibraries>true</UseDebugLibraries> |
||||
|
<PlatformToolset>v110</PlatformToolset> |
||||
|
<CharacterSet>Unicode</CharacterSet> |
||||
|
<UseOfMfc>Dynamic</UseOfMfc> |
||||
|
</PropertyGroup> |
||||
|
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration"> |
||||
|
<ConfigurationType>Application</ConfigurationType> |
||||
|
<UseDebugLibraries>true</UseDebugLibraries> |
||||
|
<PlatformToolset>v110</PlatformToolset> |
||||
|
<CharacterSet>Unicode</CharacterSet> |
||||
|
<UseOfMfc>Dynamic</UseOfMfc> |
||||
|
</PropertyGroup> |
||||
|
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration"> |
||||
|
<ConfigurationType>Application</ConfigurationType> |
||||
|
<UseDebugLibraries>false</UseDebugLibraries> |
||||
|
<PlatformToolset>v110</PlatformToolset> |
||||
|
<WholeProgramOptimization>true</WholeProgramOptimization> |
||||
|
<CharacterSet>Unicode</CharacterSet> |
||||
|
<UseOfMfc>Dynamic</UseOfMfc> |
||||
|
</PropertyGroup> |
||||
|
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release_Xp|Win32'" Label="Configuration"> |
||||
|
<ConfigurationType>Application</ConfigurationType> |
||||
|
<UseDebugLibraries>false</UseDebugLibraries> |
||||
|
<PlatformToolset>v110_xp</PlatformToolset> |
||||
|
<WholeProgramOptimization>true</WholeProgramOptimization> |
||||
|
<CharacterSet>Unicode</CharacterSet> |
||||
|
<UseOfMfc>Dynamic</UseOfMfc> |
||||
|
</PropertyGroup> |
||||
|
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration"> |
||||
|
<ConfigurationType>Application</ConfigurationType> |
||||
|
<UseDebugLibraries>false</UseDebugLibraries> |
||||
|
<PlatformToolset>v110</PlatformToolset> |
||||
|
<WholeProgramOptimization>true</WholeProgramOptimization> |
||||
|
<CharacterSet>Unicode</CharacterSet> |
||||
|
<UseOfMfc>Dynamic</UseOfMfc> |
||||
|
</PropertyGroup> |
||||
|
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release_Xp|x64'" Label="Configuration"> |
||||
|
<ConfigurationType>Application</ConfigurationType> |
||||
|
<UseDebugLibraries>false</UseDebugLibraries> |
||||
|
<PlatformToolset>v110</PlatformToolset> |
||||
|
<WholeProgramOptimization>true</WholeProgramOptimization> |
||||
|
<CharacterSet>Unicode</CharacterSet> |
||||
|
<UseOfMfc>Dynamic</UseOfMfc> |
||||
|
</PropertyGroup> |
||||
|
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" /> |
||||
|
<ImportGroup Label="ExtensionSettings"> |
||||
|
</ImportGroup> |
||||
|
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'"> |
||||
|
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" /> |
||||
|
</ImportGroup> |
||||
|
<ImportGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="PropertySheets"> |
||||
|
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" /> |
||||
|
</ImportGroup> |
||||
|
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|Win32'"> |
||||
|
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" /> |
||||
|
</ImportGroup> |
||||
|
<ImportGroup Condition="'$(Configuration)|$(Platform)'=='Release_Xp|Win32'" Label="PropertySheets"> |
||||
|
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" /> |
||||
|
</ImportGroup> |
||||
|
<ImportGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="PropertySheets"> |
||||
|
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" /> |
||||
|
</ImportGroup> |
||||
|
<ImportGroup Condition="'$(Configuration)|$(Platform)'=='Release_Xp|x64'" Label="PropertySheets"> |
||||
|
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" /> |
||||
|
</ImportGroup> |
||||
|
<PropertyGroup Label="UserMacros" /> |
||||
|
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'"> |
||||
|
<LinkIncremental>true</LinkIncremental> |
||||
|
</PropertyGroup> |
||||
|
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'"> |
||||
|
<LinkIncremental>true</LinkIncremental> |
||||
|
</PropertyGroup> |
||||
|
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'"> |
||||
|
<LinkIncremental>false</LinkIncremental> |
||||
|
<OutDir>..\build_32\bin</OutDir> |
||||
|
</PropertyGroup> |
||||
|
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release_Xp|Win32'"> |
||||
|
<LinkIncremental>false</LinkIncremental> |
||||
|
<OutDir>..\build_xp\bin</OutDir> |
||||
|
</PropertyGroup> |
||||
|
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'"> |
||||
|
<LinkIncremental>false</LinkIncremental> |
||||
|
<OutDir>..\build_64\bin</OutDir> |
||||
|
</PropertyGroup> |
||||
|
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release_Xp|x64'"> |
||||
|
<LinkIncremental>false</LinkIncremental> |
||||
|
<OutDir>..\build_64\bin</OutDir> |
||||
|
</PropertyGroup> |
||||
|
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'"> |
||||
|
<ClCompile> |
||||
|
<PrecompiledHeader>Use</PrecompiledHeader> |
||||
|
<WarningLevel>Level3</WarningLevel> |
||||
|
<Optimization>Disabled</Optimization> |
||||
|
<PreprocessorDefinitions>WIN32;_WINDOWS;_DEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions> |
||||
|
<SDLCheck>true</SDLCheck> |
||||
|
</ClCompile> |
||||
|
<Link> |
||||
|
<SubSystem>Windows</SubSystem> |
||||
|
<GenerateDebugInformation>true</GenerateDebugInformation> |
||||
|
</Link> |
||||
|
<Midl> |
||||
|
<MkTypLibCompatible>false</MkTypLibCompatible> |
||||
|
<ValidateAllParameters>true</ValidateAllParameters> |
||||
|
<PreprocessorDefinitions>_DEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions> |
||||
|
</Midl> |
||||
|
<ResourceCompile> |
||||
|
<Culture>0x0804</Culture> |
||||
|
<PreprocessorDefinitions>_DEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions> |
||||
|
<AdditionalIncludeDirectories>$(IntDir);%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories> |
||||
|
</ResourceCompile> |
||||
|
</ItemDefinitionGroup> |
||||
|
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'"> |
||||
|
<ClCompile> |
||||
|
<PrecompiledHeader>Use</PrecompiledHeader> |
||||
|
<WarningLevel>Level3</WarningLevel> |
||||
|
<Optimization>Disabled</Optimization> |
||||
|
<PreprocessorDefinitions>WIN32;_WINDOWS;_DEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions> |
||||
|
<SDLCheck>true</SDLCheck> |
||||
|
</ClCompile> |
||||
|
<Link> |
||||
|
<SubSystem>Windows</SubSystem> |
||||
|
<GenerateDebugInformation>true</GenerateDebugInformation> |
||||
|
</Link> |
||||
|
<Midl> |
||||
|
<MkTypLibCompatible>false</MkTypLibCompatible> |
||||
|
<PreprocessorDefinitions>_DEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions> |
||||
|
</Midl> |
||||
|
<ResourceCompile> |
||||
|
<Culture>0x0804</Culture> |
||||
|
<PreprocessorDefinitions>_DEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions> |
||||
|
<AdditionalIncludeDirectories>$(IntDir);%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories> |
||||
|
</ResourceCompile> |
||||
|
</ItemDefinitionGroup> |
||||
|
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'"> |
||||
|
<ClCompile> |
||||
|
<WarningLevel>Level3</WarningLevel> |
||||
|
<PrecompiledHeader>Use</PrecompiledHeader> |
||||
|
<Optimization>Disabled</Optimization> |
||||
|
<FunctionLevelLinking>true</FunctionLevelLinking> |
||||
|
<IntrinsicFunctions>true</IntrinsicFunctions> |
||||
|
<PreprocessorDefinitions>WIN32;_WINDOWS;NDEBUG;_CRT_SECURE_NO_WARNINGS;%(PreprocessorDefinitions)</PreprocessorDefinitions> |
||||
|
<SDLCheck>true</SDLCheck> |
||||
|
<AdditionalIncludeDirectories>opencv310\include;opencv310\include\opencv;opencv310\include\opencv2;..\CWFaceSDK;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories> |
||||
|
</ClCompile> |
||||
|
<Link> |
||||
|
<SubSystem>Windows</SubSystem> |
||||
|
<GenerateDebugInformation>true</GenerateDebugInformation> |
||||
|
<EnableCOMDATFolding>true</EnableCOMDATFolding> |
||||
|
<OptimizeReferences>true</OptimizeReferences> |
||||
|
<AdditionalDependencies>CWFaceSDK.lib;opencv_world310.lib;%(AdditionalDependencies)</AdditionalDependencies> |
||||
|
<AdditionalLibraryDirectories>../build_32/lib;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories> |
||||
|
</Link> |
||||
|
<Midl> |
||||
|
<MkTypLibCompatible>false</MkTypLibCompatible> |
||||
|
<ValidateAllParameters>true</ValidateAllParameters> |
||||
|
<PreprocessorDefinitions>NDEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions> |
||||
|
</Midl> |
||||
|
<ResourceCompile> |
||||
|
<Culture>0x0804</Culture> |
||||
|
<PreprocessorDefinitions>NDEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions> |
||||
|
<AdditionalIncludeDirectories>$(IntDir);%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories> |
||||
|
</ResourceCompile> |
||||
|
</ItemDefinitionGroup> |
||||
|
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release_Xp|Win32'"> |
||||
|
<ClCompile> |
||||
|
<WarningLevel>Level3</WarningLevel> |
||||
|
<PrecompiledHeader>Use</PrecompiledHeader> |
||||
|
<Optimization>Disabled</Optimization> |
||||
|
<FunctionLevelLinking>true</FunctionLevelLinking> |
||||
|
<IntrinsicFunctions>true</IntrinsicFunctions> |
||||
|
<PreprocessorDefinitions>WIN32;_WINDOWS;NDEBUG;_CRT_SECURE_NO_WARNINGS;%(PreprocessorDefinitions)</PreprocessorDefinitions> |
||||
|
<SDLCheck>true</SDLCheck> |
||||
|
<AdditionalIncludeDirectories>opencv310\include;opencv310\include\opencv;opencv310\include\opencv2;..\CWFaceSDK;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories> |
||||
|
</ClCompile> |
||||
|
<Link> |
||||
|
<SubSystem>Windows</SubSystem> |
||||
|
<GenerateDebugInformation>true</GenerateDebugInformation> |
||||
|
<EnableCOMDATFolding>true</EnableCOMDATFolding> |
||||
|
<OptimizeReferences>true</OptimizeReferences> |
||||
|
<AdditionalDependencies>CWFaceSDK.lib;opencv_world310.lib;%(AdditionalDependencies)</AdditionalDependencies> |
||||
|
<AdditionalLibraryDirectories>../build_xp/lib;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories> |
||||
|
</Link> |
||||
|
<Midl> |
||||
|
<MkTypLibCompatible>false</MkTypLibCompatible> |
||||
|
<ValidateAllParameters>true</ValidateAllParameters> |
||||
|
<PreprocessorDefinitions>NDEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions> |
||||
|
</Midl> |
||||
|
<ResourceCompile> |
||||
|
<Culture>0x0804</Culture> |
||||
|
<PreprocessorDefinitions>NDEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions> |
||||
|
<AdditionalIncludeDirectories>$(IntDir);%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories> |
||||
|
</ResourceCompile> |
||||
|
</ItemDefinitionGroup> |
||||
|
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'"> |
||||
|
<ClCompile> |
||||
|
<WarningLevel>Level3</WarningLevel> |
||||
|
<PrecompiledHeader>Use</PrecompiledHeader> |
||||
|
<Optimization>Disabled</Optimization> |
||||
|
<FunctionLevelLinking>true</FunctionLevelLinking> |
||||
|
<IntrinsicFunctions>true</IntrinsicFunctions> |
||||
|
<PreprocessorDefinitions>WIN32;DEMO_X64;_WINDOWS;NDEBUG;_CRT_SECURE_NO_WARNINGS;%(PreprocessorDefinitions)</PreprocessorDefinitions> |
||||
|
<SDLCheck>true</SDLCheck> |
||||
|
<AdditionalIncludeDirectories>opencv310\include;opencv310\include\opencv;opencv310\include\opencv2;..\CWFaceSDK;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories> |
||||
|
</ClCompile> |
||||
|
<Link> |
||||
|
<SubSystem>Windows</SubSystem> |
||||
|
<GenerateDebugInformation>true</GenerateDebugInformation> |
||||
|
<EnableCOMDATFolding>true</EnableCOMDATFolding> |
||||
|
<OptimizeReferences>true</OptimizeReferences> |
||||
|
<AdditionalDependencies>CWFaceSDK.lib;opencv_world310.lib;%(AdditionalDependencies)</AdditionalDependencies> |
||||
|
<AdditionalLibraryDirectories>../build_64/lib;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories> |
||||
|
</Link> |
||||
|
<Midl> |
||||
|
<MkTypLibCompatible>false</MkTypLibCompatible> |
||||
|
<PreprocessorDefinitions>NDEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions> |
||||
|
</Midl> |
||||
|
<ResourceCompile> |
||||
|
<Culture>0x0804</Culture> |
||||
|
<PreprocessorDefinitions>NDEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions> |
||||
|
<AdditionalIncludeDirectories>$(IntDir);%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories> |
||||
|
</ResourceCompile> |
||||
|
</ItemDefinitionGroup> |
||||
|
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release_Xp|x64'"> |
||||
|
<ClCompile> |
||||
|
<WarningLevel>Level3</WarningLevel> |
||||
|
<PrecompiledHeader>Use</PrecompiledHeader> |
||||
|
<Optimization>Disabled</Optimization> |
||||
|
<FunctionLevelLinking>true</FunctionLevelLinking> |
||||
|
<IntrinsicFunctions>true</IntrinsicFunctions> |
||||
|
<PreprocessorDefinitions>WIN32;_WINDOWS;NDEBUG;_CRT_SECURE_NO_WARNINGS;%(PreprocessorDefinitions)</PreprocessorDefinitions> |
||||
|
<SDLCheck>true</SDLCheck> |
||||
|
<AdditionalIncludeDirectories>CxImage;opencv310\include;opencv310\include\opencv;opencv310\include\opencv2;..\CWFaceSDK;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories> |
||||
|
</ClCompile> |
||||
|
<Link> |
||||
|
<SubSystem>Windows</SubSystem> |
||||
|
<GenerateDebugInformation>true</GenerateDebugInformation> |
||||
|
<EnableCOMDATFolding>true</EnableCOMDATFolding> |
||||
|
<OptimizeReferences>true</OptimizeReferences> |
||||
|
<AdditionalDependencies>CWFaceSDK.lib;opencv_world310.lib;cximage.lib;jpeg.lib;libdcr.lib;jasper.lib;libpsd.lib;png.lib;tiff.lib;mng.lib;zlib.lib;jbig.lib;%(AdditionalDependencies)</AdditionalDependencies> |
||||
|
<AdditionalLibraryDirectories>lib64;../build_64/lib;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories> |
||||
|
</Link> |
||||
|
<Midl> |
||||
|
<MkTypLibCompatible>false</MkTypLibCompatible> |
||||
|
<PreprocessorDefinitions>NDEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions> |
||||
|
</Midl> |
||||
|
<ResourceCompile> |
||||
|
<Culture>0x0804</Culture> |
||||
|
<PreprocessorDefinitions>NDEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions> |
||||
|
<AdditionalIncludeDirectories>$(IntDir);%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories> |
||||
|
</ResourceCompile> |
||||
|
</ItemDefinitionGroup> |
||||
|
<ItemGroup> |
||||
|
<Text Include="ReadMe.txt" /> |
||||
|
</ItemGroup> |
||||
|
<ItemGroup> |
||||
|
<ClInclude Include="Demo_MFC.h" /> |
||||
|
<ClInclude Include="Demo_MFCDlg.h" /> |
||||
|
<ClInclude Include="Resource.h" /> |
||||
|
<ClInclude Include="stdafx.h" /> |
||||
|
<ClInclude Include="targetver.h" /> |
||||
|
</ItemGroup> |
||||
|
<ItemGroup> |
||||
|
<ClCompile Include="Demo_MFC.cpp" /> |
||||
|
<ClCompile Include="Demo_MFCDlg.cpp" /> |
||||
|
<ClCompile Include="stdafx.cpp"> |
||||
|
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">Create</PrecompiledHeader> |
||||
|
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">Create</PrecompiledHeader> |
||||
|
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">Create</PrecompiledHeader> |
||||
|
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release_Xp|Win32'">Create</PrecompiledHeader> |
||||
|
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release|x64'">Create</PrecompiledHeader> |
||||
|
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release_Xp|x64'">Create</PrecompiledHeader> |
||||
|
</ClCompile> |
||||
|
</ItemGroup> |
||||
|
<ItemGroup> |
||||
|
<ResourceCompile Include="Demo_MFC.rc" /> |
||||
|
</ItemGroup> |
||||
|
<ItemGroup> |
||||
|
<None Include="res\Demo_MFC.rc2" /> |
||||
|
</ItemGroup> |
||||
|
<ItemGroup> |
||||
|
<Image Include="res\Demo_MFC.ico" /> |
||||
|
</ItemGroup> |
||||
|
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" /> |
||||
|
<ImportGroup Label="ExtensionTargets"> |
||||
|
</ImportGroup> |
||||
|
<ProjectExtensions> |
||||
|
<VisualStudio> |
||||
|
<UserProperties RESOURCE_FILE="Demo_MFC.rc" /> |
||||
|
</VisualStudio> |
||||
|
</ProjectExtensions> |
||||
|
</Project> |
||||
@ -0,0 +1,63 @@ |
|||||
|
<?xml version="1.0" encoding="utf-8"?> |
||||
|
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> |
||||
|
<ItemGroup> |
||||
|
<Filter Include="源文件"> |
||||
|
<UniqueIdentifier>{4FC737F1-C7A5-4376-A066-2A32D752A2FF}</UniqueIdentifier> |
||||
|
<Extensions>cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx</Extensions> |
||||
|
</Filter> |
||||
|
<Filter Include="头文件"> |
||||
|
<UniqueIdentifier>{93995380-89BD-4b04-88EB-625FBE52EBFB}</UniqueIdentifier> |
||||
|
<Extensions>h;hpp;hxx;hm;inl;inc;xsd</Extensions> |
||||
|
</Filter> |
||||
|
<Filter Include="资源文件"> |
||||
|
<UniqueIdentifier>{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}</UniqueIdentifier> |
||||
|
<Extensions>rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms</Extensions> |
||||
|
</Filter> |
||||
|
</ItemGroup> |
||||
|
<ItemGroup> |
||||
|
<Text Include="ReadMe.txt" /> |
||||
|
</ItemGroup> |
||||
|
<ItemGroup> |
||||
|
<ClInclude Include="Demo_MFC.h"> |
||||
|
<Filter>头文件</Filter> |
||||
|
</ClInclude> |
||||
|
<ClInclude Include="Demo_MFCDlg.h"> |
||||
|
<Filter>头文件</Filter> |
||||
|
</ClInclude> |
||||
|
<ClInclude Include="stdafx.h"> |
||||
|
<Filter>头文件</Filter> |
||||
|
</ClInclude> |
||||
|
<ClInclude Include="targetver.h"> |
||||
|
<Filter>头文件</Filter> |
||||
|
</ClInclude> |
||||
|
<ClInclude Include="Resource.h"> |
||||
|
<Filter>头文件</Filter> |
||||
|
</ClInclude> |
||||
|
</ItemGroup> |
||||
|
<ItemGroup> |
||||
|
<ClCompile Include="Demo_MFC.cpp"> |
||||
|
<Filter>源文件</Filter> |
||||
|
</ClCompile> |
||||
|
<ClCompile Include="Demo_MFCDlg.cpp"> |
||||
|
<Filter>源文件</Filter> |
||||
|
</ClCompile> |
||||
|
<ClCompile Include="stdafx.cpp"> |
||||
|
<Filter>源文件</Filter> |
||||
|
</ClCompile> |
||||
|
</ItemGroup> |
||||
|
<ItemGroup> |
||||
|
<ResourceCompile Include="Demo_MFC.rc"> |
||||
|
<Filter>资源文件</Filter> |
||||
|
</ResourceCompile> |
||||
|
</ItemGroup> |
||||
|
<ItemGroup> |
||||
|
<None Include="res\Demo_MFC.rc2"> |
||||
|
<Filter>资源文件</Filter> |
||||
|
</None> |
||||
|
</ItemGroup> |
||||
|
<ItemGroup> |
||||
|
<Image Include="res\Demo_MFC.ico"> |
||||
|
<Filter>资源文件</Filter> |
||||
|
</Image> |
||||
|
</ItemGroup> |
||||
|
</Project> |
||||
@ -0,0 +1,772 @@ |
|||||
|
|
||||
|
// Demo_MFCDlg.cpp : 实现文件
|
||||
|
//
|
||||
|
|
||||
|
#include "stdafx.h" |
||||
|
#include "Demo_MFC.h" |
||||
|
#include "Demo_MFCDlg.h" |
||||
|
#include "afxdialogex.h" |
||||
|
#include "CWFaceConfig.h" |
||||
|
#include "CWFaceDetection.h" |
||||
|
#include "CWFaceRecognition.h" |
||||
|
#include "CWFaceVersion.h" |
||||
|
|
||||
|
|
||||
|
#define MAX_NUM_FACES 3 // 检测的人脸数
|
||||
|
#define MAX_DET_NUM_FACES 10 // 检测线程的人脸数
|
||||
|
#define VERIFY_SHRELHOD 70 // 比对阈值
|
||||
|
#define CW_LICENCE "" // 云从授权码
|
||||
|
|
||||
|
#define WM_THREAD_SHOWVIDEO WM_USER + 101 // 自定义消息
|
||||
|
|
||||
|
//线条颜色,画框的
|
||||
|
static cv::Scalar& color = cv::Scalar(0, 0, 255); |
||||
|
static cv::Scalar& colorGreen = cv::Scalar(0, 255, 0); |
||||
|
|
||||
|
#ifdef _DEBUG |
||||
|
#define new DEBUG_NEW |
||||
|
#endif |
||||
|
|
||||
|
|
||||
|
// CDemo_MFCDlg 对话框
|
||||
|
|
||||
|
|
||||
|
|
||||
|
CDemo_MFCDlg::CDemo_MFCDlg(CWnd* pParent /*=NULL*/) |
||||
|
: CDialogEx(CDemo_MFCDlg::IDD, pParent) |
||||
|
{ |
||||
|
m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME); |
||||
|
m_pDetHandle = nullptr; |
||||
|
m_pDetVerify = nullptr; |
||||
|
m_pRecogHandle = nullptr; |
||||
|
m_bStartThread = false; |
||||
|
} |
||||
|
|
||||
|
void CDemo_MFCDlg::DoDataExchange(CDataExchange* pDX) |
||||
|
{ |
||||
|
CDialogEx::DoDataExchange(pDX); |
||||
|
DDX_Control(pDX, IDC_EDIT_SCORE, m_edtVerifyScore); |
||||
|
DDX_Control(pDX, IDC_EDIT_RESULT, m_edtVerifyResult); |
||||
|
DDX_Control(pDX, IDC_EDIT_TIME, m_edtVerifyTime); |
||||
|
DDX_Control(pDX, IDC_STATIC_PIC1, m_staticPic1); |
||||
|
DDX_Control(pDX, IDC_STATIC_PIC2, m_staticPic2); |
||||
|
DDX_Control(pDX, IDC_EDIT_VERSION, m_edtVersion); |
||||
|
DDX_Control(pDX, IDC_STATIC_VIDEO, m_staticVideo); |
||||
|
DDX_Control(pDX, IDC_STATIC_PIC3, m_staticPic3); |
||||
|
DDX_Control(pDX, IDC_EDIT_FACEBUF, m_edtFaceBuf); |
||||
|
} |
||||
|
|
||||
|
BEGIN_MESSAGE_MAP(CDemo_MFCDlg, CDialogEx) |
||||
|
ON_WM_PAINT() |
||||
|
ON_WM_QUERYDRAGICON() |
||||
|
ON_BN_CLICKED(IDC_BTN_LOAD1, &CDemo_MFCDlg::OnBnClickedBtnLoad1) |
||||
|
ON_BN_CLICKED(IDC_BTN_LOAD2, &CDemo_MFCDlg::OnBnClickedBtnLoad2) |
||||
|
ON_BN_CLICKED(IDC_BTN_VERIFY, &CDemo_MFCDlg::OnBnClickedBtnVerify) |
||||
|
ON_BN_CLICKED(IDC_BTN_INIT, &CDemo_MFCDlg::OnBnClickedBtnInit) |
||||
|
ON_BN_CLICKED(IDC_BTN_CAMERA1, &CDemo_MFCDlg::OnBnClickedBtnCamera1) |
||||
|
ON_BN_CLICKED(IDC_BTN_CAMERA2, &CDemo_MFCDlg::OnBnClickedBtnCamera2) |
||||
|
ON_BN_CLICKED(IDC_BTN_OPENUSB, &CDemo_MFCDlg::OnBnClickedBtnOpenusb) |
||||
|
ON_MESSAGE(WM_THREAD_SHOWVIDEO, &CDemo_MFCDlg::OnThreadShowVideo) |
||||
|
ON_BN_CLICKED(IDC_BTN_DET, &CDemo_MFCDlg::OnBnClickedBtnDet) |
||||
|
ON_BN_CLICKED(IDC_BTN_LOAD3, &CDemo_MFCDlg::OnBnClickedBtnLoad3) |
||||
|
END_MESSAGE_MAP() |
||||
|
|
||||
|
|
||||
|
// CDemo_MFCDlg 消息处理程序
|
||||
|
|
||||
|
BOOL CDemo_MFCDlg::OnInitDialog() |
||||
|
{ |
||||
|
CDialogEx::OnInitDialog(); |
||||
|
|
||||
|
// 设置此对话框的图标。当应用程序主窗口不是对话框时,框架将自动
|
||||
|
// 执行此操作
|
||||
|
SetIcon(m_hIcon, TRUE); // 设置大图标
|
||||
|
SetIcon(m_hIcon, FALSE); // 设置小图标
|
||||
|
|
||||
|
// TODO: 在此添加额外的初始化代码
|
||||
|
|
||||
|
m_staticPic1.GetClientRect(&m_rectPic1); |
||||
|
m_hDCPic1 = m_staticPic1.GetDC()->GetSafeHdc(); |
||||
|
|
||||
|
m_staticPic2.GetClientRect(&m_rectPic2); |
||||
|
m_hDCPic2 = m_staticPic2.GetDC()->GetSafeHdc(); |
||||
|
|
||||
|
m_staticPic3.GetClientRect(&m_rectPic3); |
||||
|
m_hDCPic3 = m_staticPic3.GetDC()->GetSafeHdc(); |
||||
|
|
||||
|
m_staticVideo.GetClientRect(&m_rectVideo); |
||||
|
m_hDCVideo = m_staticVideo.GetDC()->GetSafeHdc(); |
||||
|
|
||||
|
return TRUE; // 除非将焦点设置到控件,否则返回 TRUE
|
||||
|
} |
||||
|
|
||||
|
// 如果向对话框添加最小化按钮,则需要下面的代码
|
||||
|
// 来绘制该图标。对于使用文档/视图模型的 MFC 应用程序,
|
||||
|
// 这将由框架自动完成。
|
||||
|
|
||||
|
void CDemo_MFCDlg::OnPaint() |
||||
|
{ |
||||
|
if (IsIconic()) |
||||
|
{ |
||||
|
CPaintDC dc(this); // 用于绘制的设备上下文
|
||||
|
|
||||
|
SendMessage(WM_ICONERASEBKGND, reinterpret_cast<WPARAM>(dc.GetSafeHdc()), 0); |
||||
|
|
||||
|
// 使图标在工作区矩形中居中
|
||||
|
int cxIcon = GetSystemMetrics(SM_CXICON); |
||||
|
int cyIcon = GetSystemMetrics(SM_CYICON); |
||||
|
CRect rect; |
||||
|
GetClientRect(&rect); |
||||
|
int x = (rect.Width() - cxIcon + 1) / 2; |
||||
|
int y = (rect.Height() - cyIcon + 1) / 2; |
||||
|
|
||||
|
// 绘制图标
|
||||
|
dc.DrawIcon(x, y, m_hIcon); |
||||
|
} |
||||
|
else |
||||
|
{ |
||||
|
CDialogEx::OnPaint(); |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
//当用户拖动最小化窗口时系统调用此函数取得光标
|
||||
|
//显示。
|
||||
|
HCURSOR CDemo_MFCDlg::OnQueryDragIcon() |
||||
|
{ |
||||
|
return static_cast<HCURSOR>(m_hIcon); |
||||
|
} |
||||
|
|
||||
|
|
||||
|
// [3/3/2017 Lit]:导入图片1
|
||||
|
void CDemo_MFCDlg::OnBnClickedBtnLoad1() |
||||
|
{ |
||||
|
// TODO: 在此添加控件通知处理程序代码
|
||||
|
CFileDialog dlg(TRUE, _T("jpg|bmp|png"), NULL, OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT, |
||||
|
_T("Image Files(*.jpg;*.bmp;*.png)|*.jpg;*.bmp;*.png|All Files(*.*)|*.*||"), this); |
||||
|
if (IDOK != dlg.DoModal()) |
||||
|
{ |
||||
|
return; |
||||
|
} |
||||
|
|
||||
|
m_sPic1Path = dlg.GetPathName(); |
||||
|
ShowImg(m_sPic1Path, m_hDCPic1, m_rectPic1); |
||||
|
} |
||||
|
|
||||
|
// [3/3/2017 Lit]:导入图片2
|
||||
|
void CDemo_MFCDlg::OnBnClickedBtnLoad2() |
||||
|
{ |
||||
|
// TODO: 在此添加控件通知处理程序代码
|
||||
|
CFileDialog dlg(TRUE, _T("jpg|bmp|png"), NULL, OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT, |
||||
|
_T("Image Files(*.jpg;*.bmp;*.png)|*.jpg;*.bmp;*.png|All Files(*.*)|*.*||"), this); |
||||
|
if (IDOK != dlg.DoModal()) |
||||
|
{ |
||||
|
return; |
||||
|
} |
||||
|
|
||||
|
m_sPic2Path = dlg.GetPathName(); |
||||
|
ShowImg(m_sPic2Path, m_hDCPic2, m_rectPic2); |
||||
|
} |
||||
|
|
||||
|
// [3/30/2017 Lit]:给图片1拍照
|
||||
|
void CDemo_MFCDlg::OnBnClickedBtnCamera1() |
||||
|
{ |
||||
|
// TODO: 在此添加控件通知处理程序代码
|
||||
|
if (!m_bStartThread) |
||||
|
{ |
||||
|
MessageBox(_T("请先打开摄像头")); |
||||
|
return; |
||||
|
} |
||||
|
|
||||
|
{ |
||||
|
std::lock_guard<std::mutex> lock(m_mutex); |
||||
|
if (!m_matFrame.empty()) |
||||
|
{ |
||||
|
cv::imwrite("./1.jpg", m_matFrame); |
||||
|
} |
||||
|
else |
||||
|
{ |
||||
|
return; |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
m_sPic1Path = "./1.jpg"; |
||||
|
ShowImg(m_sPic1Path, m_hDCPic1, m_rectPic1); |
||||
|
} |
||||
|
|
||||
|
// [3/30/2017 Lit]:给图片2拍照
|
||||
|
void CDemo_MFCDlg::OnBnClickedBtnCamera2() |
||||
|
{ |
||||
|
// TODO: 在此添加控件通知处理程序代码
|
||||
|
if (!m_bStartThread) |
||||
|
{ |
||||
|
MessageBox(_T("请先打开摄像头")); |
||||
|
return; |
||||
|
} |
||||
|
|
||||
|
{ |
||||
|
std::lock_guard<std::mutex> lock(m_mutex); |
||||
|
if (!m_matFrame.empty()) |
||||
|
{ |
||||
|
cv::imwrite("./2.jpg", m_matFrame); |
||||
|
} |
||||
|
else |
||||
|
{ |
||||
|
return; |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
m_sPic2Path = "./2.jpg"; |
||||
|
ShowImg(m_sPic2Path, m_hDCPic2, m_rectPic2); |
||||
|
} |
||||
|
|
||||
|
// [3/14/2017 Lit]:初始化事件
|
||||
|
void CDemo_MFCDlg::OnBnClickedBtnInit() |
||||
|
{ |
||||
|
// TODO: 在此添加控件通知处理程序代码
|
||||
|
char szVersion[100] = {0}; |
||||
|
cw_errcode_t errCode = cwGetSDKVersion(szVersion, 100); |
||||
|
m_edtVersion.SetWindowText((CString)szVersion); |
||||
|
|
||||
|
// [3/3/2017 Lit]:创建句柄
|
||||
|
if (m_pDetHandle != nullptr && m_pDetVerify != nullptr && m_pRecogHandle != nullptr) |
||||
|
{ |
||||
|
MessageBox(_T("已初始化过,不再初始化")); |
||||
|
return; |
||||
|
} |
||||
|
|
||||
|
if (CreateFaceHandle()) |
||||
|
{ |
||||
|
MessageBox(_T("初始化成功")); |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
// [3/30/2017 Lit]:打开摄像头,开启检测线程
|
||||
|
void CDemo_MFCDlg::OnBnClickedBtnOpenusb() |
||||
|
{ |
||||
|
// TODO: 在此添加控件通知处理程序代码
|
||||
|
if (nullptr == m_pDetHandle) |
||||
|
{ |
||||
|
MessageBox(_T("检测句柄为空,请先初始化创建句柄")); |
||||
|
return; |
||||
|
} |
||||
|
if (m_bStartThread) |
||||
|
{ |
||||
|
MessageBox(_T("摄像头已打开")); |
||||
|
return; |
||||
|
} |
||||
|
|
||||
|
if (!m_capture.open(0)) |
||||
|
{ |
||||
|
MessageBox(_T("摄像头打开失败")); |
||||
|
return; |
||||
|
} |
||||
|
|
||||
|
m_bStartThread = true; |
||||
|
m_threadFaceDet = std::thread(&CDemo_MFCDlg::ThreadFaceDet, this); |
||||
|
m_threadFaceDet.detach(); |
||||
|
} |
||||
|
|
||||
|
void CDemo_MFCDlg::ThreadFaceDet() |
||||
|
{ |
||||
|
cv::Mat matImage; |
||||
|
cw_face_res_t faceBuffers[MAX_DET_NUM_FACES]; |
||||
|
while (m_bStartThread) |
||||
|
{ |
||||
|
{ |
||||
|
std::lock_guard<std::mutex> lock(m_mutex); |
||||
|
m_capture >> m_matFrame; |
||||
|
if (m_matFrame.empty()) |
||||
|
{ |
||||
|
continue; |
||||
|
} |
||||
|
matImage = m_matFrame.clone(); |
||||
|
} |
||||
|
|
||||
|
// 给图像结构体赋值
|
||||
|
cw_img_t srcImg; |
||||
|
srcImg.frameId = 0; |
||||
|
srcImg.data = (char*)matImage.data; |
||||
|
srcImg.width = matImage.cols; |
||||
|
srcImg.height = matImage.rows; |
||||
|
srcImg.angle = CW_IMAGE_ANGLE_0; |
||||
|
if (matImage.channels() ==1 ) |
||||
|
{ |
||||
|
srcImg.format = CW_IMAGE_GRAY8; |
||||
|
} |
||||
|
else if (matImage.channels() == 3) |
||||
|
{ |
||||
|
srcImg.format = CW_IMAGE_BGR888; |
||||
|
} |
||||
|
else if (matImage.channels() == 4) |
||||
|
{ |
||||
|
srcImg.format = CW_IMAGE_BGRA8888; |
||||
|
} |
||||
|
else |
||||
|
{ |
||||
|
continue; |
||||
|
} |
||||
|
|
||||
|
// 人脸检测
|
||||
|
int iFaceNum = 0; |
||||
|
cw_errcode_t errCode = cwFaceDetection(m_pDetHandle, &srcImg, faceBuffers, MAX_DET_NUM_FACES, &iFaceNum, CW_OP_DET); |
||||
|
for (int i = 0; i < iFaceNum; i++) |
||||
|
{ |
||||
|
cv::Point dst1(faceBuffers[i].faceRect.x, faceBuffers[i].faceRect.y); |
||||
|
cv::Point dst2(faceBuffers[i].faceRect.x + faceBuffers[i].faceRect.width, faceBuffers[i].faceRect.y + faceBuffers[i].faceRect.height); |
||||
|
//画框
|
||||
|
cv::rectangle(matImage, dst1, dst2, color, 3); |
||||
|
} |
||||
|
|
||||
|
SendMessage(WM_THREAD_SHOWVIDEO, 0, (LPARAM)&matImage); |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
LRESULT CDemo_MFCDlg::OnThreadShowVideo(WPARAM wPapam, LPARAM lPapam) |
||||
|
{ |
||||
|
cv::Mat matImage = *((cv::Mat*)lPapam); |
||||
|
if (!matImage.empty()) |
||||
|
{ |
||||
|
ShowVideo((char*)(matImage.data), matImage.cols, matImage.rows); |
||||
|
} |
||||
|
|
||||
|
return 0; |
||||
|
} |
||||
|
|
||||
|
// [3/3/2017 Lit]:人脸比对
|
||||
|
void CDemo_MFCDlg::OnBnClickedBtnVerify() |
||||
|
{ |
||||
|
// TODO: 在此添加控件通知处理程序代码
|
||||
|
if (m_sPic1Path.IsEmpty()) |
||||
|
{ |
||||
|
MessageBox(_T("请先导入第一张图")); |
||||
|
return; |
||||
|
} |
||||
|
if (m_sPic2Path.IsEmpty()) |
||||
|
{ |
||||
|
MessageBox(_T("请先导入第二张图")); |
||||
|
return; |
||||
|
} |
||||
|
|
||||
|
if (m_pDetVerify == nullptr) |
||||
|
{ |
||||
|
MessageBox(_T("检测句柄为空,请先初始化创建句柄")); |
||||
|
return; |
||||
|
} |
||||
|
if (m_pRecogHandle == nullptr) |
||||
|
{ |
||||
|
MessageBox(_T("识别句柄为空,请先初始化创建句柄")); |
||||
|
return; |
||||
|
} |
||||
|
|
||||
|
m_edtVerifyScore.SetWindowText(_T("")); |
||||
|
m_edtVerifyResult.SetWindowText(_T("")); |
||||
|
m_edtVerifyTime.SetWindowText(_T("")); |
||||
|
|
||||
|
DWORD tmBegin = GetTickCount(); |
||||
|
|
||||
|
int iFeaLen = cwGetFeatureLength(m_pRecogHandle); |
||||
|
char *pFeaFiled = new char[iFeaLen]; |
||||
|
if (0 == GetFeatureFromPath(m_sPic1Path, pFeaFiled)) |
||||
|
{ |
||||
|
char *pFeaProbe = new char[iFeaLen]; |
||||
|
if (0 == GetFeatureFromPath(m_sPic2Path, pFeaProbe)) |
||||
|
{ |
||||
|
float scores[1] = {0.0}; |
||||
|
cw_errcode_t errCode = cwComputeMatchScore(m_pRecogHandle, pFeaProbe, pFeaFiled, 1, scores); |
||||
|
if (CW_SDKLIT_OK == errCode) |
||||
|
{ |
||||
|
CString sScore, sResult, sTime; |
||||
|
sScore.Format(_T("%.6f"), scores[0]); |
||||
|
sTime.Format(_T("%d ms"), GetTickCount() - tmBegin); |
||||
|
if (int(scores[0] * 100) > VERIFY_SHRELHOD) |
||||
|
{ |
||||
|
sResult = _T("比对通过"); |
||||
|
} |
||||
|
else |
||||
|
{ |
||||
|
sResult = _T("比对不通过"); |
||||
|
} |
||||
|
|
||||
|
m_edtVerifyScore.SetWindowText(sScore); |
||||
|
m_edtVerifyResult.SetWindowText(sResult); |
||||
|
m_edtVerifyTime.SetWindowText(sTime); |
||||
|
} |
||||
|
else |
||||
|
{ |
||||
|
CString sTip; |
||||
|
sTip.Format(_T("比对错误:%d"), errCode); |
||||
|
MessageBox(sTip); |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
delete[] pFeaProbe; |
||||
|
pFeaProbe = nullptr; |
||||
|
} |
||||
|
|
||||
|
delete[] pFeaFiled; |
||||
|
pFeaFiled = nullptr; |
||||
|
} |
||||
|
|
||||
|
|
||||
|
void CDemo_MFCDlg::OnBnClickedBtnLoad3() |
||||
|
{ |
||||
|
// TODO: 在此添加控件通知处理程序代码
|
||||
|
CFileDialog dlg(TRUE, _T("jpg|bmp|png"), NULL, OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT, |
||||
|
_T("Image Files(*.jpg;*.bmp;*.png)|*.jpg;*.bmp;*.png|All Files(*.*)|*.*||"), this); |
||||
|
if (IDOK != dlg.DoModal()) |
||||
|
{ |
||||
|
return; |
||||
|
} |
||||
|
|
||||
|
m_sPic3Path = dlg.GetPathName(); |
||||
|
ShowImg(m_sPic3Path, m_hDCPic3, m_rectPic3); |
||||
|
} |
||||
|
|
||||
|
|
||||
|
// [7/19/2017 Lit]:人脸检测,关键点,质量分
|
||||
|
void CDemo_MFCDlg::OnBnClickedBtnDet() |
||||
|
{ |
||||
|
// TODO: 在此添加控件通知处理程序代码
|
||||
|
if (m_pDetVerify == nullptr) |
||||
|
{ |
||||
|
MessageBox(_T("检测句柄为空,请先初始化创建句柄")); |
||||
|
return; |
||||
|
} |
||||
|
|
||||
|
if (m_sPic3Path.IsEmpty()) |
||||
|
{ |
||||
|
MessageBox(_T("请先导入人脸图片")); |
||||
|
return; |
||||
|
} |
||||
|
|
||||
|
cv::Mat matImage = cv::imread((std::string)(_bstr_t)(LPCWSTR)m_sPic3Path); |
||||
|
if (matImage.empty()) |
||||
|
{ |
||||
|
MessageBox(_T("Pic Not Found")); |
||||
|
return; |
||||
|
} |
||||
|
|
||||
|
m_edtFaceBuf.SetWindowText(_T("")); |
||||
|
|
||||
|
// 给图像结构体赋值
|
||||
|
cw_img_t srcImg; |
||||
|
srcImg.frameId = 0; |
||||
|
srcImg.data = (char*)matImage.data; |
||||
|
srcImg.width = matImage.cols; |
||||
|
srcImg.height = matImage.rows; |
||||
|
srcImg.angle = CW_IMAGE_ANGLE_0; |
||||
|
if (matImage.channels()==1) |
||||
|
{ |
||||
|
srcImg.format = CW_IMAGE_GRAY8; |
||||
|
} |
||||
|
else if (matImage.channels()==3) |
||||
|
{ |
||||
|
srcImg.format = CW_IMAGE_BGR888; |
||||
|
} |
||||
|
else if (matImage.channels()==4) |
||||
|
{ |
||||
|
srcImg.format = CW_IMAGE_BGRA8888; |
||||
|
} |
||||
|
else |
||||
|
{ |
||||
|
MessageBox(_T("Pic Error")); |
||||
|
return; |
||||
|
} |
||||
|
|
||||
|
// 此处最多检测20张人脸
|
||||
|
cw_face_res_t faceBuffers[20]; |
||||
|
int iFaceNum = 0; |
||||
|
DWORD tmBegin = GetTickCount(); |
||||
|
// 人脸检测,关键点,质量分
|
||||
|
cw_errcode_t errCode = cwFaceDetection(m_pDetVerify, &srcImg, faceBuffers, 20, &iFaceNum, CW_OP_DET | CW_OP_QUALITY); |
||||
|
if (errCode != CW_SDKLIT_OK) |
||||
|
{ |
||||
|
CString sTip; |
||||
|
sTip.Format(_T("Face detect Error, Code: %d"), errCode); |
||||
|
MessageBox(sTip); |
||||
|
return; |
||||
|
} |
||||
|
if (iFaceNum < 1) |
||||
|
{ |
||||
|
MessageBox(_T("未检测到人脸")); |
||||
|
return; |
||||
|
} |
||||
|
|
||||
|
CString sFaceRet; |
||||
|
sFaceRet.Format(_T("Face Num: %d; Time: %d ms"), iFaceNum, GetTickCount() - tmBegin); |
||||
|
|
||||
|
// 人脸画框
|
||||
|
for (int i = 0; i < iFaceNum; i++) |
||||
|
{ |
||||
|
cv::Point dst1(faceBuffers[i].faceRect.x, faceBuffers[i].faceRect.y); |
||||
|
cv::Point dst2(faceBuffers[i].faceRect.x + faceBuffers[i].faceRect.width, faceBuffers[i].faceRect.y + faceBuffers[i].faceRect.height); |
||||
|
//画框
|
||||
|
cv::rectangle(matImage, dst1, dst2, colorGreen, 3); |
||||
|
|
||||
|
CString sCurFace; |
||||
|
sCurFace.Format(_T("\r\n\r\nFace%d: Rect: %d, %d, %d, %d; Quality: %f"), i + 1, faceBuffers[i].faceRect.x, faceBuffers[i].faceRect.y, |
||||
|
faceBuffers[i].faceRect.width, faceBuffers[i].faceRect.height,faceBuffers[i].quality.scores[0]); |
||||
|
sFaceRet += sCurFace; |
||||
|
} |
||||
|
|
||||
|
m_edtFaceBuf.SetWindowText(sFaceRet); |
||||
|
|
||||
|
cv::imwrite("tempDet.jpg", matImage); |
||||
|
ShowImg(_T("tempDet.jpg"), m_hDCPic3, m_rectPic3); |
||||
|
} |
||||
|
|
||||
|
|
||||
|
// [3/3/2017 Lit]:通过图片路径获取图片特征
|
||||
|
int CDemo_MFCDlg::GetFeatureFromPath(const CString &sPath, void* pFeatueData) |
||||
|
{ |
||||
|
cv::Mat matImage = cv::imread((std::string)(_bstr_t)(LPCWSTR)sPath); |
||||
|
if (matImage.empty()) |
||||
|
{ |
||||
|
MessageBox(_T("Pic Not Found")); |
||||
|
return -1; |
||||
|
} |
||||
|
|
||||
|
// 给图像结构体赋值
|
||||
|
cw_img_t srcImg; |
||||
|
srcImg.frameId = 0; |
||||
|
srcImg.data = (char*)matImage.data; |
||||
|
srcImg.width = matImage.cols; |
||||
|
srcImg.height = matImage.rows; |
||||
|
srcImg.angle = CW_IMAGE_ANGLE_0; |
||||
|
if (matImage.channels()==1) |
||||
|
{ |
||||
|
srcImg.format = CW_IMAGE_GRAY8; |
||||
|
} |
||||
|
else if (matImage.channels()==3) |
||||
|
{ |
||||
|
srcImg.format = CW_IMAGE_BGR888; |
||||
|
} |
||||
|
else if (matImage.channels()==4) |
||||
|
{ |
||||
|
srcImg.format = CW_IMAGE_BGRA8888; |
||||
|
} |
||||
|
else |
||||
|
{ |
||||
|
MessageBox(_T("Pic Error")); |
||||
|
return -1; |
||||
|
} |
||||
|
|
||||
|
cw_face_res_t faceBuffers[MAX_NUM_FACES]; |
||||
|
int iFaceNum = 0; |
||||
|
// 人脸检测,获取对齐人脸
|
||||
|
cw_errcode_t errCode = cwFaceDetection(m_pDetVerify, &srcImg, faceBuffers, MAX_NUM_FACES, &iFaceNum, CW_OP_DET | CW_OP_ALIGN); |
||||
|
if (errCode != CW_SDKLIT_OK) |
||||
|
{ |
||||
|
CString sErrTip; |
||||
|
sErrTip.Format(_T("Face detect Error, Code: %d"), errCode); |
||||
|
MessageBox(sErrTip); |
||||
|
return -1; |
||||
|
} |
||||
|
if (iFaceNum < 1) |
||||
|
{ |
||||
|
MessageBox(_T("未检测到人脸")); |
||||
|
return -1; |
||||
|
} |
||||
|
|
||||
|
errCode = cwGetFaceFeature(m_pRecogHandle, &faceBuffers[0].faceAligned, pFeatueData); |
||||
|
if (CW_SDKLIT_OK != errCode) |
||||
|
{ |
||||
|
CString sErrTip; |
||||
|
sErrTip.Format(_T("Get Feature Error, Code: %d"), errCode); |
||||
|
MessageBox(sErrTip); |
||||
|
return -1; |
||||
|
} |
||||
|
|
||||
|
return 0; |
||||
|
} |
||||
|
|
||||
|
bool CDemo_MFCDlg::CreateFaceHandle() |
||||
|
{ |
||||
|
// 32位和64位检测模型不能共用,64位用_configs_frontend.xml,非64位用_configs_frontend_x86_arm.xml
|
||||
|
#ifdef DEMO_X64 |
||||
|
std::string sModelXmlPath = "../../CWModels/_configs_frontend.xml"; |
||||
|
#else |
||||
|
std::string sModelXmlPath = "../../CWModels/_configs_frontend_x86_arm.xml"; |
||||
|
#endif // DEMO_X64
|
||||
|
|
||||
|
CString sErrorTip; |
||||
|
cw_errcode_t errCode = CW_SDKLIT_OK; |
||||
|
if (m_pDetHandle != nullptr) |
||||
|
{ |
||||
|
MessageBox(_T("检测句柄1已创建过,不再创建")); |
||||
|
} |
||||
|
else |
||||
|
{ |
||||
|
m_pDetHandle = cwCreateDetHandle(&errCode, sModelXmlPath.c_str(), CW_LICENCE); |
||||
|
if (CW_SDKLIT_OK != errCode || nullptr == m_pDetHandle) |
||||
|
{ |
||||
|
sErrorTip.Format(_T("创建检测句柄1错误,错误码:%d"), errCode); |
||||
|
MessageBox(sErrorTip); |
||||
|
return false; |
||||
|
} |
||||
|
|
||||
|
cw_det_param_t param; |
||||
|
cwGetFaceParam(m_pDetHandle, ¶m); |
||||
|
param.minSize = 48; |
||||
|
param.maxSize = 600; //摄像头大小
|
||||
|
param.pConfigFile = sModelXmlPath.c_str(); // 设置接口功能参数
|
||||
|
cwSetFaceParam(m_pDetHandle, ¶m); |
||||
|
} |
||||
|
|
||||
|
if (m_pDetVerify != nullptr) |
||||
|
{ |
||||
|
MessageBox(_T("检测句柄2已创建过,不再创建")); |
||||
|
} |
||||
|
else |
||||
|
{ |
||||
|
m_pDetVerify = cwCreateDetHandle(&errCode, sModelXmlPath.c_str(), CW_LICENCE); |
||||
|
if (CW_SDKLIT_OK != errCode || nullptr == m_pDetVerify) |
||||
|
{ |
||||
|
sErrorTip.Format(_T("创建检测句柄2错误,错误码:%d"), errCode); |
||||
|
MessageBox(sErrorTip); |
||||
|
return false; |
||||
|
} |
||||
|
|
||||
|
cw_det_param_t param; |
||||
|
cwGetFaceParam(m_pDetVerify, ¶m); |
||||
|
param.minSize = 30; |
||||
|
param.maxSize = 1000; //设置人脸大小
|
||||
|
param.pConfigFile = sModelXmlPath.c_str(); // 设置接口功能参数
|
||||
|
cwSetFaceParam(m_pDetVerify, ¶m); |
||||
|
} |
||||
|
|
||||
|
if (m_pRecogHandle != nullptr) |
||||
|
{ |
||||
|
MessageBox(_T("识别句柄已创建过,不再创建")); |
||||
|
} |
||||
|
else |
||||
|
{ |
||||
|
m_pRecogHandle = cwCreateRecogHandle(&errCode, "../../CWModels/CWR_Config_1_1.xml", CW_LICENCE, CW_FEATURE_EXTRACT); |
||||
|
if (CW_SDKLIT_OK != errCode || nullptr == m_pRecogHandle) |
||||
|
{ |
||||
|
sErrorTip.Format(_T("创建识别句柄错误,错误码:%d"), errCode); |
||||
|
MessageBox(sErrorTip); |
||||
|
return false; |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
return true; |
||||
|
} |
||||
|
|
||||
|
void CDemo_MFCDlg::ReleaseFaceHandle() |
||||
|
{ |
||||
|
m_bStartThread = false; |
||||
|
{ |
||||
|
std::lock_guard<std::mutex> lock(m_mutex); |
||||
|
m_capture.release(); |
||||
|
} |
||||
|
|
||||
|
/*
|
||||
|
if (m_threadFaceDet.joinable()) |
||||
|
{ |
||||
|
m_threadFaceDet.join(); |
||||
|
m_capture.release(); |
||||
|
}*/ |
||||
|
|
||||
|
// 程序退出时销毁句柄
|
||||
|
if (m_pDetHandle != nullptr) |
||||
|
{ |
||||
|
cwReleaseDetHandle(m_pDetHandle); |
||||
|
m_pDetHandle = nullptr; |
||||
|
} |
||||
|
if (m_pDetVerify != nullptr) |
||||
|
{ |
||||
|
cwReleaseDetHandle(m_pDetVerify); |
||||
|
m_pDetVerify = nullptr; |
||||
|
} |
||||
|
if (m_pRecogHandle != nullptr) |
||||
|
{ |
||||
|
cwReleaseRecogHandle(m_pRecogHandle); |
||||
|
m_pRecogHandle = nullptr; |
||||
|
} |
||||
|
|
||||
|
DeleteDC(m_hDCVideo); |
||||
|
DeleteDC(m_hDCPic1); |
||||
|
DeleteDC(m_hDCPic2); |
||||
|
DeleteDC(m_hDCPic3); |
||||
|
} |
||||
|
|
||||
|
|
||||
|
void CDemo_MFCDlg::PostNcDestroy() |
||||
|
{ |
||||
|
// TODO: 在此添加专用代码和/或调用基类
|
||||
|
// [3/3/2017 Lit]:程序退出时销毁句柄
|
||||
|
ReleaseFaceHandle(); |
||||
|
|
||||
|
CDialogEx::PostNcDestroy(); |
||||
|
} |
||||
|
|
||||
|
/************************************************************************/ |
||||
|
/* 显示视频 */ |
||||
|
/************************************************************************/ |
||||
|
void CDemo_MFCDlg::ShowVideo(char* szFrame, int iImgWidth, int iImgHeight) |
||||
|
{ |
||||
|
BITMAPINFO BmpInfo; |
||||
|
BmpInfo.bmiHeader.biSize = sizeof(BITMAPINFOHEADER); |
||||
|
BmpInfo.bmiHeader.biWidth = (LONG)iImgWidth; |
||||
|
BmpInfo.bmiHeader.biHeight = (LONG)iImgHeight; |
||||
|
|
||||
|
BmpInfo.bmiHeader.biPlanes = 1; |
||||
|
BmpInfo.bmiHeader.biBitCount = 24; |
||||
|
BmpInfo.bmiHeader.biCompression = BI_RGB; |
||||
|
BmpInfo.bmiHeader.biSizeImage = 0; |
||||
|
BmpInfo.bmiHeader.biXPelsPerMeter = 0; |
||||
|
BmpInfo.bmiHeader.biYPelsPerMeter = 0; |
||||
|
BmpInfo.bmiHeader.biClrUsed = 0; |
||||
|
BmpInfo.bmiHeader.biClrImportant = 0; |
||||
|
|
||||
|
SetStretchBltMode(m_hDCVideo, COLORONCOLOR); |
||||
|
StretchDIBits(m_hDCVideo, 0, (m_rectVideo.bottom - m_rectVideo.top), (m_rectVideo.right - m_rectVideo.left), (m_rectVideo.top - m_rectVideo.bottom), |
||||
|
0, 0, iImgWidth, iImgHeight, szFrame, &BmpInfo, DIB_RGB_COLORS, SRCCOPY); |
||||
|
} |
||||
|
|
||||
|
void CDemo_MFCDlg::ShowImg(CString sPicPath, HDC hDCVideo, RECT rectVideo) |
||||
|
{ |
||||
|
cv::Mat matImage = cv::imread((std::string)(_bstr_t)(LPCWSTR)sPicPath); |
||||
|
if (matImage.empty()) |
||||
|
{ |
||||
|
return; |
||||
|
} |
||||
|
if (matImage.channels() == 4) |
||||
|
{ |
||||
|
cv::Mat matTemp; |
||||
|
cv::cvtColor(matImage, matTemp, CV_BGRA2BGR); |
||||
|
matImage = matTemp.clone(); |
||||
|
} |
||||
|
|
||||
|
// 要显示宽度必须是4的倍数
|
||||
|
int iWidth = matImage.cols; |
||||
|
int iHeight = matImage.rows; |
||||
|
if (0 != iWidth % 4) |
||||
|
{ |
||||
|
iWidth = iWidth / 4 * 4; |
||||
|
int iWidthCut = matImage.cols - iWidth; |
||||
|
int iLeft = iWidthCut / 2; |
||||
|
int iRight = iWidth + iLeft; |
||||
|
matImage = matImage.colRange(iLeft, iRight).clone(); |
||||
|
} |
||||
|
|
||||
|
BITMAPINFO BmpInfo; |
||||
|
BmpInfo.bmiHeader.biSize = sizeof(BITMAPINFOHEADER); |
||||
|
BmpInfo.bmiHeader.biWidth = (LONG)iWidth; |
||||
|
BmpInfo.bmiHeader.biHeight = (LONG)iHeight; |
||||
|
|
||||
|
BmpInfo.bmiHeader.biPlanes = 1; |
||||
|
BmpInfo.bmiHeader.biBitCount = 24; |
||||
|
BmpInfo.bmiHeader.biCompression = BI_RGB; |
||||
|
BmpInfo.bmiHeader.biSizeImage = 0; |
||||
|
BmpInfo.bmiHeader.biXPelsPerMeter = 0; |
||||
|
BmpInfo.bmiHeader.biYPelsPerMeter = 0; |
||||
|
BmpInfo.bmiHeader.biClrUsed = 0; |
||||
|
BmpInfo.bmiHeader.biClrImportant = 0; |
||||
|
|
||||
|
SetStretchBltMode(hDCVideo, COLORONCOLOR); |
||||
|
StretchDIBits(hDCVideo, 0, (rectVideo.bottom - rectVideo.top), (rectVideo.right - rectVideo.left), (rectVideo.top - rectVideo.bottom), |
||||
|
0, 0, iWidth, iHeight, matImage.data, &BmpInfo, DIB_RGB_COLORS, SRCCOPY); |
||||
|
} |
||||
|
|
||||
@ -0,0 +1,103 @@ |
|||||
|
|
||||
|
// Demo_MFCDlg.h : 头文件
|
||||
|
//
|
||||
|
|
||||
|
#pragma once |
||||
|
#include "afxwin.h" |
||||
|
#include "opencv.hpp" |
||||
|
#include <mutex> |
||||
|
#include <thread> |
||||
|
|
||||
|
// CDemo_MFCDlg 对话框
|
||||
|
class CDemo_MFCDlg : public CDialogEx |
||||
|
{ |
||||
|
// 构造
|
||||
|
public: |
||||
|
CDemo_MFCDlg(CWnd* pParent = NULL); // 标准构造函数
|
||||
|
|
||||
|
// 对话框数据
|
||||
|
enum { IDD = IDD_DEMO_MFC_DIALOG }; |
||||
|
|
||||
|
protected: |
||||
|
virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV 支持
|
||||
|
|
||||
|
virtual void PostNcDestroy(); |
||||
|
|
||||
|
|
||||
|
// 实现
|
||||
|
protected: |
||||
|
HICON m_hIcon; |
||||
|
|
||||
|
// 生成的消息映射函数
|
||||
|
virtual BOOL OnInitDialog(); |
||||
|
afx_msg void OnPaint(); |
||||
|
afx_msg HCURSOR OnQueryDragIcon(); |
||||
|
|
||||
|
afx_msg void OnBnClickedBtnLoad1(); |
||||
|
afx_msg void OnBnClickedBtnLoad2(); |
||||
|
afx_msg void OnBnClickedBtnVerify(); |
||||
|
afx_msg void OnBnClickedBtnInit(); |
||||
|
afx_msg void OnBnClickedBtnCamera1(); |
||||
|
afx_msg void OnBnClickedBtnCamera2(); |
||||
|
afx_msg void OnBnClickedBtnOpenusb(); |
||||
|
afx_msg void OnBnClickedBtnLoad3(); |
||||
|
afx_msg void OnBnClickedBtnDet(); |
||||
|
|
||||
|
afx_msg LRESULT OnThreadShowVideo(WPARAM wPapam, LPARAM lPapam); |
||||
|
|
||||
|
DECLARE_MESSAGE_MAP() |
||||
|
|
||||
|
private: |
||||
|
// [3/3/2017 Lit]:通过图片路径获取图片特征
|
||||
|
int GetFeatureFromPath(const CString &sPath, void* pFeatueData); |
||||
|
|
||||
|
bool CreateFaceHandle(); |
||||
|
|
||||
|
void ReleaseFaceHandle(); |
||||
|
|
||||
|
void ThreadFaceDet(); |
||||
|
|
||||
|
void ShowVideo(char* szFrame,int iImgWidth,int iImgHeight); |
||||
|
|
||||
|
void ShowImg(CString sPicPath, HDC hDCVideo, RECT rectVideo); |
||||
|
|
||||
|
|
||||
|
private: |
||||
|
|
||||
|
void* m_pDetHandle; // 检测线程中的检测句柄
|
||||
|
void* m_pDetVerify; // 用于比对过程中的检测句柄
|
||||
|
void* m_pRecogHandle; // 识别句柄
|
||||
|
|
||||
|
CEdit m_edtVersion; |
||||
|
CEdit m_edtVerifyScore; |
||||
|
CEdit m_edtVerifyResult; |
||||
|
CEdit m_edtVerifyTime; |
||||
|
CEdit m_edtFaceBuf; |
||||
|
|
||||
|
CStatic m_staticVideo; // 显示USB摄像头的控件
|
||||
|
RECT m_rectVideo; |
||||
|
HDC m_hDCVideo; |
||||
|
|
||||
|
CStatic m_staticPic1; |
||||
|
RECT m_rectPic1; |
||||
|
HDC m_hDCPic1; |
||||
|
|
||||
|
CStatic m_staticPic2; |
||||
|
RECT m_rectPic2; |
||||
|
HDC m_hDCPic2; |
||||
|
|
||||
|
CStatic m_staticPic3; |
||||
|
RECT m_rectPic3; |
||||
|
HDC m_hDCPic3; |
||||
|
|
||||
|
cv::VideoCapture m_capture; // 摄像头操作对象
|
||||
|
cv::Mat m_matFrame; // 当前帧
|
||||
|
std::thread m_threadFaceDet; // 检测线程
|
||||
|
std::mutex m_mutex; // 锁
|
||||
|
|
||||
|
CString m_sPic1Path; // 图片1路径
|
||||
|
CString m_sPic2Path; // 图片2路径
|
||||
|
CString m_sPic3Path; // 图片3路径
|
||||
|
bool m_bStartThread; // 是否开启检测线程
|
||||
|
|
||||
|
}; |
||||
@ -0,0 +1,70 @@ |
|||||
|
================================================================================ |
||||
|
MICROSOFT 基础类库 : Demo_MFC 项目概述 |
||||
|
=============================================================================== |
||||
|
|
||||
|
应用程序向导已为您创建了此 Demo_MFC 应用程序。此应用程序不仅演示 Microsoft 基础类的基本使用方法,还可作为您编写应用程序的起点。 |
||||
|
|
||||
|
本文件概要介绍组成 Demo_MFC 应用程序的每个文件的内容。 |
||||
|
|
||||
|
Demo_MFC.vcxproj |
||||
|
这是使用应用程序向导生成的 VC++ 项目的主项目文件,其中包含生成该文件的 Visual C++ 的版本信息,以及有关使用应用程序向导选择的平台、配置和项目功能的信息。 |
||||
|
|
||||
|
Demo_MFC.vcxproj.filters |
||||
|
这是使用“应用程序向导”生成的 VC++ 项目筛选器文件。它包含有关项目文件与筛选器之间的关联信息。在 IDE 中,通过这种关联,在特定节点下以分组形式显示具有相似扩展名的文件。例如,“.cpp”文件与“源文件”筛选器关联。 |
||||
|
|
||||
|
Demo_MFC.h |
||||
|
这是应用程序的主头文件。 |
||||
|
其中包括其他项目特定的标头(包括 Resource.h),并声明 CDemo_MFCApp 应用程序类。 |
||||
|
|
||||
|
Demo_MFC.cpp |
||||
|
这是包含应用程序类 CDemo_MFCApp 的主应用程序源文件。 |
||||
|
|
||||
|
Demo_MFC.rc |
||||
|
这是程序使用的所有 Microsoft Windows 资源的列表。它包括 RES 子目录中存储的图标、位图和光标。此文件可以直接在 Microsoft Visual C++ 中进行编辑。项目资源包含在 2052 中。 |
||||
|
|
||||
|
res\Demo_MFC.ico |
||||
|
这是用作应用程序图标的图标文件。此图标包括在主资源文件 Demo_MFC.rc 中。 |
||||
|
|
||||
|
res\Demo_MFC.rc2 |
||||
|
此文件包含不在 Microsoft Visual C++ 中进行编辑的资源。您应该将不可由资源编辑器编辑的所有资源放在此文件中。 |
||||
|
|
||||
|
|
||||
|
///////////////////////////////////////////////////////////////////////////// |
||||
|
|
||||
|
应用程序向导创建一个对话框类: |
||||
|
|
||||
|
Demo_MFCDlg.h、Demo_MFCDlg.cpp - 对话框 |
||||
|
这些文件包含 CDemo_MFCDlg 类。此类定义应用程序的主对话框的行为。对话框模板包含在 Demo_MFC.rc 中,该文件可以在 Microsoft Visual C++ 中编辑。 |
||||
|
|
||||
|
///////////////////////////////////////////////////////////////////////////// |
||||
|
|
||||
|
其他功能: |
||||
|
|
||||
|
ActiveX 控件 |
||||
|
该应用程序包含对使用 ActiveX 控件的支持。 |
||||
|
|
||||
|
打印和打印预览支持 |
||||
|
应用程序向导通过从 MFC 库调用 CView 类中的成员函数生成代码,来处理打印、打印设置和打印预览命令。 |
||||
|
|
||||
|
///////////////////////////////////////////////////////////////////////////// |
||||
|
|
||||
|
其他标准文件: |
||||
|
|
||||
|
StdAfx.h, StdAfx.cpp |
||||
|
这些文件用于生成名为 Demo_MFC.pch 的预编译头 (PCH) 文件和名为 StdAfx.obj 的预编译类型文件。 |
||||
|
|
||||
|
Resource.h |
||||
|
这是标准头文件,可用于定义新的资源 ID。Microsoft Visual C++ 将读取并更新此文件。 |
||||
|
|
||||
|
Demo_MFC.manifest |
||||
|
Windows XP 使用应用程序清单文件来描述特定版本的并行程序集的应用程序依赖项。加载程序使用这些信息来从程序集缓存中加载相应的程序集,并保护其不被应用程序访问。应用程序清单可能会包含在内,以作为与应用程序可执行文件安装在同一文件夹中的外部 .manifest 文件进行重新分发,它还可能以资源的形式包含在可执行文件中。 |
||||
|
///////////////////////////////////////////////////////////////////////////// |
||||
|
|
||||
|
其他注释: |
||||
|
|
||||
|
应用程序向导使用“TODO:”来指示应添加或自定义的源代码部分。 |
||||
|
|
||||
|
如果应用程序使用共享 DLL 中的 MFC,您将需要重新分发 MFC DLL。如果应用程序所使用的语言与操作系统的区域设置不同,则还需要重新分发相应的本地化资源 mfc110XXX.DLL。 |
||||
|
有关上述话题的更多信息,请参见 MSDN 文档中有关重新分发 Visual C++ 应用程序的部分。 |
||||
|
|
||||
|
///////////////////////////////////////////////////////////////////////////// |
||||
@ -0,0 +1,73 @@ |
|||||
|
/*M///////////////////////////////////////////////////////////////////////////////////////
|
||||
|
//
|
||||
|
// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
|
||||
|
//
|
||||
|
// By downloading, copying, installing or using the software you agree to this license.
|
||||
|
// If you do not agree to this license, do not download, install,
|
||||
|
// copy or use the software.
|
||||
|
//
|
||||
|
//
|
||||
|
// License Agreement
|
||||
|
// For Open Source Computer Vision Library
|
||||
|
//
|
||||
|
// Copyright (C) 2000-2008, Intel Corporation, all rights reserved.
|
||||
|
// Copyright (C) 2009, Willow Garage Inc., all rights reserved.
|
||||
|
// Third party copyrights are property of their respective owners.
|
||||
|
//
|
||||
|
// Redistribution and use in source and binary forms, with or without modification,
|
||||
|
// are permitted provided that the following conditions are met:
|
||||
|
//
|
||||
|
// * Redistribution's of source code must retain the above copyright notice,
|
||||
|
// this list of conditions and the following disclaimer.
|
||||
|
//
|
||||
|
// * Redistribution's in binary form must reproduce the above copyright notice,
|
||||
|
// this list of conditions and the following disclaimer in the documentation
|
||||
|
// and/or other materials provided with the distribution.
|
||||
|
//
|
||||
|
// * The name of the copyright holders may not be used to endorse or promote products
|
||||
|
// derived from this software without specific prior written permission.
|
||||
|
//
|
||||
|
// This software is provided by the copyright holders and contributors "as is" and
|
||||
|
// any express or implied warranties, including, but not limited to, the implied
|
||||
|
// warranties of merchantability and fitness for a particular purpose are disclaimed.
|
||||
|
// In no event shall the Intel Corporation or contributors be liable for any direct,
|
||||
|
// indirect, incidental, special, exemplary, or consequential damages
|
||||
|
// (including, but not limited to, procurement of substitute goods or services;
|
||||
|
// loss of use, data, or profits; or business interruption) however caused
|
||||
|
// and on any theory of liability, whether in contract, strict liability,
|
||||
|
// or tort (including negligence or otherwise) arising in any way out of
|
||||
|
// the use of this software, even if advised of the possibility of such damage.
|
||||
|
//
|
||||
|
//M*/
|
||||
|
|
||||
|
#ifndef __OPENCV_OLD_CV_H__ |
||||
|
#define __OPENCV_OLD_CV_H__ |
||||
|
|
||||
|
#if defined(_MSC_VER) |
||||
|
#define CV_DO_PRAGMA(x) __pragma(x) |
||||
|
#define __CVSTR2__(x) #x |
||||
|
#define __CVSTR1__(x) __CVSTR2__(x) |
||||
|
#define __CVMSVCLOC__ __FILE__ "("__CVSTR1__(__LINE__)") : " |
||||
|
#define CV_MSG_PRAGMA(_msg) CV_DO_PRAGMA(message (__CVMSVCLOC__ _msg)) |
||||
|
#elif defined(__GNUC__) |
||||
|
#define CV_DO_PRAGMA(x) _Pragma (#x) |
||||
|
#define CV_MSG_PRAGMA(_msg) CV_DO_PRAGMA(message (_msg)) |
||||
|
#else |
||||
|
#define CV_DO_PRAGMA(x) |
||||
|
#define CV_MSG_PRAGMA(_msg) |
||||
|
#endif |
||||
|
#define CV_WARNING(x) CV_MSG_PRAGMA("Warning: " #x) |
||||
|
|
||||
|
//CV_WARNING("This is a deprecated opencv header provided for compatibility. Please include a header from a corresponding opencv module")
|
||||
|
|
||||
|
#include "opencv2/core/core_c.h" |
||||
|
#include "opencv2/imgproc/imgproc_c.h" |
||||
|
#include "opencv2/photo/photo_c.h" |
||||
|
#include "opencv2/video/tracking_c.h" |
||||
|
#include "opencv2/objdetect/objdetect_c.h" |
||||
|
|
||||
|
#if !defined(CV_IMPL) |
||||
|
#define CV_IMPL extern "C" |
||||
|
#endif //CV_IMPL
|
||||
|
|
||||
|
#endif // __OPENCV_OLD_CV_H_
|
||||
@ -0,0 +1,60 @@ |
|||||
|
/*M///////////////////////////////////////////////////////////////////////////////////////
|
||||
|
//
|
||||
|
// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
|
||||
|
//
|
||||
|
// By downloading, copying, installing or using the software you agree to this license.
|
||||
|
// If you do not agree to this license, do not download, install,
|
||||
|
// copy or use the software.
|
||||
|
//
|
||||
|
//
|
||||
|
// License Agreement
|
||||
|
// For Open Source Computer Vision Library
|
||||
|
//
|
||||
|
// Copyright (C) 2000-2008, Intel Corporation, all rights reserved.
|
||||
|
// Copyright (C) 2009, Willow Garage Inc., all rights reserved.
|
||||
|
// Third party copyrights are property of their respective owners.
|
||||
|
//
|
||||
|
// Redistribution and use in source and binary forms, with or without modification,
|
||||
|
// are permitted provided that the following conditions are met:
|
||||
|
//
|
||||
|
// * Redistribution's of source code must retain the above copyright notice,
|
||||
|
// this list of conditions and the following disclaimer.
|
||||
|
//
|
||||
|
// * Redistribution's in binary form must reproduce the above copyright notice,
|
||||
|
// this list of conditions and the following disclaimer in the documentation
|
||||
|
// and/or other materials provided with the distribution.
|
||||
|
//
|
||||
|
// * The name of the copyright holders may not be used to endorse or promote products
|
||||
|
// derived from this software without specific prior written permission.
|
||||
|
//
|
||||
|
// This software is provided by the copyright holders and contributors "as is" and
|
||||
|
// any express or implied warranties, including, but not limited to, the implied
|
||||
|
// warranties of merchantability and fitness for a particular purpose are disclaimed.
|
||||
|
// In no event shall the Intel Corporation or contributors be liable for any direct,
|
||||
|
// indirect, incidental, special, exemplary, or consequential damages
|
||||
|
// (including, but not limited to, procurement of substitute goods or services;
|
||||
|
// loss of use, data, or profits; or business interruption) however caused
|
||||
|
// and on any theory of liability, whether in contract, strict liability,
|
||||
|
// or tort (including negligence or otherwise) arising in any way out of
|
||||
|
// the use of this software, even if advised of the possibility of such damage.
|
||||
|
//
|
||||
|
//M*/
|
||||
|
|
||||
|
#ifndef __OPENCV_OLD_CV_HPP__ |
||||
|
#define __OPENCV_OLD_CV_HPP__ |
||||
|
|
||||
|
//#if defined(__GNUC__)
|
||||
|
//#warning "This is a deprecated opencv header provided for compatibility. Please include a header from a corresponding opencv module"
|
||||
|
//#endif
|
||||
|
|
||||
|
#include "cv.h" |
||||
|
#include "opencv2/core.hpp" |
||||
|
#include "opencv2/imgproc.hpp" |
||||
|
#include "opencv2/photo.hpp" |
||||
|
#include "opencv2/video.hpp" |
||||
|
#include "opencv2/highgui.hpp" |
||||
|
#include "opencv2/features2d.hpp" |
||||
|
#include "opencv2/calib3d.hpp" |
||||
|
#include "opencv2/objdetect.hpp" |
||||
|
|
||||
|
#endif |
||||
@ -0,0 +1,57 @@ |
|||||
|
/*M///////////////////////////////////////////////////////////////////////////////////////
|
||||
|
//
|
||||
|
// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
|
||||
|
//
|
||||
|
// By downloading, copying, installing or using the software you agree to this license.
|
||||
|
// If you do not agree to this license, do not download, install,
|
||||
|
// copy or use the software.
|
||||
|
//
|
||||
|
//
|
||||
|
// Intel License Agreement
|
||||
|
// For Open Source Computer Vision Library
|
||||
|
//
|
||||
|
// Copyright (C) 2000, Intel Corporation, all rights reserved.
|
||||
|
// Third party copyrights are property of their respective owners.
|
||||
|
//
|
||||
|
// Redistribution and use in source and binary forms, with or without modification,
|
||||
|
// are permitted provided that the following conditions are met:
|
||||
|
//
|
||||
|
// * Redistribution's of source code must retain the above copyright notice,
|
||||
|
// this list of conditions and the following disclaimer.
|
||||
|
//
|
||||
|
// * Redistribution's in binary form must reproduce the above copyright notice,
|
||||
|
// this list of conditions and the following disclaimer in the documentation
|
||||
|
// and/or other materials provided with the distribution.
|
||||
|
//
|
||||
|
// * The name of Intel Corporation may not be used to endorse or promote products
|
||||
|
// derived from this software without specific prior written permission.
|
||||
|
//
|
||||
|
// This software is provided by the copyright holders and contributors "as is" and
|
||||
|
// any express or implied warranties, including, but not limited to, the implied
|
||||
|
// warranties of merchantability and fitness for a particular purpose are disclaimed.
|
||||
|
// In no event shall the Intel Corporation or contributors be liable for any direct,
|
||||
|
// indirect, incidental, special, exemplary, or consequential damages
|
||||
|
// (including, but not limited to, procurement of substitute goods or services;
|
||||
|
// loss of use, data, or profits; or business interruption) however caused
|
||||
|
// and on any theory of liability, whether in contract, strict liability,
|
||||
|
// or tort (including negligence or otherwise) arising in any way out of
|
||||
|
// the use of this software, even if advised of the possibility of such damage.
|
||||
|
//
|
||||
|
//M*/
|
||||
|
|
||||
|
#ifndef __OPENCV_OLD_AUX_H__ |
||||
|
#define __OPENCV_OLD_AUX_H__ |
||||
|
|
||||
|
//#if defined(__GNUC__)
|
||||
|
//#warning "This is a deprecated opencv header provided for compatibility. Please include a header from a corresponding opencv module"
|
||||
|
//#endif
|
||||
|
|
||||
|
#include "opencv2/core/core_c.h" |
||||
|
#include "opencv2/imgproc/imgproc_c.h" |
||||
|
#include "opencv2/photo/photo_c.h" |
||||
|
#include "opencv2/video/tracking_c.h" |
||||
|
#include "opencv2/objdetect/objdetect_c.h" |
||||
|
|
||||
|
#endif |
||||
|
|
||||
|
/* End of file. */ |
||||
@ -0,0 +1,52 @@ |
|||||
|
/*M///////////////////////////////////////////////////////////////////////////////////////
|
||||
|
//
|
||||
|
// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
|
||||
|
//
|
||||
|
// By downloading, copying, installing or using the software you agree to this license.
|
||||
|
// If you do not agree to this license, do not download, install,
|
||||
|
// copy or use the software.
|
||||
|
//
|
||||
|
//
|
||||
|
// Intel License Agreement
|
||||
|
// For Open Source Computer Vision Library
|
||||
|
//
|
||||
|
// Copyright (C) 2000, Intel Corporation, all rights reserved.
|
||||
|
// Third party copyrights are property of their respective owners.
|
||||
|
//
|
||||
|
// Redistribution and use in source and binary forms, with or without modification,
|
||||
|
// are permitted provided that the following conditions are met:
|
||||
|
//
|
||||
|
// * Redistribution's of source code must retain the above copyright notice,
|
||||
|
// this list of conditions and the following disclaimer.
|
||||
|
//
|
||||
|
// * Redistribution's in binary form must reproduce the above copyright notice,
|
||||
|
// this list of conditions and the following disclaimer in the documentation
|
||||
|
// and/or other materials provided with the distribution.
|
||||
|
//
|
||||
|
// * The name of Intel Corporation may not be used to endorse or promote products
|
||||
|
// derived from this software without specific prior written permission.
|
||||
|
//
|
||||
|
// This software is provided by the copyright holders and contributors "as is" and
|
||||
|
// any express or implied warranties, including, but not limited to, the implied
|
||||
|
// warranties of merchantability and fitness for a particular purpose are disclaimed.
|
||||
|
// In no event shall the Intel Corporation or contributors be liable for any direct,
|
||||
|
// indirect, incidental, special, exemplary, or consequential damages
|
||||
|
// (including, but not limited to, procurement of substitute goods or services;
|
||||
|
// loss of use, data, or profits; or business interruption) however caused
|
||||
|
// and on any theory of liability, whether in contract, strict liability,
|
||||
|
// or tort (including negligence or otherwise) arising in any way out of
|
||||
|
// the use of this software, even if advised of the possibility of such damage.
|
||||
|
//
|
||||
|
//M*/
|
||||
|
|
||||
|
#ifndef __OPENCV_OLD_AUX_HPP__ |
||||
|
#define __OPENCV_OLD_AUX_HPP__ |
||||
|
|
||||
|
//#if defined(__GNUC__)
|
||||
|
//#warning "This is a deprecated opencv header provided for compatibility. Please include a header from a corresponding opencv module"
|
||||
|
//#endif
|
||||
|
|
||||
|
#include "cvaux.h" |
||||
|
#include "opencv2/core/utility.hpp" |
||||
|
|
||||
|
#endif |
||||
Some files were not shown because too many files changed in this diff
Loading…
Reference in new issue