35280

opencv does not display a video in mac osx

Question:

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

<img alt="enter image description here" class="b-lazy" data-src="https://i.stack.imgur.com/2QeK7.png" data-original="https://i.stack.imgur.com/2QeK7.png" src="https://etrip.eimg.top/images/2019/05/07/timg.gif" />

Answer1:

After:

imshow("video", frame);

call:

waitKey(10);

It's mandatory to call <a href="https://stackoverflow.com/a/5493668/176769" rel="nofollow">cv::waitKey()</a> 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);

Answer2:

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.

Recommend

  • javascript Confirm replacement with return true/false
  • Different builds of turn-based Game Center game can’t see each other’s matches
  • Xcode duplicated devices bug
  • How do I fix “The program issued a command but the command length is incorrect.” error when calling
  • QTP UFT Unable to find row count from table
  • C++ String tokenisation from 3D .obj files
  • Tools for understanding HTML layout
  • Thread 1: EXC_BAD_ACCESS (code =1 address = 0x0)
  • JPA flush vs commit
  • npm 5.4.1 install/uninstall all failing
  • Memory error in python- how to use more memory
  • Differences in dis-assembled C code of GCC and Borland?
  • wxPython: displaying multiple widgets in same frame
  • How to determine if there are bytes available to be read from boost:asio:serial_port
  • Google Custom Search with transparent background
  • C++ Partial template specialization - design simplification
  • Algorithm for a smudge tool?
  • R - Combining Columns to String Based on Logical Match
  • Is there a javascript serializer for JSON.Net?
  • Where to put my custom functions in Wordpress?
  • Why is the timeout on a windows udp receive socket always 500ms longer than set by SO_RCVTIMEO?
  • AT Commands to Send SMS not working in Windows 8.1
  • Windows forms listbox.selecteditem displaying “System.Data.DataRowView” instead of actual value
  • Buffer size for converting unsigned long to string
  • Acquiring multiple attributes from .xml file in c#
  • Hits per day in Google Big Query
  • How to CLICK on IE download dialog box i.e.(Open, Save, Save As…)
  • embed rChart in Markdown
  • How to get Windows thread pool to call class member function?
  • IndexOutOfRangeException on multidimensional array despite using GetLength check
  • apache spark aggregate function using min value
  • How can I remove ASP.NET Designer.cs files?
  • Checking variable from a different class in C#
  • Sorting a 2D array using the second column C++
  • costura.fody for a dll that references another dll
  • Binding checkboxes to object values in AngularJs
  • Observable and ngFor in Angular 2
  • UserPrincipal.Current returns apppool on IIS
  • Unable to use reactive element in my shiny app
  • java string with new operator and a literal