示例#1
0
        public void DetectFace(object sender, EventArgs e)
        {
            var imageFrame = _capture.QueryFrame().ToImage <Bgr, byte>();

            var timer    = Stopwatch.StartNew();
            var detected = new DetectorService().DetectFace(imageFrame);

            timer.Stop();
            labelTime.Text = timer.ElapsedMilliseconds + " ms.";
            if (detected != null)
            {
                labelFaces.Text = detected.SharpnessValue.ToString();

                DrawCircle(imageFrame, detected.DetectedRectangle);
                //imageFrame.Draw(detected.DetectedRectangle, new Bgr(Color.Aquamarine));

                facePictureBox.Image = detected.DetectedImage.Bitmap;
                _faces.Add(detected);
                richTextBox1.Text = string.Format("MaxFace: {0}, MinFace: {1}, Current:{2},  Time: {3}", _faces.BestValue, _faces.WorstValue, detected.SharpnessValue, timer.ElapsedMilliseconds + " ms.");
            }
            else
            {
                DrawText(imageFrame, new System.Drawing.Rectangle(0, 50, imageFrame.Width, imageFrame.Height), "Waiting for face...", 35);
            }

            DrawBestFace(imageFrame);
            DrawBestBadge(imageFrame);
            DrawFrame(imageFrame);
        }
示例#2
0
        public void DetectBadge(object sender, EventArgs e)
        {
            var reduceCoeff = _settings.ReduceCoeff;
            var scaleFactor = 1.0 / reduceCoeff;

            var timer = Stopwatch.StartNew();

            Image <Bgr, byte> imageResized;

            var imageFrame = _capture.QueryFrame().ToImage <Bgr, byte>();

            var roi = GetRoi(imageFrame.Width, imageFrame.Height);

            if (_trancateRoi)
            {
                imageFrame.Draw(roi, new Bgr(_roiFrameColor));
                var truncImage = imageFrame.Copy(roi);
                imageResized = reduceCoeff == 1 ? truncImage : truncImage.Resize(scaleFactor, _interpolation);
            }
            else
            {
                imageResized = reduceCoeff == 1 ? imageFrame : imageFrame.Resize(scaleFactor, _interpolation);
            }

            var template = _imgToFindColor;
            //if (reduceCoeff != 1)
            //{
            //    template = _imgToFindColor.Resize(scaleFactor, _interpolation);
            //}

            long time;
            var  detected = new DetectorService().DetectSurf(template, imageResized, out time);

            timer.Stop();
            labelTime.Text = timer.ElapsedMilliseconds + " ms.";


            if (detected != null)
            {
                labelBadges.Text = detected.SharpnessValue.ToString();
                if (reduceCoeff > 1 || roi.X > 0 || roi.Y > 0)
                {
                    detected.DetectedRectangle = new System.Drawing.Rectangle(
                        roi.X + detected.DetectedRectangle.X * reduceCoeff,
                        roi.Y + detected.DetectedRectangle.Y * reduceCoeff,
                        detected.DetectedRectangle.Width * reduceCoeff,
                        detected.DetectedRectangle.Height * reduceCoeff);
                }

                detected.DetectedImage = imageFrame.Copy(detected.DetectedRectangle);

                imageFrame.Draw(detected.DetectedRectangle, new Bgr(_detectImageFrameColor));
                badgePictureBox.Image = detected.DetectedImage.Bitmap;
                _badges.Add(detected);
                richTextBox1.Text = string.Format("MaxBadge: {0}, MinBadge: {1}, Current:{2}, Time: {3}", _badges.BestValue, _badges.WorstValue, detected.SharpnessValue, timer.ElapsedMilliseconds + " ms.");
            }
            else
            {
                var text = string.Format("Waiting for badge {0} of {1}", _badges.Count, _settings.MinBadgeCount);
                DrawText(imageFrame, new System.Drawing.Rectangle(0, 50, imageFrame.Width, imageFrame.Height), text, 35);
                var textCloser = "Bring your badge closer to the camera.";
                DrawText(imageFrame, new System.Drawing.Rectangle(0, 100, imageFrame.Width, imageFrame.Height), textCloser, 35);
            }

            DrawBestFace(imageFrame);
            DrawBestBadge(imageFrame);
            DrawFrame(imageFrame);
        }