Esempio n. 1
0
 /// <summary>人脸检测</summary>
 public Bitmap FaceVerify(Bitmap bmpImage)
 {
     try
     {
         using (var currentFrame = new Image <Bgr, Byte>(bmpImage))
         {
             //只能这么转
             invert = new Mat();
             CvInvoke.BitwiseAnd(currentFrame, currentFrame, invert);
             int c = 0;
             _rf     = new RrFaceT();
             _w      = invert.Width; _h = invert.Height;
             _itData = invert.DataPointer;
             var    lp = new IntPtr();
             IntPtr it = FaceverifyDll.rr_fd_detect(_ip, _itData, RrImageType.RR_IMAGE_BGR8UC3, _w, _h, ref lp, ref c);
             if (it.ToInt32() != 0)
             {
                 return(bmpImage);
             }
             if (c > 0)
             {
                 _rf    = (RrFaceT)Marshal.PtrToStructure(lp, typeof(RrFaceT));
                 Rrface = _rf;
             }
             FaceverifyDll.rr_fd_release_detect_result(lp);
         }
     }
     catch (Exception ex)
     {
         ex.ToSaveLog("FaceData.FaceVerify:");
     }
     return(bmpImage);
 }
Esempio n. 2
0
 /// <summary> 人脸比对结论 </summary>
 /// <param name="rf1">人脸特征码1</param>
 /// <param name="rf2">人脸特征码2</param>
 public static Single FaceResult(RrFeatureT rf1, RrFeatureT rf2)
 {
     try
     {
         byte[] byFp1 = StructToBytes(rf1);
         byte[] byFp2 = StructToBytes(rf2);
         return(FaceverifyDll.rr_fv_compare_features(byFp1, byFp2));
     }
     catch (Exception ex)
     {
         ex.ToSaveLog("FaceResult:");
     }
     return(0);
 }
Esempio n. 3
0
 protected virtual void Dispose(bool disposing)
 {
     try
     {
         if (disposing)
         {
             //执行基本的清理代码
             FaceverifyDll.rr_fd_destroy_detector(_ip);  //销毁人脸检测句柄
             FaceverifyDll.rr_fv_destroy_verifier(_ip1); //销毁人脸对比句柄
         }
     }
     catch (Exception ex)
     {
         ex.ToSaveLog("Dispose:");
     }
 }
Esempio n. 4
0
        /// <summary>人脸检测</summary>
        public Bitmap FaceVerify(Mat mat)
        {
            if (mat == null)
            {
                return(null);
            }
            try
            {
                int c = 0;
                _rf     = new RrFaceT();
                _w      = mat.Width; _h = mat.Height;
                _itData = mat.DataPointer;
                var lp = new IntPtr();
                "人脸检测句柄分析".ToSaveLog("FaceVerify:");
                IntPtr it = FaceverifyDll.rr_fd_detect(_ip, _itData, RrImageType.RR_IMAGE_BGR8UC3, _w, _h, ref lp, ref c);
                if (it.ToInt32() == 0)
                {
                    if (c > 0)
                    {
                        _rf    = (RrFaceT)Marshal.PtrToStructure(lp, typeof(RrFaceT));
                        Rrface = _rf;

                        #region 给识别出的所有人脸画矩形框
                        //int with = _rf.rect.right - _rf.rect.left;
                        //int heigth = _rf.rect.bottom - _rf.rect.top;
                        //var face = new Rectangle(_rf.rect.left, _rf.rect.top, with, heigth);
                        //Bitmap bm = FaceFun.DrawRectangleInPicture(mat.Bitmap, face, Color.Red, 2);
                        //"释放人脸检测句柄".ToSaveLog("FaceVerify:");
                        //FaceverifyDll.rr_fd_release_detect_result(lp);
                        //return bm;
                        #endregion
                    }
                    else
                    {
                        return(null);
                    }
                }
                "释放人脸检测句柄.".ToSaveLog("FaceVerify");
                FaceverifyDll.rr_fd_release_detect_result(lp);
            }
            catch (Exception ex)
            {
                ex.ToSaveLog("FaceData.FaceVerify:");
            }
            return(mat.Bitmap);
        }
Esempio n. 5
0
 /// <summary>提取人像特征码 </summary>
 public RrFeatureT FaceTz()
 {
     try
     {
         var ft = new RrFeatureT();
         //var fp = new RrFacePrimaryT { rect = _rf.rect, landmarks = _rf.landmarks };
         //byte[] byFp = FaceFun.StructToBytes(fp);
         byte[] byFp = FaceFun.StructToBytes(_rf);
         VerifyIr = FaceverifyDll.rr_fv_extract_feature(_ip1, _itData, RrImageType.RR_IMAGE_BGR8UC3, _w, _h, byFp, ref ft);
         Rft      = ft;
         return(ft);
     }
     catch (Exception ex)
     {
         ex.ToSaveLog("FaceData.FaceTz:");
     }
     return(Rft);
 }
Esempio n. 6
0
 public FaceData()
 {
     _ip  = FaceverifyDll.rr_fd_create_detector(_fdModelPath, (int)FaceverifyDll.rr_fd_get_version());
     _ip1 = FaceverifyDll.rr_fv_create_verifier(_fvModelPath, FaceverifyDll.rr_fv_get_version());
 }