Example #1
0
 public override void Do(object pData)
 {
     FaceDetect detector = (FaceDetect)pData;
     detector.SwitchTicketCam(true);
     
     bool bCmp = false;
     string strQrCode="";
     for (int i=0; i<detector.GetMaxTicketChkTimes(); i++)
     {
         bCmp = detector.DoCheckTicket(ref strQrCode);
         if (bCmp) { break; }
         JobManager.Sleep(JobManager.IDLE_WAIT_MS * 2);
     }
     detector.SwitchTicketCam(false);
     
     if (bCmp)
     {
         string str = string.Format("二维码内容: {0}", strQrCode);
         detector.PromptInfo(str);
         JobManager.Sleep(200); //! for demo only
         GetMgr().disPatch(JobManager.sHandlerOpenGate, pData);
     }
     else {
         detector.PromptError("车票验证不通过!\n请走人工验票通道。");
         detector.PlayVoice(ConstValue.VOICE_FAIL_TICKCHK, true);
         GetMgr().disPatch(JobManager.sHandlerException, pData);
     }
 }
        /// <summary>
        /// 对图片做opencv的人脸分析
        /// </summary>
        /// <param name="imgTag"></param>
        public static void OpenCVAnalysis(ImageTag imgTag)
        {
            var imageFile = imgTag.GetTrueImageFile();
            var image     = Cv2.ImRead(imageFile);

            var tps = new List <TagPart>();

            foreach (var face in FaceDetect.OpenCvDetectMultiScale(image))
            {
                var body = AITag.Common.Utils.GetBodyRect(face, (double)(64 - 8) / 128, image.Width, image.Height);

                if (body != Rect.Empty)
                {
                    tps.Add(new TagPart
                    {
                        Face = face,
                        Body = body
                    });
                }
            }

            if (tps.Count == 0)
            {
                imgTag.Status = "opencv_fail";
            }
            else
            {
                imgTag.OpenCvParts = tps;
                imgTag.Status      = "opencv_finish";
            }
        }
Example #3
0
    private void Start()
    {
        FaceAppData faceAppData = new FaceAppData("11253066", "WwnwTfmq9ulkzknDBOv9tr6s", "7DNbqdtYvhVr0nR8YMtbIUeFfwyCBVgc");

        _faceDetect = new FaceDetect(faceAppData);

        _faceSearch = new FaceSearch("FaceRec", faceAppData);
    }
Example #4
0
        // 验证通过,允许通行
        public override void Do(object pData)
        {
            FaceDetect detector = (FaceDetect)pData;

            detector.LetGo();
            JobManager.Sleep(800); //! for demo only
            GetMgr().disPatch(JobManager.sHandlerReadIDCard, pData);
        }
Example #5
0
    private void Start()
    {
        faceDetect = new FaceDetect(faceModelFile);
        draw       = new PrimitiveDraw(Camera.main, gameObject.layer);

        var webCamInput = GetComponent <WebCamInput>();

        webCamInput.OnTextureUpdate.AddListener(OnTextureUpdate);
    }
        public void TestFaceDetectFromBytesImage()
        {
            byte[] arrBytes = GetImageAsByteArray("imageTest/img1.jpg");

            using (FaceDetect faceDetect = new FaceDetect(LocationServerApiAzure.EastUS))
            {
                faceDetect.SuscriptionKey = "Api Key Azure Cognitive Services";
                ResponseFaceDetect responseFaceDetect = faceDetect.GetFacesFromImageInDisk("Path The Image").Result;
            }
        }
Example #7
0
 private static Rectangle Draw(FaceDetect face)
 {
     return(new Rectangle
     {
         Width = face.FaceRectangle.Width,
         Height = face.FaceRectangle.Height,
         Stroke = new SolidColorBrush(Colors.Yellow),
         Fill = new SolidColorBrush(Colors.Transparent),
         StrokeThickness = 3,
         Name = face.FaceId
     });
 }
Example #8
0
        private void cameraShootHaar(object sender, System.Windows.RoutedEventArgs e)
        {
            Bitmap bt = FaceDetect.emguHaarDetect(imgshoot);

            if (bt != null)
            {
                img_m22.Source = BitmapToBitmapImage(bt);
            }
            else
            {
                MessageBox.Show("未检测到人脸信息");
            }
        }
Example #9
0
        public override void Do(object pData)
        {
            FaceDetect detector = (FaceDetect)pData;

            if (detector.ReadIDCardInfo())
            {
                GetMgr().disPatch(JobManager.sHandlerFaceCmp, pData);
            }
            else
            {
                JobManager.Sleep(JobManager.IDLE_WAIT_MS);
            }
        }
    private void InitMediaPipeModelPaths()
    {
        string detectionPath = Path.Combine(Application.streamingAssetsPath, faceModelFile);

        m_faceDetect = new FaceDetect(detectionPath);

        string faceMeshPath = Path.Combine(Application.streamingAssetsPath, faceMeshModelFile);

        m_faceMesh = new FaceMesh(faceMeshPath);

        string irisDetectionPath = Path.Combine(Application.streamingAssetsPath, irisModelFile);

        m_irisLeftDetect  = new IrisDetect(irisDetectionPath);
        m_irisRightDetect = new IrisDetect(irisDetectionPath);
    }
Example #11
0
        //相似度计算

        private void m1SimCaculate(object sender, System.Windows.RoutedEventArgs e)
        {
            if (img_m11.Source != null)
            {
                st.Start();
                tempbt = FaceDetect.SkinSimDetect(tb_filepath.Text.Trim());
                st.Stop();
                img_m12.Source    = BitmapToBitmapImage(tempbt);
                lab_time1.Content = String.Format("{0:F02}毫秒", st.ElapsedMilliseconds);
                lastElsp          = st.ElapsedMilliseconds;
            }
            else
            {
                MessageBox.Show("请先打开一张图片");
            }
        }
Example #12
0
        private void m4detectface(object sender, System.Windows.RoutedEventArgs e)
        {
            st.Start();
            Bitmap bt = FaceDetect.emguHaarDetect(tb_filepath4.Text.Trim());

            st.Stop();
            if (bt != null)
            {
                img_m41.Source = BitmapToBitmapImage(bt);
            }
            else
            {
                MessageBox.Show("未检测到人脸信息");
            }
            lab_time4.Content = String.Format("{0:F02}毫秒", st.ElapsedMilliseconds - lastElsp);
            lastElsp          = st.ElapsedMilliseconds;
        }
    void Start()
    {
        string detectionPath = Path.Combine(Application.streamingAssetsPath, faceModelFile);

        faceDetect = new FaceDetect(detectionPath);

        string cameraName = WebCamUtil.FindName(new WebCamUtil.PreferSpec()
        {
            isFrontFacing = false,
            kind          = WebCamKind.WideAngle,
        });

        webcamTexture      = new WebCamTexture(cameraName, 1280, 720, 30);
        cameraView.texture = webcamTexture;
        webcamTexture.Play();
        Debug.Log($"Starting camera: {cameraName}");

        draw = new PrimitiveDraw(Camera.main, gameObject.layer);
    }
Example #14
0
        public override void Do(object pData)
        {
            FaceDetect detector = (FaceDetect)pData;

            detector.SwitchLight(2, true);
            detector.SwitchLight(3, true);
            detector.PlayVoice(ConstValue.VOICE_VIEW_CAM);

            float fScore = 0.0f;
            bool  bCmp   = false;

            for (int i = 0; i < detector.GetMaxFaceCmpTimes(); i++)
            {
                bCmp = detector.DoFaceCmp(ref fScore);
                if (bCmp)
                {
                    break;
                }
                JobManager.Sleep(JobManager.IDLE_WAIT_MS);
            }

            detector.SwitchLight(2, false);
            detector.SwitchLight(3, false);
            detector.KeepCompareInfo(fScore);

            if (bCmp)
            {
                detector.PromptInfo("人脸识别通过");
                JobManager.Sleep(100); //for test
                GetMgr().disPatch(JobManager.sHandlerTicketCheck, pData);
            }
            else
            {
                detector.PromptError("人脸识别不通过");
                detector.PlayVoice(ConstValue.VOICE_FAIL_FACECMP);
                GetMgr().disPatch(JobManager.sHandlerException, pData);
            }

            detector.WriteFaceCmpLog(fScore);
        }
Example #15
0
        static void Main(string[] args)
        {
            string[] imgs = { "mayun.jpg", "zhangxueyou.jpg", "nezha.jpg" };
            string   path = $@".\images\{imgs[2]}";

            string result = FaceDetect.Detect(path);

            JObject ro = JsonConvert.DeserializeObject <JObject>(result);
            // 解析的第一个人脸信息
            JToken faceObj = ro["result"]["face_list"][0];

            Console.WriteLine("=================================");
            Console.WriteLine($"年龄:{faceObj["age"]}");
            Console.WriteLine($"美丑打分,范围0-100:{faceObj["beauty"]}");
            Console.WriteLine($"情绪:{faceObj["emotion"]}");
            Console.WriteLine($"表情:{faceObj["expression"]}");
            Console.WriteLine($"真实人脸/卡通人脸:{faceObj["face_type"]}");
            Console.WriteLine($"性别:{faceObj["gender"]}");
            Console.WriteLine($"是否戴眼镜:{faceObj["glasses"]}");

            Console.ReadKey(false);
        }
Example #16
0
    private void Start()
    {
        faceDetect = new FaceDetect(faceModelFile);
        faceMesh   = new FaceMesh(faceMeshModelFile);
        draw       = new PrimitiveDraw(Camera.main, gameObject.layer);

        // Create Face Mesh Renderer
        {
            var go = new GameObject("Face");
            go.transform.SetParent(transform);
            var faceRenderer = go.AddComponent <MeshRenderer>();
            faceRenderer.material = faceMaterial;

            faceMeshFilter            = go.AddComponent <MeshFilter>();
            faceMeshFilter.sharedMesh = FaceMeshBuilder.CreateMesh();

            faceKeypoints = new Vector3[FaceMesh.KEYPOINT_COUNT];
        }

        var webCamInput = GetComponent <WebCamInput>();

        webCamInput.OnTextureUpdate.AddListener(OnTextureUpdate);
    }
Example #17
0
    void Start()
    {
        string detectionPath = Path.Combine(Application.streamingAssetsPath, faceModelFile);

        faceDetect = new FaceDetect(detectionPath);

        string faceMeshPath = Path.Combine(Application.streamingAssetsPath, faceMeshModelFile);

        faceMesh = new FaceMesh(faceMeshPath);

        string cameraName = WebCamUtil.FindName(new WebCamUtil.PreferSpec()
        {
            isFrontFacing = false,
            kind          = WebCamKind.WideAngle,
        });

        webcamTexture      = new WebCamTexture(cameraName, 1280, 720, 30);
        cameraView.texture = webcamTexture;
        webcamTexture.Play();
        Debug.Log($"Starting camera: {cameraName}");

        draw = new PrimitiveDraw(Camera.main, gameObject.layer);

        // Create Face Mesh Renderer
        {
            var go = new GameObject("Face");
            go.transform.SetParent(transform);
            var faceRenderer = go.AddComponent <MeshRenderer>();
            faceRenderer.material = faceMaterial;

            faceMeshFilter            = go.AddComponent <MeshFilter>();
            faceMeshFilter.sharedMesh = FaceMeshBuilder.CreateMesh();

            faceKeypoints = new Vector3[FaceMesh.KEYPOINT_COUNT];
        }
    }
        private async void btnSelectImage_Click(object sender, EventArgs e)
        {
            if (IsBusy)
            {
                return;
            }

            if (dialogOpen.ShowDialog() == DialogResult.OK)
            {
                dataFaces.Rows.Clear();
                IsBusy = true;
                btnSelectImage.Text       = "Loading...";
                pictureUsed.ImageLocation = dialogOpen.FileName;

                using (FaceDetect faceDetect = new FaceDetect(LocationServerApiAzure.EastUS))
                {
                    faceDetect.SuscriptionKey = "Api Azure Key";
                    ResponseFaceDetect responseFaceDetect = await faceDetect.GetFacesFromImageInDisk(dialogOpen.FileName);

                    if (responseFaceDetect.IsSuccess)
                    {
                        foreach (var face in responseFaceDetect.Faces)
                        {
                            dataFaces.Rows.Add(face.faceAttributes.gender, face.faceAttributes.age);
                        }
                    }
                    else
                    {
                        MessageBox.Show(responseFaceDetect.Error.Message);
                    }
                }

                btnSelectImage.Text = "Select Image";
                IsBusy = false;
            }
        }
        void LoadPageShow()
        {
            currentShowTag = images[currentIndex];

            var image = Cv2.ImRead(currentShowTag.GetTrueImageFile());

            var tps = currentShowTag.OpenCvParts;

            if (tps == null || tps.Count == 0)
            {
                // 网上有看到有人先转灰度再识别,实际效果也没好多少 var gray_img = image.CvtColor(ColorConversionCodes.RGB2GRAY);
                var ract = FaceDetect.OpenCvDetectMultiScale(image);

                tps = new List <TagPart>();

                foreach (var face in ract)
                {
                    var body = AITag.Common.Utils.GetBodyRect(face, (double)(64 - 8) / 128, image.Width, image.Height);

                    if (body != Rect.Empty)
                    {
                        tps.Add(new TagPart
                        {
                            Face = face,
                            Body = body
                        });
                    }
                }
            }

            if (tps.Count == 0)
            {
                UpdateIamgeTagStatus(currentShowTag, "opencv_fail");
                btnNextImage_Click(null, null);
                return;
            }

            currentShowTag.OpenCvParts = tps;

            panelParts.Children.Clear();

            foreach (var item in tps)
            {
                var face = item.Face;
                var body = item.Body;

                Cv2.Rectangle(image, face, Scalar.Red);

                var i2  = image.Clone(body);
                var utp = new UserTagParts();

                utp.InitData(item, i2);

                panelParts.Children.Add(utp);

                Cv2.Rectangle(image, body, Scalar.Red);

                var ioa = InputOutputArray.Create(image);
                // 顺便标注一下尺寸
                Cv2.PutText(ioa, $"top:{face.Top} left:{face.Left} w:{face.Width} h:{face.Height}",
                            new Point(face.Left, face.Bottom + 2),
                            HersheyFonts.HersheySimplex, 1, Scalar.Blue);

                ioa = InputOutputArray.Create(image);
                Cv2.PutText(ioa, $"top:{body.Top} left:{body.Left} w:{body.Width} h:{body.Height}",
                            new Point(body.Left, body.Top - 10),
                            HersheyFonts.HersheySimplex, 1, Scalar.Blue);
            }

            imgShow.Source = image.MatToBitmapImage();

            panelCurrentImgTags.Children.Clear();

            if (!string.IsNullOrEmpty(currentShowTag.TagsName))
            {
                AppendTagtoCurrentTagPanel(currentShowTag.TagsName);
            }
        }
Example #20
0
        /// <summary>
        /// 将视频封面照,拿去百度检查
        /// </summary>
        private static void DetectFace2(int maxGetCount = 60 * 2 * 30) // 30分钟的数据)
        {
            var      baiduai      = new FaceDetect();
            int      i            = 0;
            DateTime nextCallTime = DateTime.Now;

            using (var db = DBSet.GetCon(DBSet.SqliteDBName.Bilibili))
            {
                foreach (var up in db.Select <UP>(o => o.follower > 3000).OrderByDescending(o => o.follower).ToArray())
                {
                    foreach (var av in db.Select <AV>(o => o.UpId == up.Id))
                    {
                        if (isExit)
                        {
                            break;
                        }

                        var pic = new Uri(av.pic).AbsolutePath.Replace("/", "_");

                        // 只按照本地文件名做验证
                        var detect = db.Single <ImageDetect>(o => o.LocalFile == pic);

                        if (detect == null)
                        {
                            byte[] bytes = null;

                            if (FromWeb)
                            {
                                try
                                {
                                    bytes = new WebClient().DownloadData(av.pic);
                                }
                                catch (Exception e)
                                {
                                    Console.WriteLine(e);
                                }
                            }
                            else
                            {
                                // 封面照落地,根据目前采集到数据,如果将宅舞区的封面照落地的话,估计要100多G
                                // 再加上三次元区,估计服务器硬盘干不动
                                var imagePath = SpiderConfig.GetPath($"imgs/{av.UpId}/{av.Id}");

                                var imageFile = Path.Combine(imagePath, pic);
                                if (!File.Exists(imageFile))
                                {
                                    continue;
                                }

                                bytes = File.ReadAllBytes(imageFile);
                            }

                            if (bytes == null)
                            {
                                continue;
                            }

                            var wait = (int)(nextCallTime - DateTime.Now).TotalMilliseconds + 1;

                            if (wait > 0)
                            {
                                Console.WriteLine($"wait {wait}");
                                Thread.Sleep(wait);
                            }

                            var start = DateTime.Now;
                            var ret   = baiduai.DetectFromBytes(bytes);
                            Console.Write($"useTime:{ (DateTime.Now - start).TotalMilliseconds} ms ");
                            nextCallTime = DateTime.Now.AddMilliseconds(500);

                            if (ret != null)
                            {
                                var dbItem = new ImageDetect
                                {
                                    AVId      = av.Id,
                                    UpId      = av.UpId,
                                    LocalFile = pic,
                                    Url       = av.pic,
                                    Detect    = ret.result,
                                };

                                if (ret.error_code == 0)
                                {
                                    dbItem.face_num = ret.result.face_num;
                                    if (ret.result.face_num > 0)
                                    {
                                        dbItem.max_face_probability = ret.result.face_list.Max(o => o.face_probability);
                                        dbItem.max_quality          = ret.result.face_list.Max(o => GetQuality(o));
                                    }
                                }

                                db.Insert(dbItem);

                                Console.WriteLine(av.title);
                                if (maxGetCount-- < 0)
                                {
                                    return;
                                }

                                // Thread.Sleep(500); // 百度的免费接口只有 2 qps,所以在这里做一下延迟。
                            }
                        }
                        else
                        {
                            // Console.WriteLine("忽略 " + av.title);
                        }
                    }
                }
            }
        }
Example #21
0
        public override void PreDo(object pData)
        {
            FaceDetect detector = (FaceDetect)pData;

            detector.ResetIDCardInfo();
        }
 /// <summary>
 /// Initialises this class
 /// </summary>
 private void Awake()
 {
     // このクラスをシングルトンのようにふるまわせる
     Instance = this;
 }
Example #23
0
 /// <summary>
 /// 拍照并检测
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 private void cameraShoot(object sender, System.Windows.RoutedEventArgs e)
 {
     img_m22.Source = BitmapToBitmapImage(FaceLocate.faceLocate(FaceLocate.ImageBinary(FaceDetect.SkinSimDetect(imgshoot)), imgshoot));
 }
Example #24
0
 /// <summary>
 /// 提交人脸检测结果
 /// </summary>
 /// <param name="obj"></param>
 /// <returns></returns>
 public Result <TicketResult> Ticket_SubmitFaceDetect(FaceDetect obj)
 {
     _log.Info("进入【提交人脸检测结果】事件: Ticket_SubmitFaceDetect");
     return(TicketDataResult.TaskTerminationResult());
 }
Example #25
0
        public override void PreDo(object pData)
        {
            FaceDetect detector = (FaceDetect)pData;

            detector.FlashLight(1, 200);
        }