【问题标题】:Emgu CV can't play videoEmgu CV无法播放视频
【发布时间】:2015-05-17 12:20:06
【问题描述】:

我无法使用 Emgu CV 播放视频

显示错误

无法从 184.avi 创建捕获

代码如下:

public partial class Form1 : Form
{
    //Set the name of pop-up window
    String winname = "First Window";
    Timer My_Time = new Timer();
    int FPS=30;
    Capture _capture;

    public Form1()
    {
        InitializeComponent();

    //Frame Rate
    My_Timer.Interval = 1000 / FPS;
    My_Timer.Tick += new EventHandler(My_Timer_Tick);
    My_Timer.Start();

    _capture = new Capture("184.avi");   // Error this line

    }

    private void My_Timer_Tick(object sender, EventArgs e)
    {
        imageBox.Image = _capture.QueryFrame().ToBitmap();
    }

我使用 Windows 8 x64 并安装 emgucv-windows-universal-cuda 2.4.10.1940 它在 bin 中没有 opencv_ffmpeg.dll。所以我安装了 opencv-2.4.11 并从 OpenCV bin 中复制所有 dll 以粘贴到我的项目中的 Debug 中。我也将 184.avi 粘贴到 Debug 中。但是当我运行它时会显示这样的错误。如何使用 Emgu CV 播放视频?

【问题讨论】:

标签: c# opencv video emgucv


【解决方案1】:

您的代码运行良好。我认为问题在于您尚未将视频文件导入 Visual Studio。因此,尝试将视频文件导入 Visual Studio,并将属性设置为始终复制。您可以在下面看到我已导入 A.avi 文件并将其属性设置为始终复制。

并且认为您可以只使用imageBox.Image = _capture.QueryFrame(); 而不是imageBox.Image = _capture.QueryFrame().ToBitmap();,因为您不需要使用ImageBox 转换为位图。

我使用的代码与您的相同。

using System;
using System.Diagnostics;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

using Emgu.CV;
using Emgu.CV.CvEnum;
using Emgu.CV.Structure;
using Emgu.CV.UI;
using Emgu.CV.Features2D;
using Emgu.CV.Util;

namespace WindowsFormsApplication2
{
    public partial class Form1 : Form
    {//Set the name of pop-up window
        String winname = "First Window";
        Timer My_Time = new Timer();
        int FPS = 30;
        Capture _capture;

        public Form1()
        {
            InitializeComponent();

            //Frame Rate
            My_Time.Interval = 1000 / FPS;
            My_Time.Tick += new EventHandler(My_Timer_Tick);
            My_Time.Start();

            _capture = new Capture("A.avi");   // Error this line

        }

        private void My_Timer_Tick(object sender, EventArgs e)
        {
            imageBox.Image = _capture.QueryFrame();
        }
    }
}

【讨论】:

  • 我尝试了所有方法,但仍然有错误 NullReferenceException is unhandled Unable to create capture from 184.avi 我不知道如何解决这个问题。
  • 对我来说,它首先给出了同样的错误,并且在将视频文件导入到 Visual Studio 后修复了它。尝试使用 Visual Studio 检查 Emgu Cv 配置。 notebookbft.wordpress.com/2015/03/08/…
【解决方案2】:

您可以只提供完整路径而不仅仅是文件名。

您的视频文件与您的程序 exe 不在同一文件夹中。 如果您将视频文件放在程序 exe 旁边,它也应该可以工作。

【讨论】:

    猜你喜欢
    • 2018-08-28
    • 1970-01-01
    • 2015-09-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-05-30
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多