示例#1
0
        public static RecognizerResult Recognize(string unknownImg)
        {
            RecognizerResult rcgnResult = new RecognizerResult();

            if (recognizer == null)
            {
                return(null);
            }

            // Recognize the image
            Image <Gray, Byte> testImage = new Image <Gray, Byte>(unknownImg);


            float[]  distances = recognizer.GetEigenDistances(testImage);
            string[] labels    = recognizer.Labels;
            int      num       = labels.Count();

            for (int i = 0; i < num; i++)
            {
                rcgnResult.Distances.Add(labels[i], distances[i]);
            }

            EigenObjectRecognizer.RecognitionResult result = recognizer.Recognize(testImage);

            if (result != null)
            {
                rcgnResult.Distance = result.Distance;
                rcgnResult.Label    = result.Label;
            }
            rcgnResult.FileName = Path.GetFullPath(unknownImg);

            return(rcgnResult);
        }
示例#2
0
        private void FrameProcedure(object sender, EventArgs e)
        {
            Users.Add("");
            //Set Frame/Size
            Frame    = camera.QueryFrame().Resize(640, 480, Emgu.CV.CvEnum.INTER.CV_INTER_CUBIC);
            grayFace = Frame.Convert <Gray, Byte>();
            MCvAvgComp[][] faceDedectedNow = grayFace.DetectHaarCascade(faceDetected, 1.2, 10, Emgu.CV.CvEnum.HAAR_DETECTION_TYPE.DO_CANNY_PRUNING, new System.Drawing.Size(20, 20));

            foreach (MCvAvgComp f in faceDedectedNow[0])
            {
                result = Frame.Copy(f.rect).Convert <Gray, Byte>().Resize(100, 100, Emgu.CV.CvEnum.INTER.CV_INTER_CUBIC);
                Frame.Draw(f.rect, new Bgr(Color.Transparent), 2);
                if (trainingImages.ToArray().Length != 0)
                {
                    MCvTermCriteria       termCriteria = new MCvTermCriteria(Count, 0.01);
                    EigenObjectRecognizer recognizer   = new EigenObjectRecognizer(trainingImages.ToArray(), labels.ToArray(), 1500, ref termCriteria);
                    name = recognizer.Recognize(result);
                    Frame.Draw(name, ref font, new Point(f.rect.X - 4, f.rect.Y - 4), new Bgr(Color.OrangeRed));
                }

                Users.Add("");
            }
            cameraBox.Image = Frame;
            names           = "";
            Users.Clear();
        }
        void FrameGrabber(object sender, EventArgs e)
        {
            NamePersons.Add("");


            currentFrame = grabber.QueryFrame().Resize(320, 240, Emgu.CV.CvEnum.INTER.CV_INTER_CUBIC);

            gray = currentFrame.Convert <Gray, Byte>();

            MCvAvgComp[][] facesDetected = gray.DetectHaarCascade(
                face,
                1.2,
                10,
                Emgu.CV.CvEnum.HAAR_DETECTION_TYPE.DO_CANNY_PRUNING,
                new Size(20, 20));

            foreach (MCvAvgComp f in facesDetected[0])
            {
                t      = t + 1;
                result = currentFrame.Copy(f.rect).Convert <Gray, byte>().Resize(100, 100, Emgu.CV.CvEnum.INTER.CV_INTER_CUBIC);
                currentFrame.Draw(f.rect, new Bgr(Color.Red), 2);


                if (trainingImages.ToArray().Length != 0)
                {
                    MCvTermCriteria termCrit = new MCvTermCriteria(ContTrain, 0.001);

                    EigenObjectRecognizer recognizer = new EigenObjectRecognizer(
                        trainingImages.ToArray(),
                        labels.ToArray(),
                        5000,
                        ref termCrit);

                    name = recognizer.Recognize(result);

                    currentFrame.Draw(name, ref font, new Point(f.rect.X - 2, f.rect.Y - 2), new Bgr(Color.LightGreen));
                }

                NamePersons[t - 1] = name;
                NamePersons.Add("");

                /*
                 * gray.ROI = f.rect;
                 * MCvAvgComp[][] eyesDetected = gray.DetectHaarCascade(
                 * eye,
                 * 1.1,
                 * 10,
                 * Emgu.CV.CvEnum.HAAR_DETECTION_TYPE.DO_CANNY_PRUNING,
                 * new Size(20, 20));
                 * gray.ROI = Rectangle.Empty;
                 *
                 * foreach (MCvAvgComp ey in eyesDetected[0])
                 * {
                 *  Rectangle eyeRect = ey.rect;
                 *  eyeRect.Offset(f.rect.X, f.rect.Y);
                 *  currentFrame.Draw(eyeRect, new Bgr(Color.Blue), 2);
                 * }
                 */
            }
            t = 0;

            for (int nnn = 0; nnn < facesDetected[0].Length; nnn++)
            {
                names = names + NamePersons[nnn] + ", ";
            }

            imageBoxFrameGrabber.Image = currentFrame;

            NamePersons.Clear();
        }