What exactly is the output when we run the dense o

2019-07-06 05:21发布

问题:

I have been running the Python implementation code of Dense Optical Flow given in the official documentation page. At one particular line of the code, they use
mag, ang = cv2.cartToPolar(flow[...,0], flow[...,1]). When I print the values of mag, I get these - Please check this image for the output I'm getting

I have no idea how to make sense of this output.

My end objective is to use optical flow to get a resultant or an average motion value for every frame.

回答1:

Quoting the same OpenCV tutorial you use

We get a 2-channel array with optical flow vectors, (u,v).

That is the output of the dense optical flow. Basically it tells you how each of the points moved in a vectorial way. (u,v) is just the cartesian representation of a vector and it can be converted to polar coordinates, this means an angle and the magnitude.

The angle is the orientation where the pixel moved. And the magnitude is the distance that the pixel moved.

In many algorithms you may use the magnitude to know if the pixel moved (less than 1 means no movement for example). Or if you are tracking an object which you know the initial position (meaning the pixels position of the object) you may find where the majority of the pixels are moving to, and use that info to determine the new position.

BTW, cartToPolar returns the angles in Radians unless it is specified. Here is an extract of the documentation:

cv2.cartToPolar(x, y[, magnitude[, angle[, angleInDegrees]]]) → magnitude, angle

angleInDegrees must be True if you need it in degrees.