简体   繁体   English

Emgu CV无法播放视频

[英]Emgu CV can't play video

I can't play play video with Emgu CV 我无法使用Emgu CV播放视频

It's show error 显示错误

Unable to create capture from 184.avi 无法从184.avi创建捕获

Here is the code: 这是代码:

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

I use windows 8 x64 and install emgucv-windows-universal-cuda 2.4.10.1940 It have no opencv_ffmpeg.dll in bin. 我使用Windows 8 x64并安装emgucv-windows-universal-cuda 2.4.10.1940它在bin中没有opencv_ffmpeg.dll So I install opencv-2.4.11 and copy all dll from OpenCV bin to paste in Debug in my project. 因此,我安装了opencv-2.4.11并从OpenCV bin复制所有dll,以粘贴到我的项目中的Debug中。 I paste 184.avi to Debug too. 我也将184.avi粘贴到Debug。 But when I run it show error like this. 但是当我运行它时会显示这样的错误。 How to play video with Emgu CV? 如何使用Emgu CV播放视频?

Your code works fine. 您的代码工作正常。 I think the problem is that you have not imported the video file to Visual Studio. 我认为问题在于您尚未将视频文件导入Visual Studio。 So try importing the video file to visual studio and also set the properties to copy always. 因此,请尝试将视频文件导入Visual Studio,并将属性设置为始终复制。 You can see below that i have imported the A.avi file and set it's properties to copy always. 您可以在下面看到我已导入A.avi文件并将其属性设置为始终复制。

在此处输入图片说明

And think you can just use imageBox.Image = _capture.QueryFrame(); 并认为您可以只使用imageBox.Image = _capture.QueryFrame(); instead of imageBox.Image = _capture.QueryFrame().ToBitmap(); 而不是imageBox.Image = _capture.QueryFrame().ToBitmap(); because you don't need to convert to bitmap with ImageBox. 因为您不需要使用ImageBox转换为位图。

The code i used is same as yours. 我使用的代码与您的相同。

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

You can just provide full path instead of just the file name. 您可以提供完整路径,而不仅仅是文件名。

You do not have the video file in the same folder as your program exe. 您没有将视频文件与程序exe放在同一文件夹中。 If you place video file just next to your program exe, it should also work. 如果将视频文件放置在程序exe的旁边,则它也应该起作用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM