开发者

How to extract velocity vectors from dense optical flow?

开发者 https://www.devze.com 2022-12-14 02:44 出处:网络
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 \"CvAr

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.


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)


If you need the motion vectors for each pixel, then you need to compute what's called 'dense optical flow'. Starting from openCV 2.1, there is a function to do exactly that: calcOpticalFlowFarneback.

See the link below: http://opencv.itseez.com/modules/video/doc/motion_analysis_and_object_tracking.html?highlight=calcopticalflowfarneback#cv2.calcOpticalFlowFarneback


velx and vely are optical flow not the actual velocity. The method you used is Obsolete. Use this calcOpticalFlowFarneback()

0

精彩评论

暂无评论...
验证码 换一张
取 消