调试海康usb摄像头错误记录

调试海康usb摄像头错误记录
所用代码如下,代码很简单,打开摄像头,获取视频流,从视频流中截取一帧按键’s’保存.
取名:capture.py

import cv2 
import numpy as np 
import time
cap0 = cv2.VideoCapture(0)

cap1 = cv2.VideoCapture(1) 
i = 1
while(1): # get a frame 
	ret0, frame0 = cap0.read() # show a frame 
	ret1, frame1 = cap1.read() # show a frame 
	cv2.imshow("capture0", frame0) 
	cv2.imshow("capture1", frame1) 
	k = cv2.waitKey(100) & 0xFF
	if k == ord('q'):
		break 
	elif k == ord('s'):
		cv2.imwrite('left'+str('%02d'%i)+'.jpg',frame0)
		cv2.imwrite('right'+str('%02d'%i)+'.jpg',frame1)
		i=i+1
cap0.release() 
cap1.release() 
cv2.destroyAllWindows()

1.

libv4l2: error setting pixformat: Device or resource busy
libv4l2: error setting pixformat: Device or resource busy
libv4l2: error setting pixformat: Device or resource busy
libv4l2: error setting pixformat: Device or resource busy
libv4l2: error setting pixformat: Device or resource busy
libv4l2: error setting pixformat: Device or resource busy
libv4l2: error setting pixformat: Device or resource busy
libv4l2: error setting pixformat: Device or resource busy
libv4l2: error setting pixformat: Device or resource busy
libv4l2: error setting pixformat: Device or resource busy
libv4l2: error setting pixformat: Device or resource busy
VIDEOIO ERROR: V4L2: Pixel format of incoming image is unsupported by OpenCV

上次错误退出,强退的.
解决:插拔usb接口.

2.

VIDEOIO ERROR: V4L: index 0 is not correct!

下面这句话报的错,原因是在/dev下video0变成了video1或者其他,需要修改成cv2.VideoCapture(0)或者其他数字

cap0 = cv2.VideoCapture(0)

**解决:**将0调大,能找到.

3.
运行python capture.py  有时报如下错误:

aaaaaaaaaa
select timeout
select timeout
Segmentation fault (core dumped)

这种错误要等它运行完毕,不运行完毕强退的话,会导致1那种错误.
**解决:**待运行完毕,再次运行就好.

4.

VIDIOC_DQBUF: No such device

这种错误,是摄像头没链接好,可以用lsusb查看device信息,或者用ubuntu自带的cheese来看图像.
**解决:**插拔usb接口

插一句:若是在firefly这种嵌入式机子上调试双目,不能将两摄像头接在一个总线上.这是一个坑.

以前遇到上述错误总担心是opencv的问题,想错了.

你可能感兴趣的:(linux,python)