I had this same problem, and same error log in dmesg. I think what's required is to set the capture size (i.e. CV_CAP_PROP_FRAME_WIDTH and CV_CAP_PROP_FRAME_WIDTH) to an appropriate value for your camera.
After some experimentation, this worked for me on the BeagleBone Black with a Logitech HD Webcam C525:
#! /usr/bin/env python
import cv2
import sys
vc = cv2.VideoCapture(0)
vc.set(cv2.cv.CV_CAP_PROP_FRAME_WIDTH,1280)
vc.set(cv2.cv.CV_CAP_PROP_FRAME_HEIGHT,720)
if not vc.isOpened():
sys.stderr.write('could not connect to camera! \n')
sys.exit(1)
for count in range(0,5):
success,frame = vc.read()
if not success:
sys.stderr.write('could not read image from cam \n')
sys.exit(1)
cv2.imwrite('capture_%02d.png' % count,frame)
vc.release()
vc = None
I'm not sure if it's required, but I also preconfigured the camera with:
root@beaglebone:~# v4l2-ctl --set-fmt-video=width=1280,height=720,pixelformat=1