Emgu Capture以超快的速度播放视频

时间:2011-10-05 21:58:51

标签: emgucv

当我使用Emgu播放视频时,它的播放速度比应该的速度快。这是相关的代码。

public Form1()
{
    InitializeComponent();

    _capture = new Capture("test.avi");
    Application.Idle += RefreshFrames;
}

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

我尝试使用Capture对象上的SetCaptureProperty方法设置FPS,但它仍然以超快速运动方式播放。

2 个答案:

答案 0 :(得分:11)

当您的程序没有调用其他函数并且您的计算机具有可用资源时,将调用Application.Idle句柄。它不是设计为在设定的时间段调用。而是设置一个计时器并使用它的滴答功能来设置播放速度。

Timer My_Time = new Timer();
int FPS = 30;

public Form1()
{
    InitializeComponent();

    //Frame Rate
    My_Timer.Interval = 1000 / FPS;
    My_Timer.Tick += new EventHandler(My_Timer_Tick);
    My_Timer.Start();
    _capture = new Capture("test.avi");   
}

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

以上代码应该按照您的意愿进行,调整FPS以获得所需的播放速度。如果您需要任何其他信息,请告诉我,

干杯

克里斯

答案 1 :(得分:0)

public Form1()
{
    InitializeComponent();

    _capture = new Capture("test.avi");
    Application.Idle += RefreshFrames;
}

protected void RefreshFrames(object sender, EventArgs e)
{
    imageBox.Image = _capture.QueryFrame();

    Thread.sleep(1000/FrameRate);
}

使用thread.sleep将播放速度设置为实时。你可以轻松实现这一目标 使用这个:)