Ejemplo n.º 1
0
        public List <FaceInfo> FaceRecg(Bitmap bmp)//识别函数  返回更新的_currentFaceList
        {
            _currentFaceBitmp = bmp;
            byte[] facePicByte = Picformat();//格式转换

            DateTime Dtime = DateTime.Now;

            Face_detect_sdk.PFD_FACE_DETECT faceInfo = new Face_detect_sdk.PFD_FACE_DETECT();
            int s = Face_detect_sdk.PFD_GetFeature(facePicByte, ref faceInfo, _currentFaceFeature, Face_detect_sdk.PFD_OP_FACE_ROLL_0, (short)faceMinWidth);

            facePicByte = null;
            _currentFaceList.Clear();
            if (faceInfo.num != 0)
            {
                for (int i = 0; i < faceInfo.num; i++)
                {
                    if (faceInfo.info[i].enable == 0)
                    {
                        byte[] f = new byte[3000];
                        Marshal.Copy(_currentFaceFeature[i], f, 0, 3000);
                        FaceInfo info1 = new FaceInfo  //此处将获取到的人脸信息导出,可增加更多信息
                        {
                            facel   = faceInfo.info[i].faceInfo.rect_l,
                            facer   = faceInfo.info[i].faceInfo.rect_r,
                            facet   = faceInfo.info[i].faceInfo.rect_t,
                            faceb   = faceInfo.info[i].faceInfo.rect_b,
                            age     = faceInfo.info[i].age,
                            sex     = faceInfo.info[i].gen == 0 ? "男" : "女",
                            qingxie = faceInfo.info[i].roll,
                            yaotou  = faceInfo.info[i].yaw,
                            taitou  = faceInfo.info[i].pitch,
                            flen    = faceInfo.info[i].flen,
                            time    = Dtime,
                            feature = f
                        };
                        _currentFaceList.Add(info1);
                    }
                }
            }
            else
            {
                _statisticsFaceCount += _currentFaceList.Count;
                return(_currentFaceList);
            }

            GC.Collect();
            _statisticsFaceCount += _currentFaceList.Count;
            return(_currentFaceList);
        }
Ejemplo n.º 2
0
        public void Getinfo()
        {
            try
            {
                Bitmap   pic  = new Bitmap(bmp.Width, bmp.Height, PixelFormat.Format24bppRgb);
                Graphics gra1 = Graphics.FromImage(pic);
                gra1.DrawImage(bmp, new Rectangle(0, 0, bmp.Width, bmp.Height), new Rectangle(0, 0, bmp.Width, bmp.Height), GraphicsUnit.Pixel);
                gra1.Dispose();
                if (pic.PixelFormat != PixelFormat.Format24bppRgb)
                {
                    Bitmap   temp = new Bitmap(pic.Width, pic.Height, PixelFormat.Format24bppRgb);
                    Graphics g    = Graphics.FromImage(temp);
                    g.DrawImage(pic, 0, 0);
                    g.Dispose();
                    pic = temp;
                    temp.Dispose();
                    temp = null;
                }
                MemoryStream imgStream = new MemoryStream();
                pic.Save(imgStream, System.Drawing.Imaging.ImageFormat.Bmp);
                //bmp = null;
                byte[] picbyte = new byte[] { };
                picbyte = imgStream.ToArray();
                Face_detect_sdk.PFD_FACE_DETECT faceInfo1 = new Face_detect_sdk.PFD_FACE_DETECT();
                IntPtr[] kkk = new IntPtr[20];
                for (int i = 0; i < 20; i++)
                {
                    kkk[i] = Marshal.AllocHGlobal(3000);
                }
                int    faceMinWidth = int.Parse(ConfigurationManager.AppSettings["facewidth"]);
                string m            = ConfigurationManager.AppSettings["FACE_ROLL"];
                int    s;
                switch (m)
                {
                case "0": s = Face_detect_sdk.PFD_GetFeature(picbyte, ref faceInfo1, kkk, Face_detect_sdk.PFD_OP_FACE_ROLL_0, (short)faceMinWidth); break;

                case "90": s = Face_detect_sdk.PFD_GetFeature(picbyte, ref faceInfo1, kkk, Face_detect_sdk.PFD_OP_FACE_ROLL_90, (short)faceMinWidth); break;

                case "180": s = Face_detect_sdk.PFD_GetFeature(picbyte, ref faceInfo1, kkk, Face_detect_sdk.PFD_OP_FACE_ROLL_180, (short)faceMinWidth); break;

                case "270": s = Face_detect_sdk.PFD_GetFeature(picbyte, ref faceInfo1, kkk, Face_detect_sdk.PFD_OP_FACE_ROLL_270, (short)faceMinWidth); break;
                }
                picbyte = null;

                if (faceInfo1.num != 0)
                {
                    //infoList.Clear();
                    for (int i = 0; i < faceInfo1.num; i++)
                    {
                        if (faceInfo1.info[i].enable == 0)
                        {
                            Faceinfotemp info1 = new Faceinfotemp();
                            // FaceInfo faino = new FaceInfo();
                            // faino.facel =
                            info1.facel = faceInfo1.info[i].faceInfo.rect_l;
                            // faino.facer =
                            info1.facer = faceInfo1.info[i].faceInfo.rect_r;
                            // faino.facet =
                            info1.facet = faceInfo1.info[i].faceInfo.rect_t;
                            //faino.faceb =
                            info1.faceb = faceInfo1.info[i].faceInfo.rect_b;
                            //infoList.Add(faino);

                            //创建新图位图
                            Bitmap bitmap = new Bitmap(info1.facer - info1.facel, info1.faceb - info1.facet);
                            //创建作图区域
                            Graphics g = Graphics.FromImage(bitmap);
                            //截取原图相应区域写入作图区
                            g.DrawImage(pic, 0, 0, new Rectangle(info1.facel, info1.facet, info1.facer - info1.facel, info1.faceb - info1.facet), GraphicsUnit.Pixel);
                            Image saveImage = Image.FromHbitmap(bitmap.GetHbitmap());
                            //保存图片
                            info1.pic = saveImage;
                            // saveImage.Dispose();
                            g.Dispose();
                            info1.age     = faceInfo1.info[i].age;
                            info1.gender  = faceInfo1.info[i].gen;
                            info1.taitou  = faceInfo1.info[i].pitch;
                            info1.qingxie = faceInfo1.info[i].roll;
                            info1.yaotou  = faceInfo1.info[i].yaw;
                            weizhi        = (info1.facer - info1.facel) / 2 + info1.facel;
                            weizhi2       = (info1.faceb - info1.facet) / 2 + info1.facet;
                            if (ConfigurationManager.AppSettings["line"] == "0")
                            {
                                if (weizhi >= (float)redcatch_from.trackBar2.Value / 1920 * pic.Width)
                                {
                                    info1.pan3 = pic;
                                    info1.p    = 3;
                                }
                                if (weizhi <= (float)redcatch_from.trackBar.Value / 1920 * pic.Width)
                                {
                                    info1.pan1 = pic;
                                    info1.p    = 1;
                                }
                                if (weizhi > (float)redcatch_from.trackBar.Value / 1920 * pic.Width && weizhi < (float)redcatch_from.trackBar2.Value / 1920 * pic.Width)
                                {
                                    info1.pan2 = pic;
                                    info1.p    = 2;
                                }
                            }
                            else
                            {
                                if (weizhi2 > (float)(1080 - redcatch_from.trackBar4.Value) / 1080 * pic.Height)
                                {
                                    info1.pan3 = pic;
                                    info1.p    = 3;
                                }
                                if (weizhi2 < (float)(1080 - redcatch_from.trackBar3.Value) / 1080 * pic.Height)
                                {
                                    info1.pan1 = pic;
                                    info1.p    = 1;
                                }
                                if (weizhi2 > (float)(1080 - redcatch_from.trackBar3.Value) / 1080 * pic.Height && weizhi2 < (float)(1080 - redcatch_from.trackBar4.Value) / 1080 * pic.Height)
                                {
                                    info1.pan2 = pic;
                                    info1.p    = 2;
                                }
                            }
                            info1.finish = false;
                            info1.flen   = faceInfo1.info[i].flen;
                            byte[] ys = new byte[3000];
                            Marshal.Copy(kkk[i], ys, 0, 3000);
                            info1.feature = ys;
                            redcatch_from.Chuli(info1, ref redcatch_from.qingli);
                        }
                    }
                    // FItt.DrawFace(infoList, redcatch_from.pictureBox1);
                }
                else
                {//释放内存
                    pic.Dispose();
                    pic = null;
                }
                for (int i1 = 0; i1 < kkk.Length; i1++)
                {
                    Marshal.FreeHGlobal(kkk[i1]);
                }
                bmp.Dispose();
                bmp = null;
                GC.Collect();
                redcatch.shibierun = false;
            }
            catch (Exception ex) { redcatch.shibierun = false; Console.WriteLine("线程出错!!" + ex); }
        }