snipplets.dev/code/Python/opencv/capture-image.py
2023-09-26 22:05:13 +03:00

22 lines
368 B
Python
Executable File

#!/usr/bin/env python3
import cv2
cam_port = 2
cam = cv2.VideoCapture(cam_port)
while True:
result, image = cam.read()
cv2.imshow('Camera', image)
if cv2.waitKey(1) & 0xFF == ord('s'):
cv2.imwrite('capture.png', image)
if cv2.waitKey(1) & 0xFF == ord('q'):
break
cam.release()
cv2.destroyWindow('Camera')
cv2.destroyAllWindows()