Exemplo n.º 1
0
        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);
            }
        }
        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);
            }
        }
Exemplo n.º 3
0
 public static IntPtr PutFeatureByteIntoFeatureIntPtr(byte[] data)
 {
     try
     {
         if (data.Length > 0)
         {
             ASF_FaceFeature localFeature = new ASF_FaceFeature();
             localFeature.featureSize = data.Length;
             localFeature.feature     = Marshal.AllocHGlobal(localFeature.featureSize);
             Marshal.Copy(data, 0, localFeature.feature, data.Length);
             IntPtr intPtrFeature = Marshal.AllocHGlobal(Marshal.SizeOf <ASF_FaceFeature>());
             Marshal.StructureToPtr(localFeature, intPtrFeature, false);
             return(intPtrFeature);
         }
         else
         {
             return(IntPtr.Zero);
         }
     }
     catch
     {
         return(IntPtr.Zero);
     }
 }