问题
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
回答1:
A common way is to use a HSV to RGB transformation, see Middlebury Flow Dataset. Therefore:
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]
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.
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.
来源:https://stackoverflow.com/questions/10014776/how-should-i-use-the-velx-vely-information-to-get-the-displacement-in-x-and-y-be