使用emgu opencv流式传输视频时出现访问冲突

时间:2013-06-11 07:45:31

标签: opencv emgucv

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Emgu.CV;
using Emgu.CV.Structure;

namespace CrackleTest
{
    public static class Controller
    {
        public static Capture capture = new Capture();
        public static VideoWriter CaptureOutput;

        public static void Init()
        {
            capture.SetCaptureProperty(Emgu.CV.CvEnum.CAP_PROP.CV_CAP_PROP_FRAME_WIDTH, 1920);
            capture.SetCaptureProperty(Emgu.CV.CvEnum.CAP_PROP.CV_CAP_PROP_FRAME_HEIGHT, 1080);

            CaptureOutput = new VideoWriter
            (
                "output.avi",
                -1, //CvInvoke.CV_FOURCC("W","M","V","1"),
                30, //fps
                (int)capture.GetCaptureProperty(Emgu.CV.CvEnum.CAP_PROP.CV_CAP_PROP_FRAME_WIDTH),
                (int)capture.GetCaptureProperty(Emgu.CV.CvEnum.CAP_PROP.CV_CAP_PROP_FRAME_HEIGHT),
                true
            );
            capture.ImageGrabbed += SaveFrame;

            capture.Start();
        }

        public static void Stop()
        {
            capture.Stop();
            CaptureOutput.Dispose();
        }

        public static void SaveFrame(Object sender, EventArgs e)
        {
            Image<Bgr, Byte> video = capture.RetrieveBgrFrame();
            CaptureOutput.WriteFrame(video);
        }
    }
}

当我调用stop函数时,我收到一条错误消息

  

“System.AccessViolationException”类型的未处理异常   发生在Emgu.CV.dll

     

附加信息:尝试读取或写入受保护的内存。   这通常表明其他内存已损坏。

我不确定在opencv中从usb网络摄像头流式传输视频的最佳做法。

0 个答案:

没有答案