gpt4 book ai didi

c# - 使用emgu CV写视频报错"System.AccessViolationException was unhandled"

转载 作者:太空宇宙 更新时间:2023-11-03 16:30:36 25 4
gpt4 key购买 nike

我正在尝试在 visual studio 2010 中使用 EMGU CV 捕获视频,但是当它执行该行时

video.WriteFrame<Bgr, byte>(marked);

我得到以下错误:

System.AccessViolationException 未处理

试图读取或写入 protected 内存。这通常表明其他内存已损坏。

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");
}

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

谢谢

埃文

最佳答案

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

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();
}

关于c# - 使用emgu CV写视频报错"System.AccessViolationException was unhandled",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10907853/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com