无法按索引 Ubuntu 打开相机



在VirtualBox中的Ubuntu VM中运行以下代码时,我收到警告[ WARN:0@0.037] global /io/opencv/modules/videoio/src/cap_v4l.cpp (889) open VIDEOIO(V4L2:/dev/video0): can't open camera by index

import asyncio
import platform
import subprocess
import cv2
if platform.system() == 'Windows':
import winrt.windows.devices.enumeration as windows_devices
VIDEO_DEVICES = 4
class Camera:
def __init__(self):
self.cameras = []
def get_camera_indexes(self):
index = 0
camera_indexes = []
max_numbers_of_cameras_to_check = 10
while max_numbers_of_cameras_to_check > 0:
capture = cv2.VideoCapture(index)
if capture.read()[0]:
camera_indexes.append(index)
capture.release()
index += 1
max_numbers_of_cameras_to_check -= 1
return camera_indexes
camera = Camera()
print(camera.get_camera_indexes())

我已经尝试了这个问题中列出的所有内容:OpenCv错误可以';t通过视频拍摄打开相机,但我仍然没有幸运地摆脱警告。还有其他想法吗?谢谢

可能无法解决这个特定的问题,但值得一试。尝试使用imutils 打开墓地

from imutils import video  # pip install imutils
cam = video.VideoStream(src=port).start()
frame = cam.read()

相关内容

  • 没有找到相关文章

最新更新