python安装OpenCV

安装OpenCV

pip install opencv-python

python OpenCV 打开摄像头

import cv2

WIDTH  = 1080
HEIGHT = 720

cap = cv2.VideoCapture(0, cv2.CAP_DSHOW)
cap.set(cv2.CAP_PROP_FRAME_WIDTH, WIDTH)
cap.set(cv2.CAP_PROP_FRAME_HEIGHT, HEIGHT)

while True:
    ok,frame = cap.read()
    # print("ok", ok)
    # print("frame", frame)
    cv2.imshow("camera video", frame)

    if (cv2.waitKey(1) & 0xFF) == ord('q'):
        break

cap.release()
cv2.destroyAllWindows()

参考

  • python实现opencv调用摄像头
  • Python3使用opencv调用摄像头录制高清视频
  • 关于OpenCV的坑
  • python+opencv+FFmpeg rtmp推
  • 如何使用OpenCV RTMP直播推流
  • 基于OpenCV与UDP实现的视频流传输

你可能感兴趣的:(python,OpenCV,python,opencv)