C# &引用;System.AccessViolationException未经处理;使用emgu CV写入视频时出错

C# &引用;System.AccessViolationException未经处理;使用emgu CV写入视频时出错,c#,visual-studio-2010,emgucv,C#,Visual Studio 2010,Emgucv,我试图在VisualStudio2010中使用EMGU CV捕捉视频,但当它执行该行时 video.WriteFrame<Bgr, byte>(marked); video.WriteFrame(已标记); 我得到以下错误: System.AccessViolationException未处理 试图读取或写入受保护的内存。这通常表示其他内存已损坏 private void button3_Click_1(object sender, EventArgs e) {

我试图在VisualStudio2010中使用EMGU CV捕捉视频,但当它执行该行时

video.WriteFrame<Bgr, byte>(marked);
video.WriteFrame(已标记);
我得到以下错误:

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");
    }
private void按钮3\u单击1(对象发送方,事件参数e)
{
捕获照相机=新捕获();
如果(摄像机==null)
{
MessageBox.Show(“找不到摄像头”,“错误”);
}
双fps=camera.GetCaptureProperty(CAP\u PROP.CV\u CAP\u PROP\u fps);
double cpHeight=camera.GetCaptureProperty(CAP\u PROP.CV\u CAP\u PROP\u FRAME\u HEIGHT);
double cpWidth=camera.GetCaptureProperty(CAP\u PROP.CV\u CAP\u PROP\u FRAME\u WIDTH);
double fourcc=camera.GetCaptureProperty(CAP\u PROP.CV\u CAP\u PROP\u fourcc);
CvInvoke.cvNamedWindow(“摄像机”);
Image temp=camera.QueryFrame();
//路径
SaveFileDialog SaveFileDialog1=新建SaveFileDialog();
SaveFileDialog1.FileName=DateTime.Now.ToString(“yyyyMMddhhmmss”);
SaveFileDialog1.Filter=“图像文件(*.avi)|*.avi |所有文件(*.*)|*.”;
if(SaveFileDialog1.ShowDialog()==DialogResult.OK)
{
MessageBox.Show(“开始记录,ESC停止”);
}
VideoWriter video=新的VideoWriter(SaveFileDialog1.FileName,(int)fourcc,15,800,600,true);
while(temp!=null)
{
cvShowImage(“摄像机”,温度Ptr);
temp=摄影机.QueryFrame();
int c=CvInvoke.cvWaitKey(20);
图像标记=面部检测(温度);
video.WriteFrame(已标记);
如果(c==27)断开;
}
video.Dispose();
摄像头。Dispose();
CvInvoke.cvDestroyWindow(“摄像头”);
}
有人知道这可能是什么原因吗

谢谢


Evan

在重新排列了以下几行之后,它对我非常有效。此外,检查是否标记为不为空。如果标记为null,则会引发访问冲突错误

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();
}
while(温度!=null)
{
cvShowImage(“摄像机”,温度Ptr);
图像标记=面部检测(温度);
video.WriteFrame(已标记);
int c=CvInvoke.cvWaitKey(20);
如果(c==27)断开;
temp=摄影机.QueryFrame();
}

在对以下行重新排序后,它对我非常有效。此外,检查是否标记为不为空。如果标记为null,则会引发访问冲突错误

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();
}
while(温度!=null)
{
cvShowImage(“摄像机”,温度Ptr);
图像标记=面部检测(温度);
video.WriteFrame(已标记);
int c=CvInvoke.cvWaitKey(20);
如果(c==27)断开;
temp=摄影机.QueryFrame();
}

很抱歉回答得太晚,但也许有人会觉得这很有帮助

我现在自己也在处理这个错误(在不同的情况下),这似乎是一个在64位Windows上尝试在我的项目中包含32位组件的问题

在32位系统上,它运行良好,在64位系统上,我有“system.AccessViolationException未处理”

可悲的是,在我的情况下,并没有什么可以做的,只是放弃了组件,用其他方式来做


也许这也是个问题。什么是VideoWriter,看起来不像是标准的.NET课程?

很抱歉回答晚了,但也许有人会觉得它很有用

我现在自己也在处理这个错误(在不同的情况下),这似乎是一个在64位Windows上尝试在我的项目中包含32位组件的问题

在32位系统上,它运行良好,在64位系统上,我有“system.AccessViolationException未处理”

可悲的是,在我的情况下,并没有什么可以做的,只是放弃了组件,用其他方式来做

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