Pregunta

Can anybody help me to get the velocity information of each pixel from OpenCV's cvCalcOpticalFlowPyrLK?

¿Fue útil?

Solución

Look at the example (https://github.com/Itseez/opencv/blob/master/samples/cpp/lkdemo.cpp) that is also available with the openCV code.

A superquick summary:

calcOpticalFlowPyrLK is sparse so it needs points to calculate the optical flow from. use goodFeaturesToTrack to initialize the points ( takes an image and an empty point vector as input (plus some parameters available in the documentation) )

Then use cornerSubPix to refine point positions (takes an image and a full point vector (plus other params))

Finally load a new image and run calcOpticalFlowPyrLK on the points you have initialized on the previous one (takes two images (this and previous) and a full and empty point vector (corresponding to points in the previous image and this one). (you probably won't need to initialize points for the next image, but rather use the ones that calcOpticalFlowPyrLK provided)

The difference in point position divided by the time between images gives you the velocity.

But do look at the example for details

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top