xiaopch

python使用opencv模块操作usb摄像头

##pip install opencv-python 
import cv2
 
cap = cv2.VideoCapture(1)##选择第二个摄像头
fourcc = cv2.VideoWriter_fourcc(*\'XVID\')
# fps = cap.get(cv2.CAP_PROP_FPS)
size = (int(cap.get(cv2.CAP_PROP_FRAME_WIDTH)), int(cap.get(cv2.CAP_PROP_FRAME_HEIGHT)))
##保存摄像投的数据为视频文件
out = cv2.VideoWriter(\'camera_test.avi\', fourcc,10.0, size)
while True:
    ret, frame = cap.read()
    # 横向翻转
    frame = cv2.flip(frame, 1)
    out.write(frame)
    # 在图像上显示 Press Q to save and quit
    cv2.putText(frame,
                "Press Q to save and quit",
                (10, 30), cv2.FONT_HERSHEY_SIMPLEX, 0.8,
                (0, 255, 0), 2)
    cv2.imshow(\'frame\', frame)
 
    if cv2.waitKey(1) & 0xFF == ord(\'q\'):
        break
 
cap.release()
out.release()
cv2.destroyAllWindows()

分类:

技术点:

相关文章:

  • 2022-12-23
  • 2021-12-27
  • 2022-12-23
  • 2021-10-18
  • 2021-08-30
  • 2021-06-19
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2021-12-09
  • 2022-02-09
  • 2021-11-21
  • 2022-12-23
  • 2022-12-23
  • 2022-02-07
相关资源
相似解决方案