private byte[] ExtractSingleFaceFeature(IntPtr pEngine, ImageInfo imageInfo, MRECT rect, int faceOrient) { var singleFaceInfo = new ASF_SingleFaceInfo(); singleFaceInfo.faceRect = rect; singleFaceInfo.faceOrient = faceOrient; IntPtr pSingleFaceInfo = Marshal.AllocHGlobal(Marshal.SizeOf <ASF_SingleFaceInfo>()); Marshal.StructureToPtr(singleFaceInfo, pSingleFaceInfo, false); IntPtr pFaceFeature = Marshal.AllocHGlobal(Marshal.SizeOf <ASF_FaceFeature>()); try { int retCode = ASFFaceFeatureExtract(pEngine, imageInfo.width, imageInfo.height, imageInfo.format, imageInfo.imgData, pSingleFaceInfo, pFaceFeature); if (retCode == 0) { ASF_FaceFeature faceFeature = Marshal.PtrToStructure <ASF_FaceFeature>(pFaceFeature); byte[] feature = new byte[faceFeature.featureSize]; Marshal.Copy(faceFeature.feature, feature, 0, faceFeature.featureSize); return(feature); } else { return(null); } } catch { return(null); } finally { Marshal.FreeHGlobal(pSingleFaceInfo); Marshal.FreeHGlobal(pFaceFeature); } }
private static byte[] ExtractSingleFaceFeature(IntPtr pEngine, ImageInfo imageInfo, MRECT rect, int faceOrient) { var singleFaceInfo = new ASF_SingleFaceInfo(); singleFaceInfo.faceRect = rect; singleFaceInfo.faceOrient = faceOrient; IntPtr pSingleFaceInfo = Marshal.AllocHGlobal(Marshal.SizeOf <ASF_SingleFaceInfo>()); Marshal.StructureToPtr(singleFaceInfo, pSingleFaceInfo, false); IntPtr pFaceFeature = Marshal.AllocHGlobal(Marshal.SizeOf <ASF_FaceFeature>()); try { int retCode = ASFFaceFeatureExtract(pEngine, imageInfo.width, imageInfo.height, imageInfo.format, imageInfo.imgData, pSingleFaceInfo, pFaceFeature); if (retCode == 0) { ASF_FaceFeature faceFeature = Marshal.PtrToStructure <ASF_FaceFeature>(pFaceFeature); byte[] feature = new byte[faceFeature.featureSize]; Marshal.Copy(faceFeature.feature, feature, 0, faceFeature.featureSize); return(feature); } if (retCode == 81925) { throw new Exception("人脸特征检测结果置信度低!"); } else { return(null); } } catch (Exception ex) { throw new Exception($"Arcsoft_Face_Action-->ExtractSingleFaceFeature exception: {ex.Message}"); } finally { Marshal.FreeHGlobal(pSingleFaceInfo); Marshal.FreeHGlobal(pFaceFeature); } }