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

浪尽此生 提交于 2019-12-11 17:40:43

问题


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:

  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.



来源:https://stackoverflow.com/questions/10014776/how-should-i-use-the-velx-vely-information-to-get-the-displacement-in-x-and-y-be

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!