我在OpenCV中使用三个网络摄像头偶尔拍摄快照。它们连接到同一个USB总线上,由于USB带宽限制不允许同时连接所有3个(降低分辨率最多可以允许2个同时连接,而我没有更多的USB总线)。
因此,每次我想要拍摄快照时,我必须切换网络摄像头连接,但这会导致在大约40次切换后出现内存泄漏。
这是我收到的错误:
libv4l2: error allocating conversion buffer
mmap: Cannot allocate memory
munmap: Invalid argument
munmap: Invalid argument
munmap: Invalid argument
munmap: Invalid argument
Unable to stop the stream.: Bad file descriptor
munmap: Invalid argument
munmap: Invalid argument
munmap: Invalid argument
munmap: Invalid argument
libv4l1: error allocating v4l1 buffer: Cannot allocate memory
HIGHGUI ERROR: V4L: Mapping Memmory from video source error: Invalid argument
HIGHGUI ERROR: V4L: Initial Capture Error: Unable to load initial memory buffers.
OpenCV Error: Bad flag (parameter or structure field) (Unrecognized or
unsupported array type) in cvGetMat, file
/build/buildd/opencv-2.3.1/modules/core/src/array.cpp, line 2482
Traceback (most recent call last):
File "/home/irobot/project/test.py", line 7, in <module>
cv2.imshow('cam', img)
cv2.error: /build/buildd/opencv-2.3.1/modules/core/src/array.cpp:2482:
error: (-206) Unrecognized or unsupported array type in function cvGetMat
这是一个简单的代码片段,会生成以下错误:
import cv2
for i in range(0,100):
print i
cam = cv2.VideoCapture(0)
success, img = cam.read()
cv2.imshow('cam', img)
del(cam)
if cv2.waitKey(5) > -1:
break
cv2.destroyAllWindows()
或许值得一提的是,每次连接相机时我都会收到VIDIOC_QUERYMENU: Invalid argument
错误消息,但我仍然可以使用它。
额外提供一些信息,这是我使用v4l2-ctl -V
命令获取的网络摄像头输出:
~$ v4l2-ctl -V
Format Video Capture:
Width/Height : 640/480
Pixel Format : 'YUYV'
Field : None
Bytes per Line: 1280
Size Image : 614400
Colorspace : SRGB
这些错误是由什么引起的,我该如何修复它们?