Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

VideoCapture read non blocking?

I am programming in Python, Pygame from what I understand uses opencv for its webcam functions. There is a query_image() available that polls the camera so you can start fetching a frame only when there is a frame to fetch, for example:

pygame.init()
pygame.camera.init()
webcam = pygame.camera.Camera("/dev/video0",(320,240))
webcam.start()
if(webcam.query_image()):
    image = webcam.get_image()

When I use the following code with opencv:

cap = cv2.VideoCapture(0)
rval, frame = cap.read()

It waits until the frame is fetched which is for me undesirable, is there a way to poll the camera before trying to fetch to see if there is a frame available?