opencv-python-call the camera to take pictures

Call the camera to take pictures

  • Press the sbutton to take pictures and save it;
  • Press the qkey to exit.
  • You can change the path where the photos are saved by yourself
import cv2

if __name__ == '__main__': 
    i=0
    cap=cv2.VideoCapture(0)
    while(1):
        ret ,frame = cap.read()
        cv2.imshow("capture", frame)

        k=cv2.waitKey(1)
        if k==ord('s'):
            cv2.imwrite('code/opencv/save_pics/'+str(i)+'.jpg',frame)
            i+=1
        elif k==ord("q"):
            break
        
    cap.release()
    cv2.destroyAllWindows()

Show results:

Insert picture description here

Guess you like

Origin blog.csdn.net/qq_45779334/article/details/114676782