OpenCV Q&A Forum - RSS feedhttp://answers.opencv.org/questions/OpenCV answersenCopyright <a href="http://www.opencv.org">OpenCV foundation</a>, 2012-2018.Mon, 22 Feb 2016 03:59:43 -0600extracting Magnitude and angle from flowfeaturehttp://answers.opencv.org/question/87733/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[2];
split(flow, xy);
//calculate angle and magnitude
Mat magnitude, angle;
cartToPolar(xy[0], xy[1], magnitude, angle, true);
----------------------------------------------------------------
Mon, 15 Feb 2016 10:58:58 -0600http://answers.opencv.org/question/87733/extracting-magnitude-and-angle-from-flowfeature/Comment by LBerger for <p>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. </p>
<p>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.</p>
<p>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.</p>
<hr/>
<pre><code>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);
</code></pre>
<hr/>
http://answers.opencv.org/question/87733/extracting-magnitude-and-angle-from-flowfeature/?comment=87965#post-id-87965Opensource is free. If you want a better manual you can [contribute](http://opencv.org/contribute.html)Thu, 18 Feb 2016 05:32:20 -0600http://answers.opencv.org/question/87733/extracting-magnitude-and-angle-from-flowfeature/?comment=87965#post-id-87965Comment by santhoshkelathodi for <p>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. </p>
<p>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.</p>
<p>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.</p>
<hr/>
<pre><code>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);
</code></pre>
<hr/>
http://answers.opencv.org/question/87733/extracting-magnitude-and-angle-from-flowfeature/?comment=88242#post-id-88242I have just started to use the Opencv.I am sure that I could contribute in future.Mon, 22 Feb 2016 03:59:43 -0600http://answers.opencv.org/question/87733/extracting-magnitude-and-angle-from-flowfeature/?comment=88242#post-id-88242Answer by santhoshkelathodi for <p>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. </p>
<p>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.</p>
<p>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.</p>
<hr/>
<pre><code>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);
</code></pre>
<hr/>
http://answers.opencv.org/question/87733/extracting-magnitude-and-angle-from-flowfeature/?answer=87962#post-id-87962Through 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*/
}
}Thu, 18 Feb 2016 05:09:50 -0600http://answers.opencv.org/question/87733/extracting-magnitude-and-angle-from-flowfeature/?answer=87962#post-id-87962Comment by santhoshkelathodi for <p>Through trial and error I got the answer .Hope this will help someone: :)</p>
<hr/>
<pre><code> 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*/
}
}
</code></pre>
http://answers.opencv.org/question/87733/extracting-magnitude-and-angle-from-flowfeature/?comment=88240#post-id-88240Berek: 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.Mon, 22 Feb 2016 03:59:10 -0600http://answers.opencv.org/question/87733/extracting-magnitude-and-angle-from-flowfeature/?comment=88240#post-id-88240Comment by berak for <p>Through trial and error I got the answer .Hope this will help someone: :)</p>
<hr/>
<pre><code> 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*/
}
}
</code></pre>
http://answers.opencv.org/question/87733/extracting-magnitude-and-angle-from-flowfeature/?comment=87964#post-id-87964can you highlight , what the actual *problem* was ? (i don't see it in your question)Thu, 18 Feb 2016 05:21:55 -0600http://answers.opencv.org/question/87733/extracting-magnitude-and-angle-from-flowfeature/?comment=87964#post-id-87964