Alex Attinger Alex Attinger - 1 month ago 19
Python Question

OpenCV wont' capture from MacBook Pro iSight

Since a couple of days I can't open my iSight camera from inside a opencv application any more. cap = cv2.VideoCapture(0) returns, and cap.isOpened() returns true. However, cap.grab() just returns false. Any ideas?

Example Code:

import cv2

cv2.namedWindow("preview")
vc = cv2.VideoCapture(0)
rval = True


while rval:
rval, frame = vc.read()
cv2.imshow("preview", frame)

key = cv2.waitKey(20)
if key == 27: # exit on ESC
break



  • Mac OS 10.8.5

  • Python 2.7.5 (but also not working from inside a C++ app)

  • OpenCV 2.4.6.1.

  • Answer

    I am having the exact same problem using the same code however I'm on OSX 10.6. Any help would be greatly appreciated.

    Edit:

    This is how I got the camera working for your code:

    import cv2
    
    cv2.namedWindow("preview")
    vc = cv2.VideoCapture(0)
    
    rval, frame = vc.read()
    
    while True:
    
      if frame is not None:   
         cv2.imshow("preview", frame)
      rval, frame = vc.read()
    
      if cv2.waitKey(1) & 0xFF == ord('q'):
         break