title: emgu cv - exception with DetectMultiScale
body: <p>I try to detect faces on picture using emgu CV but i faced an exception</p>
  
  <pre><code>SEHException was unhandled
  </code></pre>
  
  <p>on</p>
  
  <p><code>Rectangle[] facesDetected = face.DetectMultiScale(gray, 1.1, 10, new Size(20, 20), Size.Empty);</code></p>
  
  <p>Code:</p>
  
  <pre><code>using System;
  using System.Collections.Generic;
  using System.ComponentModel;
  using System.Data;
  using System.Drawing;
  using System.Linq;
  using System.Text;
  using System.Windows.Forms;
  using Emgu.CV.Structure;
  using Emgu.CV;
  using System.Runtime.InteropServices;
  using Emgu.CV.GPU;
  using Emgu.CV.CvEnum;
  
  
  namespace WindowsFormsApplication1
  {
      public partial class Form1 : Form
      {
          Capture capture;
          Image&lt;Bgr, Byte&gt; image;
          bool captureInProgress;
          List&lt;Rectangle&gt; faces = new List&lt;Rectangle&gt;();
  
          public Form1()
          {
              InitializeComponent();
          }
  
          void ShowFromCam(object sender, EventArgs e){
              image = capture.QueryFrame();
          }
  
          private void button1_Click(object sender, EventArgs e)
          {
              if (capture == null)
              {
                  try
                  {
                      capture = new Capture();
  
                      CascadeClassifier face = new CascadeClassifier("haarcascade_frontalface_default.xml");
                      Image&lt;Gray, Byte&gt;  gray = capture.RetrieveGrayFrame();
                      Rectangle[] facesDetected = face.DetectMultiScale(
                          gray,               //image
                          1.1,                //scaleFactor
                          10,                 //minNeighbors
                          new Size(20, 20),   //minSize
                          Size.Empty);        //maxSize
                      faces.AddRange(facesDetected);
                      //Draw detected faces
                      foreach (Rectangle face1 in faces)
                          image.Draw(face1, new Bgr(Color.Red), 2);
                  }
                  catch (NullReferenceException excpt)
                  {
                      MessageBox.Show(excpt.Message);
                  }
              }
  
              if (capture != null)
              {
                  if (captureInProgress)
                  {  //if camera is getting frames then stop the capture and set button Text
                      // "Start" for resuming capture
                      button1.Text = "Start!"; //
                      Application.Idle -= ShowFromCam;
                  }
                  else
                  {
                      //if camera is NOT getting frames then start the capture and set button
                      // Text to "Stop" for pausing capture
                      button1.Text = "Stop";
                      Application.Idle += ShowFromCam;
                  }
                  captureInProgress = !captureInProgress;
              }
          }
  }
  </code></pre>
  
  <p>detailed exception:</p>
  
  <pre><code>System.Runtime.InteropServices.SEHException was unhandled
    Message=External component has thrown an exception.
    Source=Emgu.CV
    ErrorCode=-2147467259
    StackTrace:
         at Emgu.CV.CvInvoke.CvCascadeClassifierDetectMultiScale(IntPtr classifier, IntPtr image, IntPtr objects, Double scaleFactor, Int32 minNeighbors, Int32 flags, Size minSize, Size maxSize)
         at Emgu.CV.CascadeClassifier.DetectMultiScale(Image`2 image, Double scaleFactor, Int32 minNeighbors, Size minSize, Size maxSize)
         at WindowsFormsApplication1.Form1.button1_Click(Object sender, EventArgs e) in c:\users\moamen\documents\visual studio 2010\Projects\WindowsFormsApplication1\WindowsFormsApplication1\Form1.cs:line 44
         at System.Windows.Forms.Control.OnClick(EventArgs e)
         at System.Windows.Forms.Button.OnClick(EventArgs e)
         at System.Windows.Forms.Button.OnMouseUp(MouseEventArgs mevent)
         at System.Windows.Forms.Control.WmMouseUp(Message&amp; m, MouseButtons button, Int32 clicks)
         at System.Windows.Forms.Control.WndProc(Message&amp; m)
         at System.Windows.Forms.ButtonBase.WndProc(Message&amp; m)
         at System.Windows.Forms.Button.WndProc(Message&amp; m)
         at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message&amp; m)
         at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message&amp; m)
         at System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
         at System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG&amp; msg)
         at System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(IntPtr dwComponentID, Int32 reason, Int32 pvLoopData)
         at System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context)
         at System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context)
         at System.Windows.Forms.Application.Run(Form mainForm)
         at WindowsFormsApplication1.Program.Main() in c:\users\moamen\documents\visual studio 2010\Projects\WindowsFormsApplication1\WindowsFormsApplication1\Program.cs:line 18
         at System.AppDomain._nExecuteAssembly(RuntimeAssembly assembly, String[] args)
         at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
         at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
         at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
         at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean ignoreSyncCtx)
         at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
         at System.Threading.ThreadHelper.ThreadStart()
    InnerException: 
  </code></pre>
  
  <p>Thanks in advance :)</p>