Ask Your Question
0

extracting Magnitude and angle from flowfeature

asked 2016-02-15 10:58:58 -0600

santhoshkelathodi gravatar image

updated 2016-02-18 06:05:41 -0600

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[2];
split(flow, xy);
//calculate angle and magnitude
Mat magnitude, angle;
cartToPolar(xy[0], xy[1], magnitude, angle, true);

edit retag flag offensive close merge delete

Comments

1

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

LBerger gravatar imageLBerger ( 2016-02-18 05:32:20 -0600 )edit

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

santhoshkelathodi gravatar imagesanthoshkelathodi ( 2016-02-22 03:59:43 -0600 )edit

1 answer

Sort by ยป oldest newest most voted
0

answered 2016-02-18 05:09:50 -0600

santhoshkelathodi gravatar image

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[2];
 split(flow, xy);
 //calculate angle and magnitude
 Mat magnitude, angle;
 cartToPolar(xy[0], xy[1], 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*/

      }
 }
edit flag offensive delete link more

Comments

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

berak gravatar imageberak ( 2016-02-18 05:21:55 -0600 )edit
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.

santhoshkelathodi gravatar imagesanthoshkelathodi ( 2016-02-22 03:59:10 -0600 )edit

Question Tools

1 follower

Stats

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

Seen: 1,537 times

Last updated: Feb 18 '16