public BatchClassificationDialog(ref Klu klu, ref TrainingDataSet dataSet, ProcessOptions processOptions)
        {
            InitializeComponent();

            _BackgroundWorker = new BackgroundWorker();
            _BackgroundWorker.WorkerReportsProgress = true;
            _BackgroundWorker.WorkerSupportsCancellation = true;
            _BackgroundWorker.DoWork += new DoWorkEventHandler(DoWork);
            _BackgroundWorker.RunWorkerCompleted += new RunWorkerCompletedEventHandler(RunWorkerCompleted);
            _BackgroundWorker.ProgressChanged += new ProgressChangedEventHandler(ProgressChanged);        

            BrowseButton.IsEnabled = true;
            CancelButton.IsEnabled = false;
            ClassifyButton.IsEnabled = false;

            _DataSet = dataSet;
            _SelectedFiles = new ArrayList();
            _ProcessOptions = processOptions;
            // We want the images to be as less distorded as possible, so we disable all the overlays.

            _ProcessOptions.DrawAnthropometricPoints = 0;
            _ProcessOptions.DrawDetectionTime = 0;
            _ProcessOptions.DrawFaceRectangle = 0;
            _ProcessOptions.DrawSearchRectangles = 0;
            _ProcessOptions.DrawFeaturePoints = 0;
            
            _KLU = klu;
            _FFP = new FaceFeaturePoints();
            _TempBitmap = new System.Drawing.Bitmap(10, 10);

            ExpressionsComboBox.ItemsSource = _DataSet.Expression;
            ClassifyButton.Content = "Classify";
        }
        public BatchClassification(ref Klu klu, ref TrainingDataSet dataSet, ProcessOptions processOptions)
        {
            InitializeComponent();

            _DataSet = dataSet;
            _SelectedFiles = new ArrayList();
            _ProcessOptions = processOptions;
            // We want the images to be as less distorded as possible, so we disable all the overlays.

            _ProcessOptions.DrawAnthropometricPoints = 0;
            _ProcessOptions.DrawDetectionTime = 0;
            _ProcessOptions.DrawFaceRectangle = 0;
            _ProcessOptions.DrawSearchRectangles = 0;
            _ProcessOptions.DrawFeaturePoints = 0;
            
            _KLU = klu;
            _FFP = new FaceFeaturePoints();
            _TempBitmap = new System.Drawing.Bitmap(10, 10);

            ExpressionsComboBox.ItemsSource = _DataSet.Expression;
            ClassifyButton.Content = "Classify";
        }
예제 #3
0
 /// <summary>
 /// 
 /// </summary>
 /// <param name="filepath">Path to the file that shall be processed</param>
 /// <returns>true if successful; otherwise false</returns>
 public bool ProcessStillImage(string filepath, ref ProcessOptions options, ref FaceFeaturePoints ffp)
 {
     return (klu_processStillImage(filepath, options, ffp) == 1);
 }
예제 #4
0
 /// <summary>
 /// 
 /// </summary>
 /// <returns>true if successful; otherwise false</returns>
 public bool ProcessCaptureImage(ref ProcessOptions options, ref FaceFeaturePoints ffp)
 {
     return (klu_processCaptureImage(options, ffp) == 1);
 }
예제 #5
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="filepath">Path to the file that shall be processed</param>
 /// <returns>true if successful; otherwise false</returns>
 public bool ProcessStillImage(string filepath, ref ProcessOptions options, ref FaceFeaturePoints ffp)
 {
     return(klu_processStillImage(filepath, options, ffp) == 1);
 }
예제 #6
0
 private static extern int klu_processStillImage(
     [In, MarshalAs(UnmanagedType.LPStr)] string filepath,
     [In, MarshalAs(UnmanagedType.LPStruct)] ProcessOptions processOptions,
     [Out, MarshalAs(UnmanagedType.LPStruct)] FaceFeaturePoints ffp);
예제 #7
0
 /// <summary>
 ///
 /// </summary>
 /// <returns>true if successful; otherwise false</returns>
 public bool ProcessCaptureImage(ref ProcessOptions options, ref FaceFeaturePoints ffp)
 {
     return(klu_processCaptureImage(options, ffp) == 1);
 }
예제 #8
0
 private static extern int klu_processCaptureImage(
     [In, MarshalAs(UnmanagedType.LPStruct)] ProcessOptions processOptions,
     [Out, MarshalAs(UnmanagedType.LPStruct)] FaceFeaturePoints ffp);
예제 #9
0
        /// <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);
            }
        }
예제 #10
0
        public static void AddTrainingData(ref TrainingDataSet dataSet, ref FaceFeaturePoints ffp, int expressionOID, ref System.Drawing.Bitmap picture)
        {
            // Convert facial coordinates to relative face rectangle coordinates.
            // We do this because we are not interested in absolute coordinates but in quality of the face.

            int x = ffp.FaceRectangle.X;
            int y = ffp.FaceRectangle.Y;
            int w = ffp.FaceRectangle.Width;
            int h = ffp.FaceRectangle.Height;

            // Calculate the eye distance (in relative coordinates
            float dx = i2r(ffp.RightEye.EyeCenter.X, x, w) - i2r(ffp.LeftEye.EyeCenter.X, x, w);
            float dy = i2r(ffp.RightEye.EyeCenter.Y, y, h) - i2r(ffp.LeftEye.EyeCenter.Y, y, h);
            //float dx = i2r(ffp.RightEye.EyeCenter.X - ffp.LeftEye.EyeCenter.X, x, w);
            //float dy = i2r(ffp.RightEye.EyeCenter.Y - ffp.LeftEye.EyeCenter.Y, y, h);
            float eyeDist = (float)Math.Sqrt(dx * dx + dy * dy);

            // Construct thumbnail
            const int thumbnailWidth = 50;
            const int thumbnailHeight = 50;

            System.Drawing.Rectangle faceRect = new System.Drawing.Rectangle(x, y, w, h);
            System.Drawing.Bitmap faceImg = picture.Clone(faceRect, picture.PixelFormat);

            System.Drawing.Image.GetThumbnailImageAbort tc = new System.Drawing.Image.GetThumbnailImageAbort(ThumbnailCallback);
            System.Drawing.Image thumbnail = faceImg.GetThumbnailImage(thumbnailWidth, thumbnailHeight, tc, IntPtr.Zero);
            System.IO.MemoryStream ms = new System.IO.MemoryStream();
            thumbnail.Save(ms, System.Drawing.Imaging.ImageFormat.Png);

            TrainingDataSet.TrainingRow row = dataSet.Training.NewTrainingRow();

            row.ExpressionOID = expressionOID;
            row.LipCornerLeftX = i2r(ffp.Mouth.LipCornerLeft.X, x, w);
            row.LipCornerLeftY = i2r(ffp.Mouth.LipCornerLeft.Y, y, h);
            row.LipCornerRightX = i2r(ffp.Mouth.LipCornerRight.X, x, w);
            row.LipCornerRightY = i2r(ffp.Mouth.LipCornerRight.Y, y, h);
            row.LipUpLeftX = i2r(ffp.Mouth.LipUpLeft.X, x, w);
            row.LipUpLeftY = i2r(ffp.Mouth.LipUpLeft.Y, y, h);
            row.LipUpCenterX = i2r(ffp.Mouth.LipUpCenter.X, x, w);
            row.LipUpCenterY = i2r(ffp.Mouth.LipUpCenter.Y, y, h);
            row.LipUpRightX = i2r(ffp.Mouth.LipUpRight.X, x, w);
            row.LipUpRightY = i2r(ffp.Mouth.LipUpRight.Y, y, h);
            row.LipUpRightX = i2r(ffp.Mouth.LipBottomLeft.X, x, w);
            row.LipUpRightY = i2r(ffp.Mouth.LipBottomLeft.Y, y, h);
            row.LipBottomCenterX = i2r(ffp.Mouth.LipBottomCenter.X, x, w);
            row.LipBottomCenterY = i2r(ffp.Mouth.LipBottomCenter.Y, y, h);
            row.LipBottomRightX = i2r(ffp.Mouth.LipBottomRight.X, x, w);
            row.LipBottomRightY = i2r(ffp.Mouth.LipBottomRight.Y, y, h);
            row.LipBottomLeftX = i2r(ffp.Mouth.LipBottomLeft.X, x, w);
            row.LipBottomLeftY = i2r(ffp.Mouth.LipBottomLeft.Y, y, h);
            row.EyeDistance = eyeDist;
            row.LeftEyeCenterX = i2r(ffp.LeftEye.EyeCenter.X, x, w);
            row.LeftEyeCenterY = i2r(ffp.LeftEye.EyeCenter.Y, y, h);
            row.LeftLidBottomX = i2r(ffp.LeftEye.LidBottomCenter.X, x, w);
            row.LeftLidBottomY = i2r(ffp.LeftEye.LidBottomCenter.Y, y, h);
            row.LeftLidCornerLeftX = i2r(ffp.LeftEye.LidCornerLeft.X, x, w);
            row.LeftLidCornerLeftY = i2r(ffp.LeftEye.LidCornerLeft.Y, y, h);
            row.LeftLidCornerRightX = i2r(ffp.LeftEye.LidCornerRight.X, x, w);
            row.LeftLidCornerRightY = i2r(ffp.LeftEye.LidCornerRight.Y, y, h);
            row.LeftLidUpX = i2r(ffp.LeftEye.LidUpCenter.X, x, w);
            row.LeftLidUpY = i2r(ffp.LeftEye.LidUpCenter.Y, y, h);
            row.RightEyeCenterX = i2r(ffp.RightEye.EyeCenter.X, x, w);
            row.RightEyeCenterY = i2r(ffp.RightEye.EyeCenter.Y, y, h);
            row.RightLidBottomX = i2r(ffp.RightEye.LidBottomCenter.X, x, w);
            row.RightLidBottomY = i2r(ffp.RightEye.LidBottomCenter.Y, y, h);
            row.RightLidCornerLeftX = i2r(ffp.RightEye.LidCornerLeft.X, x, w);
            row.RightLidCornerLeftY = i2r(ffp.RightEye.LidCornerLeft.Y, y, h);
            row.RightLidCornerRightX = i2r(ffp.RightEye.LidCornerRight.X, x, w);
            row.RightLidCornerRightY = i2r(ffp.RightEye.LidCornerRight.Y, y, h);
            row.RightLidUpX = i2r(ffp.RightEye.LidUpCenter.X, x, w);
            row.RightLidUpY = i2r(ffp.RightEye.LidUpCenter.Y, y, h);
            row.MouthCenterX = i2r(ffp.Mouth.MouthCenter.Y, y, h);
            row.MouthCenterY = i2r(ffp.Mouth.MouthCenter.Y, y, h);
            
            row.Thumbnail = ms.ToArray();

            dataSet.Training.AddTrainingRow(row);
        }