Beispiel #1
0
        public int Compare(IntPtr pFeature1, IntPtr pFeature2, ref FaceSDK_Rec_VerifyResult result)
        {
            if (mVerifyHandler == IntPtr.Zero)
            {
                return(RET_EXCEPTION);
            }
            int rtn = RET_EXCEPTION;

            try
            {
                rtn = FaceSDK_Rec_VerifyFeature(mVerifyHandler, pFeature1, pFeature2, ref result);
            }
            catch (System.Exception ex)
            {
            }
            return(rtn);
        }
Beispiel #2
0
        public int CompareDBQuery(ref double dblSimilarity)
        {
            if (mVerifyHandler == IntPtr.Zero)
            {
                return(VERIFY_RESULT_INVALID_HANLDER); //算法未初始化
            }

            if (mDBImageThread == null || mQueryImageThread == null)
            {
                return(VERIFY_RESULT_THREAD_NOT_STARTED); //抽特征线程未启动
            }

            mDBImageThread.Join();
            mQueryImageThread.Join();

            if (mDBFeature == IntPtr.Zero)
            {
                return(VERIFY_RESULT_INVALID_DB_FEATURE);  //没有登记照特征
            }

            if (mQueryFeature == IntPtr.Zero)
            {
                return(VERIFY_RESULT_INVALID_QUERY_FEATURE);  //没有查询照特征
            }

            FaceSDK_Rec_VerifyResult result = new FaceSDK_Rec_VerifyResult();

            if (buffFeatureCount2 < 1)
            {
                return(VERIFY_RESULT_DB_IMAGE_NOFACE); //登记照中没有人脸
            }
            else if (buffFeatureCount2 < 1)
            {
                return(VERIFY_RESULT_QUERY_IMAGE_NOFACE); //查询照中没有人脸
            }
            else if (Compare(buffFeatureResult1[0].feature, buffFeatureResult2[0].feature, ref result) != RTN_SUCC)
            {
                return(VERIFY_RESULT_VERIFY_FAILED);  //比对失败
            }
            dblSimilarity = (float)result.similarity;

            return(RTN_SUCC);
        }
Beispiel #3
0
        public bool ComparePersonPair(Image DBImage, Image QueryImage, ref double dblSimilarity, int dbImageType = 1)
        {
            FaceSDK_Rec_VerifyResult result = new FaceSDK_Rec_VerifyResult();
            //for (int j = 0; j < 200; ++j)
            //{
            //    if (j == 0)
            //        Console.WriteLine("asfd");
            //    if(j == 50)
            //        Console.WriteLine("asfd");
            //    if (j == 99)
            //        Console.WriteLine("AFDS");
            //    if(j == 199)
            //        Console.WriteLine("AFDS");
            MemoryStream ms = new MemoryStream();

            DBImage.Save(ms, System.Drawing.Imaging.ImageFormat.Jpeg);
            byte[] DBbuff = ms.GetBuffer();
            ms = new MemoryStream();
            QueryImage.Save(ms, System.Drawing.Imaging.ImageFormat.Jpeg);
            byte[] Querybuff = ms.GetBuffer();
            if (mVerifyHandler == IntPtr.Zero)
            {
                dblSimilarity = 0;
                return(false);
            }

            IntPtr buffFeature1 = IntPtr.Zero;
            IntPtr buffFeature2 = IntPtr.Zero;
            // FaceSDK_Rec_FeatureExtractResult[] buffFeature2 = new FaceSDK_Rec_FeatureExtractResult() [];
            Int32 buffFeatureCount1 = 0;
            Int32 buffFeatureCount2 = 0;

            if (ExtractFeature(DBbuff, false, dbImageType, ref buffFeature1, ref buffFeatureCount1) != RTN_SUCC)
            {
                return(false);
            }
            if (ExtractFeature(Querybuff, true, 0, ref buffFeature2, ref buffFeatureCount2) != RTN_SUCC)
            {
                return(false);
            }

            FaceSDK_Rec_FeatureExtractResult[] buffFeatureResult1 = new FaceSDK_Rec_FeatureExtractResult[buffFeatureCount1];
            FaceSDK_Rec_FeatureExtractResult[] buffFeatureResult2 = new FaceSDK_Rec_FeatureExtractResult[buffFeatureCount2];

            buffFeatureResult1[0] = (FaceSDK_Rec_FeatureExtractResult)Marshal.PtrToStructure(buffFeature1, typeof(FaceSDK_Rec_FeatureExtractResult));
            buffFeatureResult2[0] = (FaceSDK_Rec_FeatureExtractResult)Marshal.PtrToStructure(buffFeature2, typeof(FaceSDK_Rec_FeatureExtractResult));

            int sizeFaceSDK_Rec_FeatureExtractResult1 = Marshal.SizeOf(buffFeatureResult1[0]);
            int sizeFaceSDK_Rec_FeatureExtractResult2 = Marshal.SizeOf(buffFeatureResult2[0]);

            for (int i = 1; i < buffFeatureCount1; ++i)
            {
                buffFeature1          = new IntPtr(buffFeature1.ToInt32() + sizeFaceSDK_Rec_FeatureExtractResult1);
                buffFeatureResult1[i] = (FaceSDK_Rec_FeatureExtractResult)Marshal.PtrToStructure(buffFeature1, typeof(FaceSDK_Rec_FeatureExtractResult));
            }
            for (int i = 1; i < buffFeatureCount2; ++i)
            {
                buffFeature2          = new IntPtr(buffFeature1.ToInt32() + sizeFaceSDK_Rec_FeatureExtractResult2);
                buffFeatureResult2[i] = (FaceSDK_Rec_FeatureExtractResult)Marshal.PtrToStructure(buffFeature2, typeof(FaceSDK_Rec_FeatureExtractResult));
            }

            if (buffFeatureCount1 < 1 || buffFeatureCount2 < 1)
            {
                return(false);
            }
            else if (Compare(buffFeatureResult1[0].feature, buffFeatureResult2[0].feature, ref result) != RTN_SUCC)
            {
                return(false);
            }

            dblSimilarity = (float)result.similarity;

            if (ReleaseFeature(ref buffFeatureResult1, ref buffFeatureCount1, ref buffFeature1) != RTN_SUCC)
            {
                return(false);
            }
            if (ReleaseFeature(ref buffFeatureResult2, ref buffFeatureCount2, ref buffFeature2) != RTN_SUCC)
            {
                return(false);
            }

            return(true);
        }
Beispiel #4
0
        public bool ComparePersonPair(byte[] DBbuff, byte[] Querybuff, ref double dblSimilarity, int dbImageType = 1)
        {
            FaceSDK_Rec_VerifyResult result = new FaceSDK_Rec_VerifyResult();

            if (mVerifyHandler == IntPtr.Zero)
            {
                dblSimilarity = 0;
                return(false);
            }

            IntPtr buffFeature1 = IntPtr.Zero;
            IntPtr buffFeature2 = IntPtr.Zero;
            // FaceSDK_Rec_FeatureExtractResult[] buffFeature2 = new FaceSDK_Rec_FeatureExtractResult() [];
            Int32 buffFeatureCount1 = 0;
            Int32 buffFeatureCount2 = 0;

            if (ExtractFeature(DBbuff, false, dbImageType, ref buffFeature1, ref buffFeatureCount1) != RTN_SUCC)
            {
                return(false);
            }
            if (ExtractFeature(Querybuff, true, 0, ref buffFeature2, ref buffFeatureCount2) != RTN_SUCC)
            {
                return(false);
            }

            FaceSDK_Rec_FeatureExtractResult[] buffFeatureResult1 = new FaceSDK_Rec_FeatureExtractResult[buffFeatureCount1];
            FaceSDK_Rec_FeatureExtractResult[] buffFeatureResult2 = new FaceSDK_Rec_FeatureExtractResult[buffFeatureCount2];

            buffFeatureResult1[0] = (FaceSDK_Rec_FeatureExtractResult)Marshal.PtrToStructure(buffFeature1, typeof(FaceSDK_Rec_FeatureExtractResult));
            buffFeatureResult2[0] = (FaceSDK_Rec_FeatureExtractResult)Marshal.PtrToStructure(buffFeature2, typeof(FaceSDK_Rec_FeatureExtractResult));

            int sizeFaceSDK_Rec_FeatureExtractResult1 = Marshal.SizeOf(buffFeatureResult1[0]);
            int sizeFaceSDK_Rec_FeatureExtractResult2 = Marshal.SizeOf(buffFeatureResult2[0]);

            for (int i = 1; i < buffFeatureCount1; ++i)
            {
                buffFeature1          = new IntPtr(buffFeature1.ToInt32() + sizeFaceSDK_Rec_FeatureExtractResult1);
                buffFeatureResult1[i] = (FaceSDK_Rec_FeatureExtractResult)Marshal.PtrToStructure(buffFeature1, typeof(FaceSDK_Rec_FeatureExtractResult));
            }
            for (int i = 1; i < buffFeatureCount2; ++i)
            {
                buffFeature2          = new IntPtr(buffFeature1.ToInt32() + sizeFaceSDK_Rec_FeatureExtractResult2);
                buffFeatureResult2[i] = (FaceSDK_Rec_FeatureExtractResult)Marshal.PtrToStructure(buffFeature2, typeof(FaceSDK_Rec_FeatureExtractResult));
            }

            if (buffFeatureCount1 < 1 || buffFeatureCount2 < 1)
            {
                return(false);
            }
            else if (Compare(buffFeatureResult1[0].feature, buffFeatureResult2[0].feature, ref result) != RTN_SUCC)
            {
                return(false);
            }

            dblSimilarity = (float)result.similarity;

            if (ReleaseFeature(ref buffFeatureResult1, ref buffFeatureCount1, ref buffFeature1) != RTN_SUCC)
            {
                return(false);
            }
            if (ReleaseFeature(ref buffFeatureResult2, ref buffFeatureCount2, ref buffFeature2) != RTN_SUCC)
            {
                return(false);
            }

            return(true);
        }
Beispiel #5
0
 private extern static int FaceSDK_Rec_VerifyFeature(IntPtr pHandle, IntPtr pFeature1, IntPtr pFeature2, ref FaceSDK_Rec_VerifyResult result);