OpenCv:u!= 0从视频文件读取帧时发生异常 [英] OpenCv:u!=0 Exception while reading frames from video file

查看:486
本文介绍了OpenCv:u!= 0从视频文件读取帧时发生异常的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试从视频文件中获取帧,但是在读取帧时,会引发OpenCv:u!= 0异常。我正在使用Emgu.Cv dll。
我写的代码如下:

I'm trying to get frames from a video file but while reading frames, OpenCv:u!=0 exception is being thrown. I'm using Emgu.Cv dll. I have written the code as follows:

private void GetVideoFrames(String Filename)
{
    try
    {
        captureFrame = new Capture(Filename);
        bool Reading = true;
        while (Reading)
        {
            using (frame = captureFrame.QueryFrame().ToImage<Bgr, Byte>())
            {
                if 
                if (frame != null)
                {
                    imageBox1.Image = frame;
                    frameCount++;
                }
                else
                {
                    Reading = false;
                }
            }
        }
    }

可以任何人都请提供一些帮助。

Could anyone please provide some help.

推荐答案

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

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

这篇关于OpenCv:u!= 0从视频文件读取帧时发生异常的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆