If i do:
while(1) {
//retrieve image from the camera
webCamImage=cvQueryFrame(camera) // where 'camera' is cvCreateCameraCapture(0)
//do some heavy processing on the image that may take around half a second
funcA()
}
Now when I go to consecutive iterations, it seems that webCamImage lags !
Even if i move the camera, webCamImage takes long time to get updated to the new field of view, and it keeps showing and processing previous field of view camera frames.
I am assuming that cvQuery has some buffer that retrieves the frames.
Can you please advise me on how to get the updated camera view each iteration ?
Many thanks
cvQueryFrameis just a wrapper that calls 2 other functions:cvGrabFrame, which gets data from the camera very quickly, andcvRetrieveFrame, which uncompresses this data and puts it into anIplImage. If you need frames captured immediately, just grab the frame, and retrieve it for processing later.See http://opencv.jp/opencv-1.0.0_org/docs/ref/opencvref_highgui.htm FMI
Having said that, though, I use
cvQueryFramewith a typical webcam, and I have no trouble getting dozens of frames per second. Any chance that the part that’s lagging is actually in yourfuncA()call? edit: from the comment in your code, I see thatfuncA()is indeed the slow part. If it takes half a second to execute, you’ll only get a new frame fromcvQUeryFrameevery half second, just as you describe. Try either makingfuncAfaster, or put it in a separate thread.and as a friendly reminder, the
IplImagereturned bycvQueryFrame/cvRetrieveFrameshould not be modified or deleted by the user; it’s part of OpenCV’s internal system for storing things, and if you’re doing anything interesting with it, you should make a copy. I don’t know if you’re doing this already, but I certainly did it wrong when I started out.