0
点赞
收藏
分享

微信扫一扫

Python OpenCV 从视频保存图片

雪域迷影 2022-03-30 阅读 215
pythonopencv
# 读取数据
import cv2
cam_port_num = 0
# 定位对象
video = cv2.VideoCapture(cam_port_num)

while (True):
    # 收集 video frame
    # 采用frame
    result, frame = video.read()

    # 显示结果
    cv2.imshow('video', frame)

    # 按s保存图片
    if cv2.waitKey(1) & 0xFF == ord('s'):
        cv2.imwrite("img.png", frame)
        print('ok')
        continue
    # 按q退出
    if cv2.waitKey(1) & 0xFF == ord('q'):
        break

# 使用循环loop指令后 release 视频
video.release()
# Destroy all the windows
cv2.destroyAllWindows()
举报

相关推荐

0 条评论