farzin parsa
farzin parsa

Reputation: 547

how should I use the velX,velY information to get the displacement in X and Y between current frame and previous frame?

I am using the Lucas Kanade Optical Flow algorithm from openCV library in C#; There are series of frames that in every two of them I want to find out what was the optical flow and show it in a pictureBox.

I could fetch the velX & velY from following function:

Emgu.CV.OpticalFlow.LK(imGrayCurrent, imGrayNext, windSize, velX, velY);

Now,How should I use these two for show the flow between two frames? or in other words how should I get the displacement of pixels?

Tnx

Upvotes: 0

Views: 657

Answers (1)

Tobias Senst
Tobias Senst

Reputation: 2830

A common way is to use a HSV to RGB transformation, see Middlebury Flow Dataset. Therefore:

  1. Transform motion vectors to polar coordinates:

    length = sqrt(velx² + vely²)

    angle = acos(vely / length) [Attention additional checks for e.g. infinity has to be done]

  2. Normalize angle to [0,360] (for OpenCV, or [0,1] depending on the function you use later) and the length to [0,1]. Create a hsv space (3-Channel Image with the first channel H (Hue), second channel S (Saturation) and the third channel V (Value)) and set: H = angle, S = length and V = 1.

  3. Convert HSV colorspace to RGB e.g. by using cv::cvtColor(hsv, rgb, HSV2BGR);

The resulting image show now the motion vector field (velx,vely) where the color donates the direction of your motion and the saturation the length or speed of your motion.

Upvotes: 1

Related Questions