# extracting Magnitude and angle from flowfeature 1)I wanted to get all the pixels with some motion and wanted to store the position and angle in some data structure(Which data structure to use and how?). Could anyone help me how I could do it.

2)Whether the below code is correct to extract the magnitude and direction of Optical Flow vector. If so how I can I do the operation mentioned in 1) from here on.

3)I find that the openCV manual could be supplemented with examples of the usage of different functions. I am not sure whether anyone else think the same.I think it will help new users. Now to write code I need to do lot of search on the net. :(. However community is having good response.

calcOpticalFlowFarneback(prevgray, gray, flow, 0.5, 3, 15, 3, 5, 1.2, 0);
Mat xy;
split(flow, xy);
//calculate angle and magnitude
Mat magnitude, angle;
cartToPolar(xy, xy, magnitude, angle, true);


edit retag close merge delete

1

Opensource is free. If you want a better manual you can contribute

I have just started to use the Opencv.I am sure that I could contribute in future.

Sort by » oldest newest most voted

Through trial and error I got the answer .Hope this will help someone: :)

 calcOpticalFlowFarneback(prevgray, gray, flow, 0.5, 3, 15, 3, 5, 1.2, 0);
Mat xy;
split(flow, xy);
//calculate angle and magnitude
Mat magnitude, angle;
cartToPolar(xy, xy, magnitude, angle, true);
for(int y = 0; y < prevgray.rows; y++)
{
for(int x = 0; x < prevgray.cols; x++)
{
const Point2f& fxy = flow.at< Point2f>(y, x);
float magxy = magnitude.at<float>(y,x);
float angleDeg = angle.at<float>(y,x);
/*Print them(magxy, angleDeg) here*/

}
}

more

can you highlight , what the actual problem was ? (i don't see it in your question)

1

Berek: There was no problem. It was just that I did not know how to interpret the data as I did not understand the Mat object clearly. In fact I wanted to get the magnitude and direction of all the pixels with Optical flow.

Official site

GitHub

Wiki

Documentation

## Stats

Asked: 2016-02-15 10:58:58 -0500

Seen: 657 times

Last updated: Feb 18 '16