/// <summary> /// 该接口目前仅支持单人脸IR活体检测(不支持年龄、性别、3D角度的检测),默认取第一张人脸 /// 图像数据以结构体形式传入,对采用更高字节对齐方式的图像兼容性更好 /// </summary> /// <param name="imageFormat">图像格式</param> /// <param name="image">图片</param> /// <param name="multiFaceInfo">人脸框信息</param> /// <param name="combinedMask">检测属性</param> /// <returns>返回0表示正常;返回负数请根据ErrorCodeUtil类注释查看;其他值请在官网-帮助中心查询</returns> public int ASFProcessEx_IR(Image image, MultiFaceInfo multiFaceInfo, int combinedMask, ASF_ImagePixelFormat imageFormat = ASF_ImagePixelFormat.ASVL_PAF_GRAY) { int retCode = -1; if (multiFaceInfo == null) { return(ErrorCodeUtil.MULPTIFACEINFO_IS_NULL); } if (image == null) { return(ErrorCodeUtil.IMAGE_IS_NULL); } ImageInfo imageInfo = new ImageInfo(); imageInfo = ASF_ImagePixelFormat.ASVL_PAF_RGB24_B8G8R8.Equals(imageFormat) ? ImageUtil.ReadBMP(image) : ImageUtil.ReadBMP_IR(image); if (imageInfo == null) { return(ErrorCodeUtil.IMAGE_DATA_READ_FAIL); } //转化人脸信息 ASF_MultiFaceInfo multiFaceInfoStruct = new ASF_MultiFaceInfo(); IntPtr pMultiFaceInfo = MemoryUtil.Malloc(MemoryUtil.SizeOf <ASF_MultiFaceInfo>()); multiFaceInfoStruct.faceNum = multiFaceInfo.faceNum; if (multiFaceInfo.faceNum > 0) { if (multiFaceInfo.faceID != null) { multiFaceInfoStruct.faceID = MemoryUtil.Malloc(multiFaceInfo.faceNum * MemoryUtil.SizeOf <int>()); Marshal.Copy(multiFaceInfo.faceID, 0, multiFaceInfoStruct.faceID, multiFaceInfo.faceNum); } multiFaceInfoStruct.faceOrients = MemoryUtil.Malloc(multiFaceInfo.faceNum * MemoryUtil.SizeOf <int>()); Marshal.Copy(multiFaceInfo.faceOrients, 0, multiFaceInfoStruct.faceOrients, multiFaceInfo.faceNum); multiFaceInfoStruct.faceRects = MemoryUtil.Malloc(MemoryUtil.SizeOf <MRECT>() * multiFaceInfo.faceNum); byte[] allByte = new byte[MemoryUtil.SizeOf <MRECT>() * multiFaceInfo.faceNum]; for (int i = 0; i < multiFaceInfo.faceNum; i++) { byte[] tempBytes = MemoryUtil.StructToBytes(multiFaceInfo.faceRects[i]); tempBytes.CopyTo(allByte, MemoryUtil.SizeOf <MRECT>() * i); } Marshal.Copy(allByte, 0, multiFaceInfoStruct.faceRects, allByte.Length); } MemoryUtil.StructureToPtr(multiFaceInfoStruct, pMultiFaceInfo); ASF_ImageData asfInfoData = CommonUtil.TransImageDataStructByImageInfo(imageInfo); IntPtr pImageInfo = MemoryUtil.Malloc(MemoryUtil.SizeOf <ASF_ImageData>()); MemoryUtil.StructureToPtr(asfInfoData, pImageInfo); //调用SDK接口 retCode = ASFFunctions.ASFProcessEx_IR(pEngine, pImageInfo, pMultiFaceInfo, combinedMask); //释放内存 MemoryUtil.FreeArray(imageInfo.imgData, multiFaceInfoStruct.faceID, multiFaceInfoStruct.faceOrients, multiFaceInfoStruct.faceRects, pMultiFaceInfo, pImageInfo); return(retCode); }