简体   繁体   English

如何在Windows上将Logitech Webcam C922 Pro与python链接

[英]How to link the logitech Webcam C922 pro with python on Windows

I am attempting to link my Logitech C922 Pro webcam to Python and read from it using Windows, but I am getting an assertion error. 我试图将Logitech C922 Pro网络摄像头链接到Python并使用Windows从中读取,但是出现断言错误。 This is the code I am using: 这是我正在使用的代码:

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()

But the error I am getting is: 但是我得到的错误是:

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'

Your code is fine, there is just one line needs to be changed 您的代码很好,只需更改一行

Change this: 更改此:

cap = cv2.VideoCapture(1)

To this: 对此:

cap = cv2.VideoCapture(0)

This line will get your job done: 此行将完成您的工作:

cap = cv2.VideoCapture(0)

If you want to load a video from your directory then use: 如果要从目录加载视频,请使用:

cap = cv2.VideoCapture('image_path')

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何使用opencv和python编程缩放罗技网络摄像头c930e? - How to zoom the logitech webcam c930e using opencv with python programming? 使用 python 从罗技网络摄像头录制音频和视频的好方法 - good and simple way to record audio and video from logitech webcam with python 如何使用 opencv 和多线程(罗技 c920)在 python 中捕获视频 - How to capture video in python with opencv and multithread (logitech c920) 如果有人有使用 Nvidia Jetbot 的经验,你知道如何更改 gstreamer 管道以使用网络摄像头吗? 我正在使用 c170 罗技 - If anyone has experience with the Nvidia Jetbot, do you know how to change the gstreamer pipeline to work with a webcam? I'm using a c170 Logitech 如何使用 openCV 和 Logitech C920 使 python 每秒记录 30 或 60 帧 - How to make python record 30 or 60 frames per second using openCV and a Logitech C920 cv2.VideoWriter不会使用fourcc h.264(使用Logitech c920,python 2.7,Windows 8)写入文件 - cv2.VideoWriter will not write file using fourcc h.264 (with logitech c920, python 2.7, windows 8) 在 python 3 和 windows 中拍摄网络摄像头照片 - taking webcam photos in python 3 and windows 如何链接C lib与python在Windows下嵌入? - How to link C lib against python for embedding under Windows? 捕获和操作网络摄像头馈送并将其公开为“虚拟网络摄像头” - 在 Python 中,在 Windows 中 - Capturing and manipulating a webcam feed and exposing it as a “virtual webcam” - in Python, on Windows 在Windows上使用Python从网络摄像头捕获图像 - Capturing image from Webcam Using Python on Windows
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM