python-123

1.首先,需要安装opencv库文件,可以通过PIP install opencv-python(scripts目录下安装);

 

2.其次,验证安装版本pip list;

 

3.验证能否打开摄像头,实例如下(亲测可用):

import cv2

cap = cv2.VideoCapture(0)

while True:

  ret,frame =cap.read()

  cv2.imshow(\'frame\',frame)

  if cv2,waitKey(1) == ord(\'1\'):

    break

cap.release()

cv2.destroyAllWindows()

 

4.验证可以录制视频并保存在指定路径下,实例如下(亲测可用):

import cv2

import matplotlib

import numpy

import os

global now_time

cap = cv2.VideoCapture(0)

fourcc = cv2.VideoWriter_fourcc(*"MJPG")

out = cv2.VideoWriter("C:\\A\\output.avi",fourcc,25.,(640,480))

while(cap.isOpened()):

  ret,frame =cap.read()

  if ret:

    out.write(frame)

    cv2.imshow(\'frame\',frame)

    if cv2,waitKey(1) == ord(\'1\'):

      break

  else:break

cap.release()

out.release()

cv2.destroyAllWindows()

 

分类:

技术点:

相关文章:

  • 2021-11-02
  • 2021-12-14
  • 2021-11-14
  • 2021-12-15
  • 2021-12-14
  • 2021-11-02
  • 2022-01-21
  • 2021-10-09
猜你喜欢
  • 2021-08-24
  • 2021-12-15
  • 2021-11-08
  • 2021-10-17
  • 2021-09-23
  • 2021-08-15
  • 2021-10-27
相关资源
相似解决方案