/// <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 e) { MessageBox.Show(e.Message.ToString()); this.MainThread.Abort(); return; } }
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)); }
/// <summary> /// DatagridView click handling function /// </summary> private void loadingCellClickContent() { ProcessedRowData data = new ProcessedRowData(); data.RowID = int.Parse(mainDataGridView.SelectedRows[0].Cells[0].Value.ToString()); data.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)); ShowHideButtons(true); mainDataGridView.Refresh(); mainProgressBar.Value = data.RowID; ImageDisplay imageDisplayForm = new ImageDisplay(this.FaceDetector.makeFaceDetectedImage(data.FileName, data.Faces)); imageDisplayForm.Show(); }
/// <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; //mainDataGridView.Update(); //mainDataGridView.Refresh(); }
/// <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) { autoDetectButton.Visible = true; ShowHideButtons(true); loadButton.Visible = true; threadProcessButton.Visible = true; dirButton.Visible = true; } }
private void autoProcessBackgroundWorker_DoWork(object sender, DoWorkEventArgs e) { // autoprocessing main loop in the background wokre 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; } } }
/// <summary> /// function for detection /// </summary> private void commonDetect() { loadButton.Visible = false; 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 this.Hasprocessed = true; loadButton.Visible = true; mainProgressBar.Value = this.CurrentRowID; mainProgressBar.Update(); }