无法通过索引OpenCV打开相机

问题描述 投票:0回答:1

我有一个 chromebook,我使用 VSCode 作为我的 IDE,使用 Python3 作为我的语言。运行此代码时出现错误:

[ERROR:[email protected]] global obsensor_uvc_stream_channel.cpp:156 getStreamChannelGroup 相机索引超出范围

import numpy as np
import cv2

cap = cv2.VideoCapture(0)

while True:
    ret, frame = cap.read()

    cv2.imshow('frame', frame)

    if cv2.waitKey(1) == ord('q'):
        break
cap.release()
cv2.destroyAllWindows

我已经将索引更改为不同的值,但没有任何效果。

python opencv
1个回答
0
投票

Camera index Out of range, it means your device camera is not detecting.

cap = cv2.VideoCapture(0)

-确保您的 Chromebook 已连接或内置摄像头,并且它运行正常。

-检查正在使用的相机索引是否正确。该索引应与您要访问的相机设备相对应。请记住,相机索引通常从 0 开始,因此第一个相机的索引为 0,第二个相机的索引为 1,依此类推。

© www.soinside.com 2019 - 2024. All rights reserved.