如何将Logitech Webcam C922 pro与Windows上的python链接

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

我正在尝试将Logitech C922 Pro网络摄像头链接到Python并使用Windows进行读取,但是出现断言错误。这是我正在使用的代码:

import cv2
import time
cap = cv2.VideoCapture(1)
cap.set(5, 60)

framecount = 0
prevMillis = 0

print(cap.get(5))

def fpsCount():
    global prevMillis
    global framecount
    millis = int(round(time.time() * 1000))
    framecount += 1
    if millis - prevMillis > 1000:
        print(framecount)
        prevMillis = millis 
        framecount = 0

while True:
    __, frame = cap.read()
    #frame = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
    #blur = cv2.blur(frame, (5, 5))
    #ret, thresh = cv2.threshold(blur, 170, 255, 0)
    cv2.imshow("Image", frame)


    fpsCount()    
    k = cv2.waitKey(1) & 0xff
    if k == 27:
        break

cap.release()
cv2.destroyAllWindows()

但是我得到的错误是:

cv2.imshow("Image", frame)
cv2.error: OpenCV(4.1.2) C:\projects\opencv-python\opencv\modules\highgui\src\window.cpp:376: error: (-215:Assertion failed) size.width>0 && size.height>0 in function 'cv::imshow'
python python-3.x opencv webcam
1个回答
0
投票

您的代码很好,只需更改一行]

更改此:

cap = cv2.VideoCapture(1)

为此:

cap = cv2.VideoCapture(0)
© www.soinside.com 2019 - 2024. All rights reserved.