mrushyendra / planar-segmentation

Segmentation of a video frame into ground and upright objects using sparse and dense optical flow techniques in OpenCV.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Planar Segmentation

Given a top-down video from a moving vehicle, this program uses optical flow techniques to segment an image frame from the video into a ground portion and a moving/elevated portion. The user has 2 options - (i) using dense optical flow and (ii) sparse optical flow.

Note: The program aims to simply demonstrate the use of this technique. Use in production may require various modifications.

(i) Dense Optical Flow

Flow vectors are calculated for the movement of each pixel between 2 successive frames in a video. Objects/Structures that protrude from the ground have larger displacements, and thus larger flow vectors, and are colored accordingly. Contours are generated based on the original image and this is compared with the flow vectors to outline the shapes of objects that rise from the ground.

Results of planar segmentation using dense optical flow

(Clockwise, from top left: initial image, contour detection, dense optical flow calculation, final shortlisted contours)

(ii) Sparse Optical Flow

Results of planar segmentation using sparse optical flow

To speed up computation, optical flow is only calculated for a sparse grid of points using the Lucas Kanade method. The results are drawn onto the video frame, with pixels that have large displacement highlighted (i.e. pixels representing objects that lie above the ground plane).

Usage (after compiling):

./[Program Name] [VideoFileName]

About

Segmentation of a video frame into ground and upright objects using sparse and dense optical flow techniques in OpenCV.


Languages

Language:C++ 94.5%Language:C 5.5%