opencv does not display a video in mac osx

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

brew install opencv

and the version is 2.4.3

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

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)

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

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

this is the opencv code

#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;
}

Answers


After:

imshow("video", frame);

call:

waitKey(10);

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.

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


Try compiling OpenCV with FFMPEG support enabled in order to have access to more codecs. If brew can't do it, install ffmpeg and cmake with brew, then grab the sources of OpenCV on github and recompile them.


Need Your Help

MVC disable unobtrusive validation for specific validator

asp.net-mvc jquery-validate unobtrusive-validation

I'm currently building a MVC4 project which uses unobtrusive validation through data annotations.

Assembler get value of pointer

assembly x86 att

At the moment I play a bit with assembler but I have one question to pointers. In my assembler program I have a String which I put in the registers EAX and I want to get the third character from the

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.