Get most recent frame from webcam

后端 未结 2 1603
时光说笑
时光说笑 2021-02-20 11:12

I am using OpenCV2 to take some timelapse photos with a webcam. I want to extract the most recent view seen by the webcam. I try to accomplish this like so.

impo         


        
2条回答
  •  没有蜡笔的小新
    2021-02-20 11:56

    I found a bit of code from Capture single picture with opencv that helps. I modified it so that it continuously displays the most recent image captured. It doesn't seem to have a buffer problem, but I might have misunderstood your question.

    import numpy as np
    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):
        ret,frame = cap.read() # return a single frame in variable `frame
        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()
    

提交回复
热议问题