多个usb相机使用心得

显示多个video*

一个摄像头插入后会出现两个video且都有同样设备名,比如video0,video1。只有video0有数据。另一个video1用opencv是读不到数据的。(而且往往是编号较小的那个video*是可以读的)

绑定多个相机端口号

参考博客ubuntu18.04固定摄像头标志为video0

多个相机插入不同USB口

两个usb相机同时打开可能会出现问题。通过一个usb口进入主板的两个相机会出现第一个相机占用端口的问题,导致第二个相机无法打开。必须要插两个独立的usb口。

设置曝光值

OpenCV 3.4.10不支持更改exposure曝光参数,偶然间我使用自己台式机上opencv-python 4.2.0的cv2支持更改参数。知道是OpenCV版本问题,4.2.0修复了bug。
如果需要ros话题,可以直接用OpenCV 4.2.0cv2转发成rostopic

附相机读取代码

#!/usr/bin/env python
# coding: utf-8
import cv2
print(cv2.__version__)
cap_ir_mono = cv2.VideoCapture('/dev/video_ir_mono')
# cap_color_mono = cv2.VideoCapture('/dev/video0')
# cap_color_mono = cv2.VideoCapture(0)

## 设置曝光参数
cap_ir_mono.set(cv2.CAP_PROP_AUTO_EXPOSURE, 1)  # manual mode
cap_ir_mono.set(cv2.CAP_PROP_EXPOSURE, 10) # value form 1 ~ 30 is ok

while cap_ir_mono.isOpened():
    ret_ir, frame_ir = cap_ir_mono.read()
    print('ir:', ret_ir)
    if ret_ir:
        print('ir:', len(frame_ir))
        cv2.imshow("cap_ir", frame_ir)
    cv2.waitKey(1)


'''
下面是多线程打开多个相机,经常找设备失败。不好用
'''

# import cv2
# import threading
# import time
#
# class camThread(threading.Thread):
#     def __init__(self, previewName, camID):
#         threading.Thread.__init__(self)
#         self.previewName = previewName
#         self.camID = camID
#     def run(self):
#         print("Starting " + self.previewName)
#         print("self.camID " + self.camID)
#         self.camPreview(self.camID)
#
#     def camPreview(self, type):
#         if type == 'color':
#             print('type color: ', type)
#             cam = cv2.VideoCapture(5)
#             while cam.isOpened():
#                 rval, frame = cam.read()
#                 print('rval: ', rval)
#                 if rval:
#                     cv2.imshow(self.previewName, frame)
#                     key = cv2.waitKey(1)
#                     if key == 27:  # exit on ESC
#                         break
#             cv2.destroyWindow(self.previewName)
#
#         elif type == 'ir':
#             print('type ir: ', type)
#             cam = cv2.VideoCapture(2)
#             while cam.isOpened():
#                 rval, frame = cam.read()
#                 print('rval: ', rval)
#                 if rval:
#                     cv2.imshow(self.previewName, frame)
#                     key = cv2.waitKey(1)
#                     if key == 27:  # exit on ESC
#                         break
#             cv2.destroyWindow(self.previewName)
#
# if __name__ == "__main__":
#     # Create threads as follows
#     thread1 = camThread("color_mono", 'color')
#     thread2 = camThread("ir_mono", 'ir')
#
#     thread1.start()
#     time.sleep(3)
#     thread2.start()
#     print("Active threads", threading.activeCount())
  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值