Ask Your Question

Revision history [back]

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*/

      }
 }