/// <summary> /// 获取RGB活体结果 /// </summary> /// <param name="pEngine">引擎handle</param> /// <param name="livenessInfo">RGB活体结果</param> /// <returns>返回0表示正常;返回负数请根据ErrorCodeUtil类注释查看;其他值请在官网-帮助中心查询</returns> public int ASFGetLivenessScore(out LivenessInfo livenessInfo) { int retCode = -1; livenessInfo = new LivenessInfo(); IntPtr pLiveness = MemoryUtil.Malloc(MemoryUtil.SizeOf <ASF_LivenessInfo>()); //调用SDK接口 retCode = ASFFunctions.ASFGetLivenessScore(pEngine, pLiveness); if (retCode != 0) { MemoryUtil.Free(pLiveness); return(retCode); } //转化结果 ASF_LivenessInfo asfLivenessInfo = new ASF_LivenessInfo(); asfLivenessInfo = MemoryUtil.PtrToStructure <ASF_LivenessInfo>(pLiveness); livenessInfo.num = asfLivenessInfo.num; if (asfLivenessInfo.num > 0) { livenessInfo.isLive = new int[asfLivenessInfo.num]; Marshal.Copy(asfLivenessInfo.isLive, livenessInfo.isLive, 0, asfLivenessInfo.num); } MemoryUtil.FreeArray(pLiveness); return(retCode); }
/// <summary> /// RGB活体检测 /// </summary> /// <param name="pEngine">引擎Handle</param> /// <param name="imageInfo">图像数据</param> /// <param name="multiFaceInfo">活体检测结果</param> /// <returns>保存活体检测结果结构体</returns> public static ASF_LivenessInfo LivenessInfo_RGB(IntPtr pEngine, ImageInfo imageInfo, ASF_MultiFaceInfo multiFaceInfo, out int retCode) { IntPtr pMultiFaceInfo = UtilToolMemory.Malloc(UtilToolMemory.SizeOf <ASF_MultiFaceInfo>()); UtilToolMemory.StructureToPtr(multiFaceInfo, pMultiFaceInfo); if (multiFaceInfo.faceNum == 0) { retCode = -1; //释放内存 UtilToolMemory.Free(pMultiFaceInfo); return(new ASF_LivenessInfo()); } try { //人脸信息处理 retCode = ASFFunctions.ASFProcess(pEngine, imageInfo.width, imageInfo.height, imageInfo.format, imageInfo.imgData, pMultiFaceInfo, FaceEngineMask.ASF_LIVENESS); if (retCode == 0) { //获取活体检测结果 IntPtr pLivenessInfo = UtilToolMemory.Malloc(UtilToolMemory.SizeOf <ASF_LivenessInfo>()); retCode = ASFFunctions.ASFGetLivenessScore(pEngine, pLivenessInfo); Console.WriteLine("Get Liveness Result:" + retCode); ASF_LivenessInfo livenessInfo = UtilToolMemory.PtrToStructure <ASF_LivenessInfo>(pLivenessInfo); //释放内存 UtilToolMemory.Free(pMultiFaceInfo); UtilToolMemory.Free(pLivenessInfo); return(livenessInfo); } else { //释放内存 UtilToolMemory.Free(pMultiFaceInfo); return(new ASF_LivenessInfo()); } } catch { retCode = -1; //释放内存 UtilToolMemory.Free(pMultiFaceInfo); return(new ASF_LivenessInfo()); } }
/// <summary> /// RGB Vivo detection /// </summary> /// <param name="pEngine">Engine Handle</param> /// <param name="imageInfo">Image data</param> /// <param name="multiFaceInfo">In vivo test results</param> /// <returns>Preserve the structure of in vivo detection results</returns> public static ASF_LivenessInfo LivenessInfo_RGB(IntPtr pEngine, ImageInfo imageInfo, ASF_MultiFaceInfo multiFaceInfo, out int retCode) { IntPtr pMultiFaceInfo = MemoryUtil.Malloc(MemoryUtil.SizeOf <ASF_MultiFaceInfo>()); MemoryUtil.StructureToPtr(multiFaceInfo, pMultiFaceInfo); if (multiFaceInfo.faceNum == 0) { retCode = -1; //Release memory MemoryUtil.Free(pMultiFaceInfo); return(new ASF_LivenessInfo()); } try { //Face information processing retCode = ASFFunctions.ASFProcess(pEngine, imageInfo.width, imageInfo.height, imageInfo.format, imageInfo.imgData, pMultiFaceInfo, FaceEngineMask.ASF_LIVENESS); if (retCode == 0) { //Obtain in vivo test results IntPtr pLivenessInfo = MemoryUtil.Malloc(MemoryUtil.SizeOf <ASF_LivenessInfo>()); retCode = ASFFunctions.ASFGetLivenessScore(pEngine, pLivenessInfo); Console.WriteLine("Get Liveness Result:" + retCode); ASF_LivenessInfo livenessInfo = MemoryUtil.PtrToStructure <ASF_LivenessInfo>(pLivenessInfo); //Release memory MemoryUtil.Free(pMultiFaceInfo); MemoryUtil.Free(pLivenessInfo); return(livenessInfo); } else { //Release memory MemoryUtil.Free(pMultiFaceInfo); return(new ASF_LivenessInfo()); } } catch { retCode = -1; //Release memory MemoryUtil.Free(pMultiFaceInfo); return(new ASF_LivenessInfo()); } }