我正在尝试在 Visual Studio 2010 中使用 EMGU CV 捕获视频,但是当它执行该行时
video.WriteFrame<Bgr, byte>(marked);
我得到以下错误:
System.AccessViolationException 未处理
尝试读取或写入受保护的内存。这通常表明其他内存已损坏。
private void button3_Click_1(object sender, EventArgs e)
{
Capture camera = new Capture();
if (camera == null)
{
MessageBox.Show("can't find a camera", "error");
}
double fps = camera.GetCaptureProperty(CAP_PROP.CV_CAP_PROP_FPS);
double cpHeight = camera.GetCaptureProperty(CAP_PROP.CV_CAP_PROP_FRAME_HEIGHT);
double cpWidth = camera.GetCaptureProperty(CAP_PROP.CV_CAP_PROP_FRAME_WIDTH);
double fourcc = camera.GetCaptureProperty(CAP_PROP.CV_CAP_PROP_FOURCC);
CvInvoke.cvNamedWindow("camera");
Image<Bgr, byte> temp = camera.QueryFrame();
//路径
SaveFileDialog SaveFileDialog1 = new SaveFileDialog();
SaveFileDialog1.FileName = DateTime.Now.ToString("yyyyMMddhhmmss");
SaveFileDialog1.Filter = "Image Files(*.avi)|*.avi|All files (*.*)|*.*";
if (SaveFileDialog1.ShowDialog() == DialogResult.OK)
{
MessageBox.Show("START RECORD,ESC TO STOP");
}
VideoWriter video = new VideoWriter(SaveFileDialog1.FileName, (int)fourcc, 15, 800, 600, true);
while (temp != null)
{
CvInvoke.cvShowImage("camera", temp.Ptr);
temp = camera.QueryFrame();
int c = CvInvoke.cvWaitKey(20);
Image<Bgr, byte> marked = faceDetection(temp);
video.WriteFrame<Bgr, byte>(marked);
if (c == 27) break;
}
video.Dispose();
camera.Dispose();
CvInvoke.cvDestroyWindow("camera");
}
有谁知道这可能是什么原因造成的?
谢谢
埃文