2

我正在尝试在 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");
    }

有谁知道这可能是什么原因造成的?

谢谢

埃文

4

2 回答 2

0

很抱歉回答迟了,但也许有人会觉得它有帮助。

我自己现在(在不同的情况下)正在与这个错误作斗争,看起来尝试在 64 位 Windows 上的项目中包含 32 位组件是一个问题。

在 32 位系统上它运行完美,在 64 位上我有“System.AccessViolationException 未处理”

可悲的是,在我的情况下无能为力,只是放弃组件并以其他方式做

也许这里也有问题。什么是 VideoWriter,看起来不像标准的 .NET 类?

于 2013-10-25T14:33:17.180 回答
0

重新排序以下几行后,它对我来说非常有用。还检查标记为不为空。如果标记为空,那么它将引发访问冲突错误。

while (temp != null)
{
    CvInvoke.cvShowImage("camera", temp.Ptr);

    Image<Bgr, byte> marked = faceDetection(temp);
    video.WriteFrame<Bgr, byte>(marked);

    int c = CvInvoke.cvWaitKey(20);
    if (c == 27) break;

    temp = camera.QueryFrame();
}
于 2012-07-01T06:06:23.597 回答