void drawOptFlowMap (const Mat& flow, Mat& cflowmap, int step, double scale, const Scalar& color) {
for(int y = 0; y < cflowmap.rows; y += step)
for(int x = 0; x < cflowmap.cols; x += step)
{
const Point2f& fxy = flow.at<Point2f>(y, x);
line(cflowmap, Point(x,y), Point(cvRound(x+fxy.x), cvRound(y+fxy.y)),
color);
circle(cflowmap, Point(cvRound(x+fxy.x), cvRound(y+fxy.y)), 1, color, -1);
}
}
int main()
{
...read, declare images etc....
cvNamedWindow("optical Flow", CV_WINDOW_NORMAL);
calcOpticalFlowFarneback(Previous_Gray, Current_Gray, flow, 0.5, 3, 15, 3, 5, 1.2, 0);
cvtColor(Previous_Gray, cflow, CV_GRAY2BGR);
drawOptFlowMap(flow, cflow, 32, 50, CV_RGB(0, 255, 0));
imshow("optical Flow", cflow);
etc etc
}