OpenCV-播放AVI文件 [英] OpenCV - Play AVI File

查看:490
本文介绍了OpenCV-播放AVI文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图在ubuntu中使用opencv c ++在avi文件中播放,但没有任何输出.我正在使用的代码是我在网上找到的用于播放avi视频的标准代码,但是我看不到任何输出.是的,视频与我的src代码文件夹位于同一目录中.我唯一看到的是,在while循环的第一次迭代中,帧为空,因此中断了.但是我不知道视频正在vlc上播放的原因.在此我将不胜感激,因为在过去的4-5个小时中我一直坚持不懈. #include"cv.h"//将其包含到使用的OpenCV主函数中. #include"highgui.h"//包括它以使用GUI功能.

I am trying to play in avi file using opencv c++ in ubuntu but i am getting no output. The code im using is a standard code that i found online that is used to play an avi video but im seeing no output. And yes the video is in the same directory as my src code folder. The only thing im seeing is that on the first iteration of the while loop, frame is empty and hence breaks. but i do not know why it is happening as the video is working on vlc. I would really appreciate some help here as i have been stuck on it for the past 4-5 hours. #include "cv.h" // include it to used Main OpenCV functions. #include "highgui.h" //include it to use GUI functions.

int main(int argc, char** argv)
{
cvNamedWindow("Example3", CV_WINDOW_AUTOSIZE);

//CvCapture* capture = cvCreateFileCapture("20051210-w50s.flv");
CvCapture* capture = cvCreateFileCapture("tree.avi");
/* if(!capture)
    {
        std::cout <<"Video Not Opened\n";
        return -1;
    }*/
IplImage* frame = NULL;

while(1) {

    frame = cvQueryFrame(capture);
    //std::cout << "Inside loop\n";
    if (!frame)
        break;
    cvShowImage("Example3", frame);
    char c = cvWaitKey(33);
    if (c == 27) break;
}
cvReleaseCapture(&capture);
cvDestroyWindow("Example3");
std::cout << "Hello!";
return 0;
}

推荐答案

删除代码行:

char c = cvWaitKey(33);
if (c == 27) break;

而不是这些,只需添加:

and instead of these, just add :

cvWaitKey(33);

这可能会有所帮助.这是适合我的python代码:

May be this could help.Here is the python code, that worked fine for me:

import cv
if __name__ == '__main__':
  capture = cv.CreateFileCapture('Wildlife.avi')
  loop = True
  while(loop):
    frame = cv.QueryFrame(capture)
    if (frame == None):
            break;
    cv.ShowImage('Wild Life', frame)
    char = cv.WaitKey(33)
    if (char != -1):
        if (ord(char) == 27):
            loop = False

或者可能会有所帮助.

这篇关于OpenCV-播放AVI文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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