1. 安装Python, 略。
2. 安装 OpenCV: 文章来源:https://www.toymoban.com/news/detail-635643.html
pip install opencv-python
3. 预览摄像头画面脚本:文章来源地址https://www.toymoban.com/news/detail-635643.html
import cv2
cap = cv2.VideoCapture(0, cv2.CAP_DSHOW)
if not (cap.isOpened()):
print("Could not open video device")
cap.set(cv2.CAP_PROP_FRAME_WIDTH, 640)
cap.set(cv2.CAP_PROP_FRAME_HEIGHT,480)
cap.set(cv2.CAP_PROP_FOURCC, cv2.VideoWriter.fourcc('Y', 'U', 'Y', 'V'))
while(True):
# Capture frame-by-frame
ret, frame = cap.read()
cv2.imshow('frame', frame)
#Waits for a user input to quit the application
if cv2.waitKey(1) & 0xFF == ord('q'):
break
cap.release()
cv2.destroyAllWindows()
到了这里,关于Python OpenCV读取并显示USB UVC摄像头的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!