# segmentation

This element creates and updates a fg/bg model using one of several approaches. The one called "codebook" refers to the codebook approach following the opencv O'Reilly book [1] implementation of the algorithm described in K. Kim, T. H. Chalidabhongse, D. Harwood and L. Davis [2]. BackgroundSubtractorMOG [3], or MOG for shorts, refers to a Gaussian Mixture-based Background/Foreground Segmentation Algorithm. OpenCV MOG implements the algorithm described in [4]. BackgroundSubtractorMOG2 [5], refers to another Gaussian Mixture-based Background/Foreground segmentation algorithm. OpenCV MOG2 implements the algorithm described in [6] and [7].

[1] Learning OpenCV: Computer Vision with the OpenCV Library by Gary Bradski and Adrian Kaehler, Published by O'Reilly Media, October 3, 2008 [2] "Real-time Foreground-Background Segmentation using Codebook Model", Real-time Imaging, Volume 11, Issue 3, Pages 167-256, June 2005. [3] http://opencv.itseez.com/modules/video/doc/motion_analysis_and_object_tracking.html#backgroundsubtractormog [4] P. KadewTraKuPong and R. Bowden, "An improved adaptive background mixture model for real-time tracking with shadow detection", Proc. 2nd European Workshop on Advanced Video-Based Surveillance Systems, 2001 [5] http://opencv.itseez.com/modules/video/doc/motion_analysis_and_object_tracking.html#backgroundsubtractormog2 [6] Z.Zivkovic, "Improved adaptive Gaussian mixture model for background subtraction", International Conference Pattern Recognition, UK, August, 2004. [7] Z.Zivkovic, F. van der Heijden, "Efficient Adaptive Density Estimation per Image Pixel for the Task of Background Subtraction", Pattern Recognition Letters, vol. 27, no. 7, pages 773-780, 2006.

## Example launch line

     gst-launch-1.0  v4l2src device=/dev/video0 ! videoconvert ! segmentation test-mode=true method=2 ! videoconvert ! ximagesink

## Hierarchy

    GObject
        ╰──GInitiallyUnowned
            ╰──GstObject
                ╰──GstElement
                    ╰──GstBaseTransform
                        ╰──GstVideoFilter
                            ╰──GstOpencvVideoFilter
                                ╰──segmentation

## Factory details

Authors: – Miguel Casas-Sanchez <miguelecasassanchez></miguelecasassanchez>

Classification: – `Filter/Effect/Video`

Rank – none

Plugin – opencv

Package – GStreamer Bad Plug-ins

## Pad Templates

### `sink`

    video/x-raw:
             format: RGBA
              width: [ 1, 2147483647 ]
             height: [ 1, 2147483647 ]
          framerate: [ 0/1, 2147483647/1 ]

Presence – always

Direction – sink

Object type – GstPad

### `src`

    video/x-raw:
             format: RGBA
              width: [ 1, 2147483647 ]
             height: [ 1, 2147483647 ]
          framerate: [ 0/1, 2147483647/1 ]

Presence – always

Direction – src

Object type – GstPad

## Properties

### learning-rate

    “learning-rate” gfloat

Speed with which a motionless foreground pixel would become background (inverse of number of frames)

Flags : Read / Write

Default value : 0.01

### method

    “method” Segmentation-method *

Segmentation method to use

Flags : Read / Write

Default value : mog2 (2)

### test-mode

    “test-mode” gboolean

If true, the output RGB is overwritten with the calculated foreground (white color)

Flags : Read / Write

Default value : false

## Named constants

### Segmentation-method

#### Members

`codebook` (0) – Codebook-based segmentation (Bradski2008)
`mog` (1) – Mixture-of-Gaussians segmentation (Bowden2001)
`mog2` (2) – Mixture-of-Gaussians segmentation (Zivkovic2004)

The results of the search are