I'm not doing nothing in particular, but i'm reading the opencv documentation and I can't understand the difference between the method read
and grab
from the VideoCapture
, here this what they do:
grab: The methods/functions grab the next frame from video file or camera and return true (non-zero) in the case of success.
read: decodes and returns the next video frame.
In the two method extract the next frame. what is the difference? Link to the documentation
There's a subtle yet significant difference that becomes more obvious when taking a closer look at the documentation for each of the two methods.
grab
"only" gets the image from the camera and holds it for further processing:
The methods/functions grab the next frame from video file or camera and return true (non-zero) in the case of success. [...] you call
VideoCapture::grab()
for each camera and after that call the slower methodVideoCapture::retrieve()
to decode and get frame from each camera.
In this case, you still have to retrieve the frame (i.e. "decode and get") from OpenCV so that you can work with it. grab
only returns a boolean that indicates whether OpenCV was able to get the frame from the camera - the return parameter in this case is not the frame.
read
combines both grab
and retrieve
operations into one command and returns the already decoded frame:
The methods/functions combine
VideoCapture::grab()
andVideoCapture::retrieve()
in one call. This is the most convenient method for reading video files or capturing data from decode and return the just grabbed frame. If no frames has been grabbed (camera has been disconnected, or there are no more frames in video file), the methods return false and the functions return NULL pointer.
This method returns the actual frame back to your application so you don't have to worry about checking the boolean parameter and writing an additional line of code to get the frame back by OpenCV.
Depending on your application it may be easier to just use read
as it will likely save you one or two lines of code.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With