Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to extract velocity vectors from dense optical flow?

Problem: I'm trying to align two frames of a moving video.

I'm currently trying to use the function "cvCalcOpticalFlowLK" and the result outputs velocity vectors of x and y in the form of a "CvArr".

So I obtained the result, but i'm not sure how to use these vector arrays.

My question is this... how do i know what is the velocity of each pixel? Is it just the value of each pixel value at that particular point?

Note: I would've used the other optical flow functions such as cvCalcOpticalFlowPyrLK() as it is much easier, but i want the dense optical flow.

like image 946
monky822 Avatar asked Dec 10 '09 00:12

monky822


1 Answers

Apparently my original assumption was true. The "velx" and "vely" outputs from the optical flow function are the actual velocities for each pixel value. To best extract them, I accessed the pixel from the raw data and pulled the value. There are 2 ways to do this.

cvGet2D() -- this way is slower but if you only need to access 1 pixel it's okay.

or

(uchar*)(image->imageData + height*image->widthStep + width);

(image is an IplImage, width and height are just the corresponding widths and heights of the image)

like image 167
monky822 Avatar answered Dec 26 '22 11:12

monky822