我正在使用 Windows 7 x64,EmguCV 2.4.9。当我在笔记本电脑上运行代码时,它在下面显示了这个问题。在我的桌面中,代码运行良好。谁能告诉我是什么问题:
代码如下:
public MainWindow()
{
InitializeComponent();
}
void timer_Tick(object sender, EventArgs e)
{
Image<Bgr, Byte> currentFrame = capture.QueryFrame();
if (currentFrame != null)
{
Image<Gray, Byte> grayFrame = currentFrame.Convert<Gray, Byte>();
**var detectedFaces = grayFrame.DetectHaarCascade(haarCascade)[0]; ///Problem arises in this line::: SEHException was unhandeled**
foreach (var face in detectedFaces)
currentFrame.Draw(face.rect, new Bgr(0, double.MaxValue, 0), 3);
image1.Source = ToBitmapSource(currentFrame);
}
}
[DllImport("gdi32")]
private static extern int DeleteObject(IntPtr o);
public static BitmapSource ToBitmapSource(IImage image)
{
using (System.Drawing.Bitmap source = image.Bitmap)
{
IntPtr ptr = source.GetHbitmap(); //obtain the Hbitmap
BitmapSource bs = System.Windows.Interop.Imaging.CreateBitmapSourceFromHBitmap(
ptr,
IntPtr.Zero,
Int32Rect.Empty,
System.Windows.Media.Imaging.BitmapSizeOptions.FromEmptyOptions());
DeleteObject(ptr); //release the HBitmap
return bs;
}
}
private void Window_Loaded(object sender, RoutedEventArgs e)
{
capture = new Capture();
haarCascade = new HaarCascade(@"C:\Emgu\emgucv-windows-universal-gpu 2.4.9.1847\opencv\data\haarcascades\haarcascade_frontalface_default.xml");
timer = new DispatcherTimer();
timer.Tick += new EventHandler(timer_Tick);
timer.Interval = new TimeSpan(0, 0, 0);
timer.Start();
}
}
}
我已经在我的 bin\debug 和 system32 中复制了 opencv_xxx.dll。但仍然遇到问题。一些帮助将不胜感激。