Esempio n. 1
0
        /// <summary>
        /// Thread processing main loop fucntion
        /// </summary>
        private void StartThreadProcessing()
        {
            try
            {
                for (int i = 0; i < this.ImageFilelist.Length; i++)
                {
                    this.CurrentRowID = i;
                    string           filename = this.ImageFilelist[this.CurrentRowID];
                    Rect[]           faces    = this.FaceDetector.GetDetectedFaces(filename);
                    ProcessedRowData data     = new ProcessedRowData(this.CurrentRowID, filename, faces);

                    //invoking main delegate finction to update UI thread
                    this.Invoke(new UpDateDisplayImagesDelegate(UpDateDisplayImages), data);

                    // adding sleep to slow down for lesser cpu power load.
                    Thread.Sleep(100);
                }
            }
            catch (Exception)
            {
                this.MainThread.Abort();
            }
            finally
            {
                this.Invoke(new FinalThreadActivationDeligation(FinalThreadActivation));
            }
        }
Esempio n. 2
0
        /// <summary>
        /// DatagridView click handling function
        /// </summary>
        private void LoadingCellClickContent()
        {
            //TODO fix form creation mode

            ProcessedRowData data = new ProcessedRowData
            {
                RowID    = int.Parse(mainDataGridView.SelectedRows[0].Cells[0].Value.ToString()),
                FileName = mainDataGridView.SelectedRows[0].Cells[1].Value.ToString()
            };

            data.Faces            = data.setRectFromXML(mainDataGridView.SelectedRows[0].Cells[3].Value.ToString());
            data.DetectFaceNumber = int.Parse(mainDataGridView.SelectedRows[0].Cells[2].Value.ToString());
            MainPictureBoxImageSet(this.FaceDetector.MakeFaceDetectedImage(data.FileName, data.Faces));
            mainProgressBar.Value = data.RowID;

            if (Application.OpenForms.OfType <ImageDisplay>().Count() == 1)
            {
                Application.OpenForms.OfType <ImageDisplay>().First().Close();
            }

            ImageDisplay imageDisplayForm = new ImageDisplay();

            imageDisplayForm.MainPictureBoxImageSet(this.FaceDetector.MakeFaceDetectedImage(data.FileName, data.Faces));
            imageDisplayForm.Show();
        }
Esempio n. 3
0
        private void AutoProcessBackgroundWorker_ProgressChanged(object sender, ProgressChangedEventArgs e)
        {
            // updating UI from the background worker, sender ohject is from the AutoProcessBackgroundWorker_DoWork()
            mainProgressBar.Value = e.ProgressPercentage;
            ProcessedRowData rowData = (ProcessedRowData)e.UserState;

            this.UpdateDataset(rowData);
            mainProgressBar.Value = rowData.RowID;
            MainPictureBoxImageSet(this.FaceDetector.MakeFaceDetectedImage(rowData.FileName, rowData.Faces));
        }
Esempio n. 4
0
        /// <summary>
        /// function updating the Dataset for both single and auto processing
        /// </summary>
        /// <param name="rowData">ProcessedRowData obj </param>
        public void UpdateDataset(ProcessedRowData rowData)
        {
            DataRow dataRow = this.MainTable.NewRow();

            dataRow["Row ID"]               = rowData.RowID.ToString();
            dataRow["File Name"]            = rowData.FileName;
            dataRow["Detected Face Number"] = rowData.DetectFaceNumber.ToString();
            dataRow["Detected Face(s)"]     = rowData.getSerializeRectforXML().ToString();

            this.MainTable.Rows.Add(dataRow);
            mainDataGridView.DataSource    = this.MainDataSet.Tables[0];
            mainDataGridView.SelectionMode = DataGridViewSelectionMode.FullRowSelect;
            mainDataGridView.ReadOnly      = true;
        }
Esempio n. 5
0
        /// <summary>
        /// deligate calling function for update UI from background thread
        /// </summary>
        /// <param name="processedRowData"></param>
        private void UpDateDisplayImages(ProcessedRowData processedRowData)
        {
            mainProgressBar.Maximum = this.ImageFilelist.Length - 1;
            this.UpdateDataset(processedRowData);

            this.CurrentRowID     = processedRowData.RowID;
            mainProgressBar.Value = processedRowData.RowID;
            MainPictureBoxImageSet(this.FaceDetector.MakeFaceDetectedImage(processedRowData.FileName, processedRowData.Faces));


            if (mainProgressBar.Value == mainProgressBar.Maximum)
            {
                threadProcessButton.Text = "Thread Process";
                processLabel.Text        = "Process";
            }
        }
Esempio n. 6
0
        /// <summary>
        /// function for detection
        /// </summary>
        private void CommonDetect()
        {
            int    id       = this.CurrentRowID;
            string filename = this.ImageFilelist[id];

            // getting the detected faces
            Rect[] faces = this.FaceDetector.GetDetectedFaces(filename);

            //making the row data
            ProcessedRowData data = new ProcessedRowData(id, filename, faces);

            //setting the images in picturebox
            MainPictureBoxImageSet(FaceDetector.GetFaceDetectedBitmapImage(filename));

            // adding the result in datagridview
            UpdateDataset(data);

            //updating UI
            mainProgressBar.Value = this.CurrentRowID;
            mainProgressBar.Update();
        }
Esempio n. 7
0
        private void AutoProcessBackgroundWorker_DoWork(object sender, DoWorkEventArgs e)
        {
            // autoprocessing main loop in the background work


            for (int i = 0; i < this.ImageFilelist.Length; i++)
            {
                this.CurrentRowID = i;
                string           filename = this.ImageFilelist[this.CurrentRowID];
                Rect[]           faces    = this.FaceDetector.GetDetectedFaces(filename);
                ProcessedRowData data     = new ProcessedRowData(this.CurrentRowID, filename, faces);
                autoProcessBackgroundWorker.ReportProgress(i, data);

                // adding thread waiting for CPU usage conservation.
                Thread.Sleep(200);

                if (autoProcessBackgroundWorker.CancellationPending)
                {
                    // handling cancel from button clicking
                    break;
                }
            }
        }
Esempio n. 8
0
        private void TaskProcessButton_Click(object sender, EventArgs e)
        {
            this.MainAction = new Action(() =>
            {
                // task action will have the main loop, in the loop various invokes for updating the UI elements will be called


                for (int i = 0; i < this.ImageFilelist.Length; i++)
                {
                    if (this.MainCancellationToken.IsCancellationRequested)
                    {
                        this.MainCancellationTokenSource = new CancellationTokenSource();
                        this.MainCancellationToken       = this.MainCancellationTokenSource.Token;
                        break;
                    }


                    // mainProgressBar
                    Action progressBarAction = new Action(() =>
                    {
                        this.CurrentRowID     = i;
                        mainProgressBar.Value = i;
                    });

                    mainProgressBar.Invoke(progressBarAction);

                    //datagridView
                    this.CurrentRowID = i;
                    string filename   = this.ImageFilelist[this.CurrentRowID];
                    Rect[] faces      = this.FaceDetector.GetDetectedFaces(filename);
                    ProcessedRowData processedRowData = new ProcessedRowData(this.CurrentRowID, filename, faces);

                    Action dataGridViewAction = new Action(() =>
                    {
                        this.UpdateDataset(processedRowData);
                    });
                    mainDataGridView.Invoke(dataGridViewAction);
                    //
                    Action pictureBoxSetAction = new Action(() =>
                    {
                        MainPictureBoxImageSet(this.FaceDetector.MakeFaceDetectedImage(processedRowData.FileName, processedRowData.Faces));
                    });
                    mainPictureBox.Invoke(pictureBoxSetAction);

                    //slowing down talk for less CPU load
                    Thread.Sleep(100);
                }
                Action finalAction = new Action(() =>
                {
                    processLabel.Text      = "Process";
                    taskProcessbutton.Text = "Task Process";
                    //autoDetectButton.Enabled = true;
                    //threadProcessButton.Enabled = true;
                    this.ThreadFlag = false;
                    this.ThreadType = (int)THREAD_TYPE.NONE;
                });
                this.Invoke(finalAction);
            });


            if ((this.ThreadType == (int)THREAD_TYPE.NONE) || (this.ThreadType == (int)THREAD_TYPE.TASK))
            {
                try
                {
                    Monitor.TryEnter(this.ProcessLock, this.TTimeout, ref this.LockTaken);
                    if (this.LockTaken)
                    {
                        if (this.HasDir && this.IsInitialized)
                        {
                            if (!this.ThreadFlag)
                            {
                                Task.Run(MainAction, MainCancellationToken);
                                this.ThreadFlag        = true;
                                this.ThreadType        = (int)THREAD_TYPE.TASK;
                                taskProcessbutton.Text = "Cancel";
                                processLabel.Text      = "Task Processing";
                                //autoDetectButton.Enabled = false;
                                //threadProcessButton.Enabled = false;
                            }
                            else
                            {
                                taskProcessbutton.Text = "Task Process";
                                MainCancellationTokenSource.Cancel();
                                this.ThreadFlag   = false;
                                this.ThreadType   = (int)THREAD_TYPE.NONE;
                                processLabel.Text = "Process";
                                //autoDetectButton.Enabled = true;
                                //threadProcessButton.Enabled = true;
                            }
                        }
                    }
                }
                catch (Exception exception)
                {
                    MessageBox.Show(exception.Message.ToString());
                }
                finally
                {
                    if (this.LockTaken)
                    {
                        Monitor.Exit(this.ProcessLock);
                        this.LockTaken = false;
                    }
                }
            }
        }