private void processNextFile()
        {
            _CurrentImagePathIndex++;

            // Start infront if we reach the end
            if (_CurrentImagePathIndex >= _ImagePathArray.Count)
            {
                _CurrentImagePathIndex = 0;
            }

            if (_CurrentImagePathIndex < _ImagePathArray.Count)
            {
                _KLU.ProcessStillImage((string)_ImagePathArray[_CurrentImagePathIndex], ref _ProcessOptions, ref _FFP);

                int width = 0, height = 0;
                _KLU.GetLastProcessedImageDims(ref width, ref height);

                if (_TempBitmap.Width != width || _TempBitmap.Height != height)
                {
                    Console.WriteLine("Need to resize the tmpBitmap to " + width + "x" + height);
                    _TempBitmap.Dispose();
                    GC.Collect();
                    _TempBitmap = new System.Drawing.Bitmap(width, height);
                }

                _KLU.GetLastProcessedImage(ref _TempBitmap);
                //_KLU.SetImageBrushFromBitmap(ref imageBrush, ref _TempBitmap);
                _KLU.SetWpfImageFromBitmap(ref image1, ref _TempBitmap);
            }
        }
示例#2
0
        private void ClassifyButton_Click(object sender, RoutedEventArgs e)
        {
            if (_SelectedFiles.Count < 1)
            {
                MessageBox.Show("You must at least pick 1 file to classify. Use the \"Browse\" button to look for image files.", "Request for file selection", MessageBoxButton.OK);
                return;
            }

            // Setup the progress bar
            ProgressBar.IsIndeterminate = false;
            ProgressBar.Maximum         = _SelectedFiles.Count;
            ProgressBar.Minimum         = 0;
            ProgressBar.Value           = 0;

            // Process all the selected images files in another thread.

            int expressionOID = (int)Convert.ToUInt32(ExpressionsComboBox.SelectedValue);

            for (int i = 0; i < _SelectedFiles.Count; i++)
            {
                _KLU.ProcessStillImage((string)_SelectedFiles[i], ref _ProcessOptions, ref _FFP);

                int width = 0, height = 0;
                _KLU.GetLastProcessedImageDims(ref width, ref height);

                if (_TempBitmap.Width != width || _TempBitmap.Height != height)
                {
                    Console.WriteLine("Need to resize the _TempBitmap to " + width + "x" + height);
                    _TempBitmap.Dispose();
                    GC.Collect();
                    _TempBitmap = new System.Drawing.Bitmap(width, height);
                }

                _KLU.GetLastProcessedImage(ref _TempBitmap);

                // Add the training data to the dataset
                ffp.MainWindow.AddTrainingData(ref _DataSet, ref _FFP, expressionOID, ref _TempBitmap);

                ProgressBar.Value = i + 1;
            }
        }
        private void DoWork(object sender, DoWorkEventArgs e)
        {
            BackgroundWorker worker = sender as BackgroundWorker;

            if (worker.CancellationPending)
            {
                e.Cancel = true;
                return;
            }

            int expressionOID = Convert.ToInt32(e.Argument);

            // Process all the selected images files in another thread.

            for (int i = 0; i < _SelectedFiles.Count; i++)
            {
                _KLU.ProcessStillImage((string)_SelectedFiles[i], ref _ProcessOptions, ref _FFP);

                int width = 0, height = 0;
                _KLU.GetLastProcessedImageDims(ref width, ref height);

                if (_TempBitmap.Width != width || _TempBitmap.Height != height)
                {
                    Console.WriteLine("Need to resize the _TempBitmap to " + width + "x" + height);
                    _TempBitmap.Dispose();
                    GC.Collect();
                    _TempBitmap = new System.Drawing.Bitmap(width, height);
                }

                _KLU.GetLastProcessedImage(ref _TempBitmap);

                // Add the training data to the dataset
                ffp.MainWindow.AddTrainingData(ref _DataSet, ref _FFP, expressionOID, ref _TempBitmap);

                if (i % 10 == 0 || i == (_SelectedFiles.Count - 1))
                {
                    worker.ReportProgress((int)(100 * (float)(i + 1) / (float)_SelectedFiles.Count));
                }
            }
        }
        /// <summary>
        /// The main entry point for this window.
        /// </summary>
        public MainWindow()
        {
            InitializeComponent();

            Console.WriteLine("Loc: " + System.Reflection.Assembly.GetExecutingAssembly().Location);

            try
            {
                _CurrentImagePathIndex = 0;
                _ImagePathArray        = new ArrayList();
                _ProcessOptions        = new ProcessOptions();
                _FFP = new FaceFeaturePoints();

                _ProcessOptions.DoEyeProcessing          = 1;
                _ProcessOptions.DoMouthProcessing        = 1;
                _ProcessOptions.DrawAnthropometricPoints = 0;
                _ProcessOptions.DrawSearchRectangles     = 0;
                _ProcessOptions.DrawFaceRectangle        = 1;
                _ProcessOptions.DrawDetectionTime        = 1;
                _ProcessOptions.DrawFeaturePoints        = 1;
                _ProcessOptions.DoVisualDebug            = 0;

                #region Intialize encapsulated OpenCV subsystem
                _KLU        = new Klu();
                _TempBitmap = new System.Drawing.Bitmap(10, 10);

                // Create a Timer with a Normal Priority
                _CaptureTimer = new DispatcherTimer(DispatcherPriority.ApplicationIdle, this.Dispatcher);

                // Set the callback to just show the time ticking away
                // NOTE: We are using a control so this has to run on
                // the UI thread
                _CaptureTimer.Tick += new EventHandler(
                    delegate(object s, EventArgs a)
                {
                    _KLU.ProcessCaptureImage(ref _ProcessOptions, ref _FFP);

                    // Ensure the image (bitmap) we are writing to has the correct dimensions
                    int width = 0, height = 0;
                    _KLU.GetLastProcessedImageDims(ref width, ref height);

                    if (_TempBitmap.Width != width || _TempBitmap.Height != height)
                    {
                        Console.WriteLine("Need to resize the _TempBitmap to " + width + "x" + height);
                        _TempBitmap.Dispose();
                        GC.Collect();
                        _TempBitmap = new System.Drawing.Bitmap(width, height);
                    }

                    _KLU.GetLastProcessedImage(ref _TempBitmap);
                    _KLU.SetWpfImageFromBitmap(ref image1, ref _TempBitmap);
                    //_KLU.SetImageBrushFromBitmap(ref imageBrush, ref _TempBitmap);
                }
                    );
                #endregion

                #region "Connect" to database
                _TAM     = new TableAdapterManager();
                _DataSet = new TrainingDataSet();

                // Load data from SQL database and fill our DataSet
                _TAM.ExpressionTableAdapter = new ExpressionTableAdapter();
                _TAM.TrainingTableAdapter   = new TrainingTableAdapter();

                LoadData();
                #endregion
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Error!", MessageBoxButton.OK, MessageBoxImage.Error);
            }
        }