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
 public static Bitmap DrawRectangleInPicture(Bitmap bmp, RrFaceT rf, Color rectColor, int lineWidth, float faceIr = 0f)
 {
     try
     {
         if (bmp == null)
         {
             return(null);
         }
         using (Graphics g = Graphics.FromImage(bmp))
         {
             Brush brush  = new SolidBrush(rectColor);
             var   pen    = new Pen(brush, lineWidth);
             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);
             g.DrawRectangle(pen, face);
             var text   = string.Format("信值:{0}", Math.Round(faceIr * 100f, 2));
             var myFont = new Font("微软雅黑", 10);
             g.DrawString(text, myFont, brush, face.Left, face.Top - 20);
         }
     }
     catch (Exception ex)
     {
         ex.ToSaveLog("DrawRectangleInPicture:");
     }
     return(bmp);
 }
Esempio n. 3
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);
        }