且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

OpenCv:u!= 0从视频文件读取帧时发生异常

更新时间:2022-04-06 22:36:36

根据我的看法,您应该制作从相机抓取的帧的副本。您可以使用以下代码。

according to me, you should make a copy of frame grabbed from camera. You could you the following code. It is tested and error free.

    Capture captureFrame = new Capture(Filename);
    Mat frame = new Mat();
    Mat frame_copy = new Mat();

    //Capture Image from file
    private void GetVideoFrames(String Filename)
    {
        try
        {
            captureFrame = new Capture(Filename);
            captureFrame.ImageGrabbed += ShowFrame;
            captureFrame.Start();
        }
        catch (Exception ex)
        {
            MessageBox.Show(ex.ToString());
        }
    }

    //Show in ImageBox
    private void ShowFrame(object sender, EventArgs e)
    {
        captureFrame.Retrieve(frame);
        frame_copy = frame;
        imageBox1.Image = frame_copy ;
    }