opencv在Mac OSX中不显示视频 [英] opencv does not display a video in mac osx

查看:338
本文介绍了opencv在Mac OSX中不显示视频的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我刚刚在OSX 10.8.3的Mac上安装了opencv,并通过brew安装了它:

I just installed opencv on my mac with OSX 10.8.3, i installed it with brew:

brew install opencv

,版本为2.4.3

>>> ls /usr/local/Cellar/opencv
2.4.3

我尝试显示视频.格式为.asf,编解码器为MJPG(我只能在VLC中打开它,请参见屏幕截图)

I try to display a video. The format is .asf and the codec is MJPG (i can open it only with VLC, see the screenshot)

帧数(如果在opencv中打印或在VLC中可见)是相同的.

The number of frame (if printed out in opencv or seen in VLC) is the same.

但是,如果我运行opencv程序,则仅显示第一帧.另一个没有.为什么?

But if i run the opencv program only the first frame is showed. the other not.. why??

这是opencv代码

#include <iostream> 
#include <string> 
#include <sstream>

#include <opencv2/core/core.hpp> 
#include <opencv2/imgproc/imgproc.hpp> 
#include <opencv2/highgui/highgui.hpp> 

using namespace std;
using namespace cv;


int main(int argc, char *argv[]) {

    Mat frame;
    int numframe = 0;

    if (argc != 2) {
        cout << "Not enough parameters" << endl;
        return -1;
    }

    const string source = argv[1];
    VideoCapture capture(source);
    namedWindow("video", CV_WINDOW_AUTOSIZE);

    if (!capture.isOpened()) {
        cout  << "Could not open " << source << endl;
        return -1;
    }

    for(;;) {
        capture >> frame;
        numframe++;
        if (frame.empty()) {
            cout << "frame empty.." << endl;
            break;
        }
        cout << numframe << endl;
        imshow("video", frame);
    }

    return 0;
}

推荐答案

之后:

imshow("video", frame);

致电:

waitKey(10);

必须调用 cv::waitKey() 来显示窗口.该参数是窗口将保持打开状态的毫秒数.此函数返回在此期间按下的键的ASCII码.

It's mandatory to call cv::waitKey() to display the window. The parameter is the number of milliseconds that the window will remain opened. This function return the ASCII code of the key pressed during that time.

理想情况下,您可以将10替换为可以在正确的FPS上显示帧的数字.换句话说:cv::waitKey(1000 / fps);

Ideally, you would replace 10 by the number that makes it display the frames at the right FPS. In other words: cv::waitKey(1000 / fps);

这篇关于opencv在Mac OSX中不显示视频的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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