Detecting forward or backwards camera movement using OpticalFlow?

I’m trying to detect if a camera is moving backwards or forwards using OpenCV. From the examples and tutorials i see that OpticalFlow using the Lucas-Kanade algorithm may be my best option. Luckily for me, i do not really need to worry about side to side movement or movement at an angle.

The general idea i was thinking is to use the Lucas-Kanade algo in order to generate sets of points (lines) of objects it locates in the scene. If the objects are moving towards the horizon vanishing point (center) then the camera is moving backwards. If they are moving the opposite direction towards the edges of the scene then the camera is moving forwards.

Another idea was to locate objects in the scene and see if the size of them is growing smaller or bigger. This may be hard though as the length of video i have to work with is in the 5 - 10 seconds in length, the camera may move 10 or so feet and there may be nothing in front of the camera to track.

I have seen little to no topics, discussions, or sites that talk about this. Everything is related to a stationary camera and detecting motion of objects in its FOV.

Anyone have an idea of how this can be accomplished?

First run a polar warping on the image (probably the semilog method is better), then do the optical flow and check if the vectors go left-right or inversely…

use DIS optical flow, it’s faster and better than LK.

optical flow for a camera moving forward/backward will have vectors pointing towards the vanishing point, which may or may not be in the center of the view. it will be the point towards which the camera moves.

you should polar-warp those vectors instead of the picture. polar-warping the picture requires interpolation. warping the vectors does not.