1 | initial version |
Mat New_Previous_Gray (holds the previous image)
Mat New_Current_Gray (holds the current image)
Mat_<Point2f> Optical_Flow;
Ptr<DenseOpticalFlow> tvl1 = createOptFlow_DualTVL1();
tvl1->calc(New_Previous_Gray, New_Current_Gray, Optical_Flow);
for(int y = 0; y < Optical_Flow.cols; y++)
{
for(int x = 0; x < Optical_Flow.rows; x++)
{
const Point2f& flow_xy = Optical_Flow.at<Point2f>(x, y);
int Vel_x = flow_xy.x;
int Vel_y = flow_xy.y;
Pxl_Distance = sqrt(double(((abs(Vel_x) * abs(Vel_x)) + (abs(Vel_y) * abs(Vel_y)))));
}
}
so i could get the velocity for every pixel in "Pxl_Distance".
hope this sample code is clear cheers.