Ask Your Question
0

Looking for information regarding how to use DenseOpticalFlow

asked 2013-07-16 08:35:59 -0600

Hi, I'm looking for information and sample code for using the DenseOpticalFlow object. There are two methods listed for the object, cacl and collectGarbage. Does anyone know anything about using this object? What header file is required, what library?

Thanks.

  • Neil Shore
edit retag flag offensive close merge delete

2 answers

Sort by ยป oldest newest most voted
0

answered 2014-04-04 09:18:46 -0600

Dawit gravatar image
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.

edit flag offensive delete link more

Comments

Thanks for the addon, but try to avoid digging up ancient topics. They are here for references mainly, but if we keep throwing them up with new answers newer questions go to second pages and get less frequently answered.

StevenPuttemans gravatar imageStevenPuttemans ( 2014-04-07 02:17:43 -0600 )edit

ok didn't see the date.

Dawit gravatar imageDawit ( 2014-05-19 03:50:34 -0600 )edit

No problem, was just a remark on my side!

StevenPuttemans gravatar imageStevenPuttemans ( 2014-05-19 03:59:08 -0600 )edit

if you are familiar with it could you help me with this :) http://answers.opencv.org/question/33589/dense-optical-flow-dualtvl1-in-ndk/

Dawit gravatar imageDawit ( 2014-05-20 01:54:09 -0600 )edit
0

answered 2013-07-16 08:47:00 -0600

Looking at the OpenCV docs for this function, it is clearly that it is contained inside the Video Analysis Library.

Basically it is a dense approach for calculating the optical flow between subsequent frames, indicating how movement of pixels is happening. Using the calc function you will create the optical flow map for a sequence of subsequent images, as for the collectGarbage, it basically releases all inner intialization of elements, making sure that two subsequent calculations of the optical flow field, won't interfere with eachother.

Optical flow field can then be used to track objects, based on their movement.

The difference between dense and sparse indexing can be read here.

edit flag offensive delete link more

Question Tools

Stats

Asked: 2013-07-16 08:35:59 -0600

Seen: 708 times

Last updated: Apr 04 '14