我使用 3 个网络摄像头偶尔在 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
是什么导致了这些错误,我该如何解决?