Ask Your Question
0

OpenCV play video not working on MacOsx 2.4.13.2

asked 2017-06-22 11:51:00 -0500

sabzo gravatar image

updated 2017-06-22 12:02:33 -0500

berak gravatar image

I'm reproducing example 2-3 from the OpenCV Oreilly book https://books.google.com/books?id=LPm...

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

    using namespace std;

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

      cv::namedWindow("win", cv::WINDOW_AUTOSIZE);

      cv::VideoCapture cap;

      if (argc==1) {
        cap.open(0);
      } else if(argc == 2) {
        cout << "Playing " << argv[1] << endl;
        cap.open(argv[1]);
      }

      if (!cap.isOpened()) {
        std::cerr << "Coudln't open camera capture." << std::endl;
        return -1;
      }

      cv::Mat frame;
      while(1) {
        cap >> frame;
        if (frame.empty()) break;
        cv::imshow("win", frame);
        if (cv::waitKey(33) >= 0) break;
      }
      return 0;
    }

The error I'm getting is cryptic:

*** Terminating app due to uncaught exception 'NSRangeException', reason: '*** -[__NSArrayM objectAtIndex:]: index 0 beyond bounds for empty array'
*** First throw call stack:
(
        0   CoreFoundation                      0x00007fffab35557b __exceptionPreprocess + 171
        1   libobjc.A.dylib                     0x00007fffc07191da objc_exception_throw + 48
        2   CoreFoundation                      0x00007fffab2720ab -[__NSArrayM objectAtIndex:] + 203
        3   libopencv_highgui.2.4.dylib         0x0000000102305709 _ZN13CvCaptureFileC2EPKc + 281
        4   libopencv_highgui.2.4.dylib         0x000000010230423e _Z32cvCreateFileCapture_AVFoundationPKc + 34
        5   libopencv_highgui.2.4.dylib         0x00000001022f8afc cvCreateFileCapture + 14
        6   libopencv_highgui.2.4.dylib         0x00000001022f8d9e _ZN2cv12VideoCapture4openERKNSt3__112basic_stringIcNS1_11char_traitsIcEENS1_9allocatorIcEEEE + 64
        7   play                                0x0000000101e1a725 main + 661
        8   libdyld.dylib                       0x00007fffc0ffa235 start + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException

Is this a bug on the library or a MacOsx issue? I set up OpenCV using brew install.

edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted
0

answered 2017-06-25 15:08:02 -0500

sabzo gravatar image

This was a bug in the Code. I worked with a OpenCV contributor in testing a patch, I submitted a PR and the latest 2.4 branch now addresses this issue.

edit flag offensive delete link more
Login/Signup to Answer

Question Tools

1 follower

Stats

Asked: 2017-06-22 11:51:00 -0500

Seen: 227 times

Last updated: Jun 25 '17