栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

从接口名称而不是摄像机编号创建openCV VideoCapture

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

从接口名称而不是摄像机编号创建openCV VideoCapture

import re
import subprocess
import cv2
import os

device_re = re.compile("Buss+(?P<bus>d+)s+Devices+(?P<device>d+).+IDs(?P<id>w+:w+)s(?P<tag>.+)$", re.I)df = subprocess.check_output("lsusb", shell=True)for i in df.split('n'):    if i:        info = device_re.match(i)        if info: dinfo = info.groupdict() if "Logitech, Inc. Webcam C270" in dinfo['tag']:     print "Camera found."     bus = dinfo['bus']     device = dinfo['device']     breakdevice_index = Nonefor file in os.listdir("/sys/class/video4linux"):    real_file = os.path.realpath("/sys/class/video4linux/" + file)    print real_file    print "/" + str(bus[-1]) + "-" + str(device[-1]) + "/"    if "/" + str(bus[-1]) + "-" + str(device[-1]) + "/" in real_file:        device_index = real_file[-1]        print "Hurray, device index is " + str(device_index)camera = cv2.VideoCapture(int(device_index))while True:    (grabbed, frame) = camera.read() # Grab the first frame    cv2.imshow("Camera", frame)    key = cv2.waitKey(1) & 0xFF

首先在USB设备列表中搜索所需的字符串。获取总线和设备
号。

在video4linux目录下找到符号链接。从
realpath中提取设备索引,并将其传递给VideoCapture方法。



转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/659640.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号