protected override Mat GetFaces(Mat frame, out FacesList facesList)
        {
            // debug - replace video stream with still image for testing
            //var file = "C:\\Users\\Lamby\\Documents\\Visual Studio 2017\\Projects\\TrackingCamera\\TrackingCamera\\DetectorClasses\\ModelDetectorVGG_VOC0712Plus\\bali-crop.jpg";
            string file = "C:\\Users\\Lamby\\Desktop\\fd-acc-result3-e1539872783684.jpg";

            frame = Cv2.ImRead(file);

            Mat imageBlob = CvDnn.BlobFromImage(frame, 1.0, new Size(300, 300),
                                                new Scalar(104.0, 177.0, 123.0), false, false);

            this.Detector.SetInput(imageBlob, "data");
            Mat detections = this.Detector.Forward("detection_out");

            //reshape from [1,1,200,7] to [200,7]
            Mat detectionMat = detections.Reshape(1, detections.Size(2));

            // debug
            //GetFaceBestConfidence(detections, out int faceId, out double faceProbability);

            if (detectionMat.Rows <= 0)             //
            {
                facesList = new FacesList();
                return(null);
            }
            else
            {
                facesList = new FacesList();
                Scalar rgbColour = new Scalar(0, 255, 255);

                for (int i = 0; i < detectionMat.Rows; i++)
                {
                    var confidence = detectionMat.At <float>(i, 2);

                    if (confidence > this.MinConfidence)
                    {
                        int X1 = (int)(detectionMat.At <float>(i, 3) * frame.Width);                          //detectionMat.At<int> returns 0 with this floating point caffe model?
                        int Y1 = (int)(detectionMat.At <float>(i, 4) * frame.Height);
                        int X2 = (int)(detectionMat.At <float>(i, 5) * frame.Width);
                        int Y2 = (int)(detectionMat.At <float>(i, 6) * frame.Height);

                        frame.Rectangle(new Point(X1, Y1), new Point(X2, Y2), rgbColour, 2, OpenCvSharp.LineTypes.Link4);
                        string faceText = String.Format("{0:P2}", confidence);
                        Cv2.PutText(frame, faceText, new Point(X1, Y2 + 9), HersheyFonts.HersheyComplex, 0.3, rgbColour);

                        var faceMat = frame[new Rect(X1, Y1, X2 - X1, Y2 - Y1)];
                        facesList.Add(new Face(faceMat, new Point(X1, Y1), new Point(X2, Y2), confidence));

                        // Debug
                        //Cv2.ImShow("Detected Face", faceMat);
                        //Cv2.WaitKey(1);
                    }
                }

                return(frame);
            }
        }
示例#2
0
        public override Mat Detect(Mat frame, out FacesList facesList)
        {
            facesList = new FacesList();
            try
            {
                return(GetFaces(frame, out facesList));
            }
            catch (Exception detail)
            {
                Globals.Log.Error(detail);
            }

            return(null);
        }
示例#3
0
 protected abstract Mat GetFaces(Mat frame, out FacesList facesList);
 public abstract Mat Detect(Mat frame, out FacesList facesList);