python 实现拍照

安装CV2 :pip install -i https://pypi.tuna.tsinghua.edu.cn/simple opencv-python
import cv2
cap=cv2.VideoCapture(0)
width, height = cap.get(3), cap.get(4)
cap.set(cv2.CAP_PROP_FRAME_WIDTH, width)
cap.set(cv2.CAP_PROP_FRAME_HEIGHT, height)
设置大小
i = 0
while 1:
    ret ,frame = cap.read()
    k=cv2.waitKey(1)
    if k==27:
        break
    elif k==ord('s'):
        print("保存成功")
        cv2.imwrite('1.jpg',frame)保存操作
        i+=1
    cv2.imshow("capture", frame)
cap.release()
cv2.destroyAllWindows()

评论

刷新

友情链接