Opencv does not display video on mac osx

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

brew install opencv 

and version 2.4.3

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

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

The number of frames (if printed in opencv or displayed in VLC) is the same.

But if I run the opencv program, only the first frame will be shown. there is no other .. why ??

this is 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; } 

enter image description here

+1
source share
2 answers

After:

 imshow("video", frame); 

call:

 waitKey(10); 

Be sure to call cv::waitKey() to display the window. A parameter is the number of milliseconds that will remain open. This function returns the ASCII code of the key pressed during this time.

Ideally, you replace 10 with a number that forces it to display frames in the right FPS. In other words: cv::waitKey(1000 / fps);

+1
source

Try compiling OpenCV with FFMPEG support to access more codecs. If brew cannot do this, install ffmpeg and cmake with brew, then grab OpenCV sources on github and recompile them.

+1
source

Source: https://habr.com/ru/post/976531/


All Articles