///<summary> ///图像质量检测 ///推荐阈值0.35 ///图像数据以结构体形式传入,对采用更高字节对齐方式的图像兼容性更好 ///</summary> /// <param name="hEngine">引擎handle</param> /// <param name="imgData">图片数据</param> /// <param name="detectedFaces">人脸位置信息</param> /// <param name="imageQualityInfo">图像质量检测结果</param> /// <param name="detectModel">预留字段,当前版本使用默认参数(ASF_DETECT_MODEL_RGB)即可</param> /// <returns>调用结果</returns> public int ASFImageQualityDetectEx(Image image, MultiFaceInfo multiFaceInfo, out ImageQualityInfo imageQualityInfo, ASF_ImagePixelFormat imageFormat = ASF_ImagePixelFormat.ASVL_PAF_RGB24_B8G8R8, ASF_DetectModel detectModel = ASF_DetectModel.ASF_DETECT_MODEL_RGB) { int retCode = -1; imageQualityInfo = new ImageQualityInfo(); 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_ImageData asfInfoData = CommonUtil.TransImageDataStructByImageInfo(imageInfo); IntPtr pImageInfo = MemoryUtil.Malloc(MemoryUtil.SizeOf <ASF_ImageData>()); MemoryUtil.StructureToPtr(asfInfoData, pImageInfo); ASF_ImageQualityInfo ImageQualityInfoStruct = new ASF_ImageQualityInfo(); IntPtr pImageQualityInfo = MemoryUtil.Malloc(MemoryUtil.SizeOf <ASF_ImageQualityInfo>()); //转化人脸信息 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); //调用SDK接口 retCode = ASFFunctions.ASFImageQualityDetectEx(pEngine, pImageInfo, pMultiFaceInfo, pImageQualityInfo); if (retCode != 0) { MemoryUtil.FreeArray(imageInfo.imgData, pMultiFaceInfo, pImageInfo, pImageQualityInfo); return(retCode); } ImageQualityInfoStruct = MemoryUtil.PtrToStructure <ASF_ImageQualityInfo>(pImageQualityInfo); MemoryUtil.FreeArray(imageInfo.imgData, pMultiFaceInfo, pImageInfo, pImageQualityInfo); //转化非托管内存到托管内存 imageQualityInfo.num = ImageQualityInfoStruct.num; if (imageQualityInfo.num > 0) { imageQualityInfo.faceQualityValues = new float[imageQualityInfo.num]; Marshal.Copy(ImageQualityInfoStruct.faceQualityValues, imageQualityInfo.faceQualityValues, 0, imageQualityInfo.num); } return(retCode); }