Exemple #1
0
        /// <summary>
        /// 人脸比对
        /// </summary>
        /// <param name="data1">第一张人脸数据</param>
        /// <param name="data2">第二张人脸数据</param>
        /// <returns></returns>
        public float Compare(byte[] data1, byte[] data2)
        {
            try
            {
                FaceFeature feature1 = new FaceFeature();
                feature1.feature = Marshal.AllocHGlobal(data1.Length);
                Marshal.Copy(data1, 0, feature1.feature, data1.Length);
                feature1.featureSize = data1.Length;
                IntPtr pLocalFeature1 = Marshal.AllocHGlobal(Marshal.SizeOf(feature1));
                Marshal.StructureToPtr(feature1, pLocalFeature1, false);

                FaceFeature feature2 = new FaceFeature();
                feature2.feature = Marshal.AllocHGlobal(data2.Length);
                Marshal.Copy(data2, 0, feature2.feature, data2.Length);
                feature2.featureSize = data2.Length;
                IntPtr pLocalFeature2 = Marshal.AllocHGlobal(Marshal.SizeOf(feature2));
                Marshal.StructureToPtr(feature2, pLocalFeature2, false);
                float similar = 0.0f;

                ASFAPI.ASFFaceFeatureCompare(hEngine, pLocalFeature1, pLocalFeature2, out similar);
                return(similar);
            }
            catch (Exception ex)
            {
                return(0.0f);
            }
        }
Exemple #2
0
        /// <summary>
        /// 获取人脸特征
        /// </summary>
        /// <returns></returns>
        public byte[] getFaceFeature(Bitmap image)
        {
            BitmapImage bitmapImage   = null;
            var         multiFaceInfo = DetectFaces(image, out bitmapImage);

            if (multiFaceInfo.faceNum == 0 || multiFaceInfo.faceOrient == IntPtr.Zero || multiFaceInfo.faceRect == IntPtr.Zero)
            {
                return(null);
            }

            SingleFaceInfo info  = new SingleFaceInfo();
            Mrect          mrect = new Mrect();

            int[] orientArray = new int[multiFaceInfo.faceNum];
            Marshal.Copy(multiFaceInfo.faceOrient, orientArray, 0, orientArray.Length);
            info.faceOrient = orientArray[0];

            byte[] byteArray = new byte[4 * 4];
            Marshal.Copy(multiFaceInfo.faceRect, byteArray, 0, byteArray.Length);
            int    size   = Marshal.SizeOf(mrect);
            IntPtr buffer = Marshal.AllocHGlobal(size);

            try
            {
                Marshal.Copy(byteArray, 0, buffer, size);
                mrect = (Mrect)Marshal.PtrToStructure(buffer, typeof(Mrect));
            }
            finally
            {
                Marshal.FreeHGlobal(buffer);
            }
            info.faceRect = mrect;

            FaceFeature feature = new FaceFeature();
            IntPtr      ptr1    = Marshal.AllocHGlobal(Marshal.SizeOf(info));

            Marshal.StructureToPtr(info, ptr1, false);
            var result = ASFAPI.ASFFaceFeatureExtract(hEngine, bitmapImage.Width, bitmapImage.Height, bitmapImage.Format, bitmapImage.ImageData, ptr1, ref feature);

            Marshal.FreeHGlobal(ptr1);
            byte[] data = null;
            if (result == 0 && feature.featureSize > 0 && feature.feature != IntPtr.Zero)
            {
                data = new byte[1032];
                Marshal.Copy(feature.feature, data, 0, 1032);
                return(data);
            }
            else
            {
                return(null);
            }
        }
Exemple #3
0
        /// <summary>
        /// 人脸比对
        /// </summary>
        /// <param name="data1">第一张人脸数据</param>
        /// <param name="data2">第二张人脸数据</param>
        /// <returns></returns>
        public float Compare(byte[] data1, byte[] data2)
        {
            FaceFeature feature1 = new FaceFeature();
            FaceFeature feature2 = new FaceFeature();
            IntPtr      ptr1     = Marshal.AllocHGlobal(data1.Length);
            IntPtr      ptr2     = Marshal.AllocHGlobal(data2.Length);

            Marshal.Copy(data1, 0, ptr1, data1.Length);
            Marshal.Copy(data2, 0, ptr2, data2.Length);
            feature1.feature     = ptr1;
            feature1.featureSize = 1032;
            feature2.feature     = ptr2;
            feature2.featureSize = 1032;
            float similar = 0.0f;

            ASFAPI.ASFFaceFeatureCompare(hEngine, feature1, feature2, ref similar);
            return(similar);
        }
Exemple #4
0
 public static extern int ASFFaceFeatureCompare(IntPtr hEngine, FaceFeature feature1, FaceFeature feature2, ref float confidenceLevel);
Exemple #5
0
 public static extern int ASFFaceFeatureExtract(IntPtr hEngine, int width, int height, int format, byte[] imgData, IntPtr faceInfo, ref FaceFeature feature);