我有一台非常便宜的中国立体声相机CHUSEI 3D。我想将其与ROS一起使用,以获取我当前正在执行的机械臂教程的立体图像。
不幸的是,网络摄像头没有真正的文档。在默认模式下,如果它连接到我的Ubuntu计算机,并且我打开Cheese Webcam Booth,则它仅显示一台摄像机的图像。在互联网上,我找到了一种适用于MacO的pyusb解决方案。我已经在Ubuntu 16.04上尝试过,但是它给我一个错误16:资源繁忙。
我已经在代码中添加了dev.detach_kernel_driver(0)
行,并且ctrl_transfer
起作用了……但是这种方式之后我无法访问网络摄像头。
因此,我的问题是,使用Python和Ubuntu 16.04,有没有一种方法可以将这些命令发送到网络摄像头而无需分离内核驱动程序,因此我仍然可以访问网络摄像头?
import cv2
import usb.core
import usb.util
import usb.backend.libusb1
cam=cv2.VideoCapture(0)
backend = usb.backend.libusb1.get_backend(find_library=lambda x: "/usr/lib/libusb-1.0.so")
dev = usb.core.find(idVendor=0x18e3, idProduct=0x5031,backend=backend)
dev.detach_kernel_driver(0)
# simulate the SET_CUR sequence
dev.ctrl_transfer(0x21,0x01,0x0800,0x0600,[0x50,0xff])
dev.ctrl_transfer(0x21,0x01,0x0f00,0x0600,[0x00,0xf6])
dev.ctrl_transfer(0x21,0x01,0x0800,0x0600,[0x25,0x00])
dev.ctrl_transfer(0x21,0x01,0x0800,0x0600,[0x5f,0xfe])
dev.ctrl_transfer(0x21,0x01,0x0f00,0x0600,[0x00,0x03])
dev.ctrl_transfer(0x21,0x01,0x0f00,0x0600,[0x00,0x02])
dev.ctrl_transfer(0x21,0x01,0x0f00,0x0600,[0x00,0x12])
dev.ctrl_transfer(0x21,0x01,0x0f00,0x0600,[0x00,0x04])
dev.ctrl_transfer(0x21,0x01,0x0800,0x0600,[0x76,0xc3])
k=0
print('ok')
while (k!=ord('q')):
ret,frame=cam.read()
frame = cv2.resize(frame,(640,480),interpolation=cv2.INTER_CUBIC)
cv2.imshow("cam_test",frame)
k=cv2.waitKey(18)&0xFF
kv=k-ord('0')
# print(kv)
# if press 1,2,3 or 4, change the 3d camera mode
if kv in [1,2,3,4]:
dev.ctrl_transfer(0x21,0x01,0x0a00,0x0600,[kv,0x00])
错误消息
Traceback (most recent call last):
File "test.py", line 13, in <module>
dev.ctrl_transfer(0x21,0x01,0x0800,0x0600,[0x50,0xff])
File "/home/ubuntu/.local/lib/python2.7/site-packages/usb/core.py", line 1034, in ctrl_transfer
self._ctx.managed_claim_interface(self, interface_number)
File "/home/ubuntu/.local/lib/python2.7/site-packages/usb/core.py", line 102, in wrapper
return f(self, *args, **kwargs)
File "/home/ubuntu/.local/lib/python2.7/site-packages/usb/core.py", line 167, in managed_claim_interface
self.backend.claim_interface(self.handle, i)
File "/home/ubuntu/.local/lib/python2.7/site-packages/usb/backend/libusb1.py", line 811, in claim_interface
_check(self.lib.libusb_claim_interface(dev_handle.handle, intf))
File "/home/ubuntu/.local/lib/python2.7/site-packages/usb/backend/libusb1.py", line 595, in _check
raise USBError(_strerror(ret), ret, _libusb_errno[ret])
usb.core.USBError: [Errno 16] Resource busy