Capture single picture with opencv

后端 未结 3 2392
迷失自我
迷失自我 2021-02-20 10:20

I have seen several things about capturing frames from a webcam stream using python and opencv, But how do you capture only one picture at a specified resolution with python and

3条回答
  •  天涯浪人
    2021-02-20 11:13

    You can capture a single frame by using the VideoCapture method of OpenCV.

    import cv2
    
    cap = cv2.VideoCapture(0) # video capture source camera (Here webcam of laptop) 
    ret,frame = cap.read() # return a single frame in variable `frame`
    
    while(True):
        cv2.imshow('img1',frame) #display the captured image
        if cv2.waitKey(1) & 0xFF == ord('y'): #save on pressing 'y' 
            cv2.imwrite('images/c1.png',frame)
            cv2.destroyAllWindows()
            break
    
    cap.release()
    

    Later you can modify the resolution easily using PIL.

提交回复
热议问题