I'm using the OpenCV wrapper - Emgu CV, and I'm trying to implement a motion tracker using Optical Flow, but I can't figure out a way to combine the horizontal and vertical information retrieved from the OF algorithm:
flowx = new Image<Gray, float>(size);
flowy = new Image<Gray, float>(size);
OpticalFlow.LK(currImg, prevImg, new Size(15, 15), flowx, flowy);
My problem is not knowing how to combine the info of vertical and horizontal movement in order to build the tracker of moving objects? A new image?
By the way, there is a easy way to display the flow info on the current frame?
Thanks in advance.
Here is the function i have defined in my youtube head movement tracker video tutorial. You can find the full source code attached to the video
Optical flow visualization. The common approach is to use a color-coded 2D flow field. It means that we display the flow as an image, where pixel intensity corresponds to the absolute value of the flow in the pixel, while the hue reflects the direction of the flow. Look at Fig.2 in [Baker et al., 2009]. Another way is to draw vectors of flow in a grid over the first image (say, every 10 pixels).
Combining x and y. It is not clear what you mean here. The pixel (x,y) from the first image is moved to (x+flowx, y+flowy) on the second one. So, to track an object you fix the position of the object on the first image and add the flow value to get its position on the second one.
There are some known optical flow algorithms. one of them that may be good for you is Lucas Kanade.. you can find a matlab source here