OpenCV on Mac is not opening USB web camera

Try to run your code without this line: break;. Probably you will find more than just one camera, and one of them will WebCam.
Note that parameter of cap.open is not only the number of camera – it also defines which API you want to use:

Camera dispatching method: index is the camera number.

  • If given an index from 0 to 99, it tries to find the first
  • API that can access a given camera index.
  • Add multiples of 100 to select an API (comment from cap.cpp)

Possibilities (taken from highgui_c.h):

CV_CAP_ANY      =0,     // autodetect  
CV_CAP_MIL      =100,   // MIL proprietary drivers  
CV_CAP_VFW      =200,   // platform native  
CV_CAP_V4L      =200,
CV_CAP_V4L2     =200,  
CV_CAP_FIREWARE =300,   // IEEE 1394 drivers  
CV_CAP_FIREWIRE =300,  
CV_CAP_IEEE1394 =300,  
CV_CAP_DC1394   =300,  
CV_CAP_CMU1394  =300,  
CV_CAP_STEREO   =400,   // TYZX proprietary drivers  
CV_CAP_TYZX     =400,  
CV_TYZX_LEFT    =400,  
CV_TYZX_RIGHT   =401,  
CV_TYZX_COLOR   =402,  
CV_TYZX_Z       =403,  
CV_CAP_QT       =500,   // QuickTime  
CV_CAP_UNICAP   =600,   // Unicap drivers  
CV_CAP_DSHOW    =700,   // DirectShow (via videoInput)  
CV_CAP_PVAPI    =800,   // PvAPI, Prosilica GigE SDK  
CV_CAP_OPENNI   =900,   // OpenNI (for Kinect)  
CV_CAP_OPENNI_ASUS =910,   // OpenNI (for Asus Xtion)  
CV_CAP_ANDROID  =1000,  // Android  
CV_CAP_XIAPI    =1100,   // XIMEA Camera API  
CV_CAP_AVFOUNDATION = 1200  // AVFoundation framework for iOS (OS X Lion will have the same API)

Probably CV_CAP_AVFOUNDATION = 1200 is what you are looking for – try to start you loop from 1200 and don’t forget to remove break; and I think that you will find what you are looking for.

Leave a Comment