[英]How to zoom the logitech webcam c930e using opencv with python programming?
[英]How to link the logitech Webcam C922 pro with python on Windows
我試圖將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'
您的代碼很好,只需更改一行
更改此:
cap = cv2.VideoCapture(1)
對此:
cap = cv2.VideoCapture(0)
此行將完成您的工作:
cap = cv2.VideoCapture(0)
如果要從目錄加載視頻,請使用:
cap = cv2.VideoCapture('image_path')
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.