protected override void RecognizeFace(Image <Bgr, byte> face)
        {
            if (students.Length != 0)
            {
                //RESIZE THE FACE TO BE RECOGNIZED SO ITS EQUAL TO THE FACES ALREADY IN THE TRAINING SET
                int width  = 120;
                int height = 120;

                face = FramesManager.ResizeColoredImage(face, new Size(width, height));

                //ATTEMPT TO RECOGNIZE THE PERPETRATOR
                face_recognition_result = faces_manager.MatchFace(face);

                //IF A VALID ID IS RETURMED
                if (face_recognition_result.match_was_found)
                {
                    //GET STUDENT ASSOCIATED WITH ID
                    foreach (var student in students)
                    {
                        if (student.id == face_recognition_result.id)
                        {
                            face_recognition_result.identified_student = student;
                            break;
                        }
                    }
                }

                return;
            }
        }
        private void AddDetectedFacesToListViewPanel()
        {
            try
            {
                if (its_time_to_pick_perpetrator_faces)
                {
                    if (detected_faces != null && current_frame != null)
                    {
                        ImageListView image_list_view = Singleton.SELECT_PERP_FACES.GetImageListView();

                        for (int i = 0; i < detected_faces.Length; i++)
                        {
                            //get face
                            Image <Bgr, byte> face = FramesManager.CropSelectedFace(detected_faces[i], current_frame.Clone());

                            //resize face
                            face = FramesManager.ResizeColoredImage(face, new Size(120, 120));

                            //add face to image list
                            Singleton.SELECT_PERP_FACES.suspect_faces.TryAdd(count, face);

                            //add face to image list view
                            image_list_view.Invoke(new AddImage(Singleton.SELECT_PERP_FACES.AddImage), new object[] { "face " + count, "face " + count, face.ToBitmap() });

                            //increment id counter
                            count++;
                        }
                    }
                }
            }
            catch (Exception e)
            {
                Debug.WriteLine(e.Message);
            }
        }
Ejemplo n.º 3
0
        //ADDS A CAPTURED FRAME TO A THREAD SAFE QUEUE FOR EASY ACESS WHEN THE FRAME IS PROCESSED BY MULTIPLE FRAMES
        public bool AddNextFrameToQueueForProcessing()
        {
            using (current_frame = FramesManager.GetNextFrame(camera.camera_capture))
            {
                if (current_frame != null)
                {
                    int  width    = Singleton.MAIN_WINDOW.GetControl(MainWindow.MainWindowControls.review_image_box).Width;
                    int  height   = Singleton.MAIN_WINDOW.GetControl(MainWindow.MainWindowControls.review_image_box).Height;
                    Size new_size = new Size(width, height);

                    Singleton.REVIEW_FRAMES_TO_BE_PROCESSED.Enqueue(FramesManager.ResizeColoredImage(current_frame.Clone(), new_size));

                    return(true);
                }

                //FRAME IS NULL
                //MEANING END OF FILE IS REACHED
                else
                {
                    //ADD BLACK FRAME TO DATASTORE AND TERMINATE THREAD
                    //ALSO SIGNAL TO OTHERS THAT THIS THREAD IS DONE
                    WORK_DONE = true;
                    running   = false;
                    Debug.WriteLine("Terminating video from file");
                    return(false);
                }
            }
        }
Ejemplo n.º 4
0
        protected override void RecognizeFace(Image <Bgr, byte> face)
        {
            if (active_perpetrators.Length != 0)
            {
                //RESIZE THE FACE TO RECOGNIZE SO ITS EQUAL TO THE FACES ALREADY IN THE TRAINING SET
                int width  = 120;
                int height = 120;

                face = FramesManager.ResizeColoredImage(face, new Size(width, height));

                //GET ID OF MOST SIMILAR PERPETRATOR
                FaceRecognitionResult result = faces_manager.MatchFace(face);

                //IF A VALID RESULT IS RETURNED
                if (result != null)
                {
                    //IF A VALID ID IS RETURMED
                    if (result.match_was_found)
                    {
                        //GET PERPETRATOR ASSOCIATED WITH ID
                        foreach (var perp in active_perpetrators)
                        {
                            if (perp.id == result.id)
                            {
                                result.identified_perpetrator = perp;
                                break;
                            }
                        }
                    }
                    Singleton.FACE_RECOGNITION_RESULTS.Enqueue(result);
                }
                return;
            }
        }
Ejemplo n.º 5
0
        public void FramesManagerResizeImageTest()
        {
            Image <Bgr, byte> image = new Image <Bgr, byte>(new Bitmap(100, 100));
            Size new_size           = new Size(10, 10);

            image = FramesManager.ResizeColoredImage(image, new_size);
            Assert.IsNotNull(image);
        }
        private void ShowFaceRecognitionProgress()
        {
            //THIS KEEPS TRACK OF PROGRESS
            double progress_decimal = 1;

            //DISPLAY EACH OF PERPETRATORS' FACES IN THE PERPETRATORS PICTURE BOX FOR A FLEETING MOMEMNT;REPEAT TILL ALL FACES ARE DONE
            foreach (var student in students)
            {
                for (int i = 0; i < student.photos.Length; i++)
                {
                    //GET THE AMOUNT OF WORK DONE                           PERPS.LENGTH*5 COZ EACH PERP HAS A MINIMUM OF 5 FACES
                    int percentage_completed = (int)(((progress_decimal / (students.Length * 5) * 100)));

                    //RESIZE THE FACE TO RECOGNIZE SO ITS EQUAL TO THE FACES ALREADY IN THE TRAINING SET
                    int width  = 120;
                    int height = 120;

                    student.photos[i] = FramesManager.ResizeColoredImage(student.photos[i], new Size(width, height));

                    //DISPLAY STUDENT FACE
                    SetControlPropertyThreadSafe(perpetrators_pictureBox, "Image", student.photos[i].ToBitmap());

                    if (percentage_completed >= 100)
                    {
                        if (face_recognition_result.match_was_found)
                        {
                            //UPDATE PROGRESS LABEL
                            progress_label.ForeColor = Color.Purple;
                            SetControlPropertyThreadSafe(progress_label, "Text", "Match\nFound");

                            //DISPLAY IDENTIFIED STUDENT FACE
                            SetControlPropertyThreadSafe(perpetrators_pictureBox, "Image", face_recognition_result.identified_student.photos[0].ToBitmap());
                        }
                        else
                        {
                            //UPDATE PROGRESS LABEL
                            progress_label.ForeColor = Color.Red;
                            SetControlPropertyThreadSafe(progress_label, "Text", "No\nMatch\nFound");
                        }
                    }
                    else
                    {
                        //UPDATE PROGRESS LABEL
                        SetControlPropertyThreadSafe(progress_label, "Text", "" + percentage_completed + "%");
                    }

                    //LET THE THREAD SLEEP
                    Thread.Sleep(SLEEP_TIME);

                    progress_decimal++;
                }
            }
        }
Ejemplo n.º 7
0
        //ADDS A CAPTURED FRAME TO THREAD SAFE QUEUES
        //FOR EASY ACESS WHEN THE FRAME IS PROCESSED BY MULTIPLE THREADS LATER
        public bool AddNextFrameToQueuesForProcessing()
        {
            //get next frame from camera
            current_frame = FramesManager.GetNextFrame(camera_capture);

            if (current_frame != null)
            {
                int  new_width  = Singleton.MAIN_WINDOW.GetControl(MainWindow.MainWindowControls.live_stream_image_box1).Width;
                int  new_height = Singleton.MAIN_WINDOW.GetControl(MainWindow.MainWindowControls.live_stream_image_box1).Height;
                Size new_size   = new Size(new_width, new_height);

                //add frame to queue for display
                Singleton.LIVE_FRAMES_TO_BE_DISPLAYED.Enqueue(FramesManager.ResizeColoredImage(current_frame.Clone(), new_size));

                //add frame to queue for storage
                Singleton.FRAMES_TO_BE_STORED.Enqueue(current_frame.Clone());

                //resize frame to save on memory and improve performance
                int width  = Singleton.MAIN_WINDOW.GetControl(MainWindow.MainWindowControls.review_image_box).Width;
                int height = Singleton.MAIN_WINDOW.GetControl(MainWindow.MainWindowControls.review_image_box).Height;

                Size size = new Size(width, height);

                current_frame = FramesManager.ResizeColoredImage(current_frame, size);

                //add frame to queue for face detection and recognition
                Singleton.LIVE_FRAMES_TO_BE_PROCESSED.Enqueue(current_frame.Clone());

                //return
                return(true);
            }

            //FRAME IS NULL
            //MEANING END OF FILE IS REACHED
            else
            {
                //ADD BLACK FRAME TO DATASTORE AND TERMINATE THREAD
                //ALSO SIGNAL TO OTHERS THAT THIS THREAD IS DONE
                WORK_DONE = true;
                running   = false;

                Debug.WriteLine("Terminating camera output");
                return(false);
            }
        }
Ejemplo n.º 8
0
        public bool DisplayFaceRecognitionProgress(Image <Bgr, byte> face)
        {
            if (face != null)
            {
                //IF THERE ARE PERPETRATORS TO COMPARE AGAINIST
                if (active_perpetrators.Length != 0)
                {
                    //RESIZE THE FACE TO RECOGNIZE SO ITS EQUAL TO THE FACES ALREADY IN THE TRAINING SET
                    int width  = 120;
                    int height = 120;

                    face = FramesManager.ResizeColoredImage(face, new Size(width, height));

                    //CLEAR PANEL IF ITEMS ARE TOO MANY
                    ClearPanelIfItemsAreMany();

                    //CREATE PICTURE BOX FOR FACE TO BE RECOGNIZED
                    unknown_face_pictureBox             = new MyPictureBox();
                    unknown_face_pictureBox.Location    = new Point(10, 10);
                    unknown_face_pictureBox.Size        = new Size(120, 120);
                    unknown_face_pictureBox.BorderStyle = BorderStyle.FixedSingle;
                    unknown_face_pictureBox.Image       = face.ToBitmap();

                    //CREATE PICTURE BOX FOR PERPETRATORS
                    perpetrators_pictureBox             = new MyPictureBox();
                    perpetrators_pictureBox.Location    = new Point(185, 10);
                    perpetrators_pictureBox.Size        = new Size(120, 120);
                    perpetrators_pictureBox.BorderStyle = BorderStyle.FixedSingle;

                    //CREATE PROGRESS LABEL
                    progress_label           = new Label();
                    progress_label.Location  = new Point(143, 60);
                    progress_label.ForeColor = Color.Green;
                    progress_label.Text      = "0%";

                    //CREATE PANEL CONTAINER FOR THE ABOVE CONTROLS
                    Panel panel = new Panel();
                    panel.AutoSize    = true;
                    panel.Location    = new Point(x, y);
                    panel.BorderStyle = BorderStyle.FixedSingle;
                    panel.Padding     = new Padding(10);

                    panel.Controls.AddRange(new Control[] { unknown_face_pictureBox, perpetrators_pictureBox, progress_label });

                    //SINCE THIS THREAD IS STARTED OFF THE GUI THREAD THEN INVOKES MAY BE REQUIRED
                    if (panel_live_stream.InvokeRequired)
                    {
                        //ADD GUI CONTROLS USING INVOKES
                        Action action = () => panel_live_stream.Controls.Add(panel);
                        panel_live_stream.Invoke(action);
                    }

                    //IF NO INVOKES ARE NEEDED THEN
                    else
                    {
                        //JUST ADD THE CONTROLS
                        panel_live_stream.Controls.Add(panel);
                    }

                    //CREATE A NEW PROGRESS THREAD TO SHOW FACE RECOG PROGRESS
                    ShowFaceRecognitionProgress();

                    //INCREASE THE GLOBAL Y SO NEXT PIC BOXES ARE DRAWN BELOW THIS ONE
                    y += 145;
                    return(true);
                }
            }
            return(false);
        }