I am trying to grab a single frame from the webcam using OpenCV. But the image returned by the QueryFrame() is much older than the current frame. It takes multiple QueryFrame() calls to get the most recent image but even that lags by 2 to 3 seconds from the expected current image. I tried using different webcams but the outcomes are same. I tried the read() method from cv2 and had the same issues. Is there anyway to fix this and get the current frame from the webcam using OpenCV?
Webcam has 30fps with 640/480 resolution. OS : Ubuntu 12.04, OpenCV 2.4.9
# CV code
import cv
capture = cv.CaptureFromCAM(0)
img = cv.QueryFrame(capture)
cv.SaveImage("test2.JPG", img)
# CV2 code
import cv2
cam = cv2.VideoCapture()
cam.open(-1)
img=cam.read()
cv2.imwrite("test3.jpg",img[1])