python-opencv 调取摄像头并保存图片

通过opencv-python 调用摄像头并保存图片

import torch
# -*- coding:utf-8 -*-
import numpy as np
import cv2
import matplotlib.pyplot as plt

cap = cv2.VideoCapture(0)

while True:
    ret, frame = cap.read()
    cv2.imshow('f', frame)
    if cv2.waitKey(1) & 0xFF == ord('q'):
        # cv2_im = cv2.cvtColor(frame, cv2.COLOR_BGR2RGB)
        cv2.imwrite('result/1.jpg', frame)
        # cv2.imshow('chengoj', cv2_im)
        # cv2.waitKey(5)
        break
cap.release()
cv2.destroyAllWindows()

你可能感兴趣的:(opencv)