To Use Camera

In OpenCV for python (not seen in cpp), it seems that cap = cv2.VideoCapture(0); is non-blocking, and cap.isOpened() would be automatically true, no matter it’s opened or not.

In order to wait camera to setup properly, use the code below.

cv2.namedWindow('preview'); # This is necessary.. the waitKey won't work without it 
cap = cv2.VideoCapture(0);

while True:
  rval, _ =
  if rval:


On Ubuntu, to compile with python support:

The source can be gained from, and there are currently 2 branchs: the 3.0-dev version (master branch), and the 2.4 version.

Build the one you need, by checkout the corresponding branch