# grabcut

This element is a wrapper around OpenCV grabcut implementation. GrabCut is an image segmentation method based on graph cuts technique. It can be seen as a way of fine-grain segmenting the image from some FG and BG "seed" areas. The OpenCV implementation follows the article [1]. The "seed" areas are taken in this element from either an input bounding box coming from a face detection, or from alpha channel values. The input box is taken from a "face" event such as the one generated from the 'facedetect' element. The Alpha channel values should be one of the following (cv.hpp): enum{ GC_BGD = 0, //!< background GC_FGD = 1, //!< foreground GC_PR_BGD = 2, //!< most probably background GC_PR_FGD = 3 //!< most probably foreground }; with values over GC_PR_FGD interpreted as GC_PR_FGD. IN CASE OF no alpha mask input (all 0's or all 1's), the 'GstOpenCvFaceDetect-face' downstream event is used to create a bbox of PR_FG elements. If both foreground alpha is not specified and there is no face detection, nothing is done.

[1] C. Rother, V. Kolmogorov, and A. Blake, "GrabCut: Interactive foreground extraction using iterated graph cuts, ACM Trans. Graph., vol. 23, pp. 309–314, 2004.

## Example launch line

     gst-launch-1.0 --gst-debug=grabcut=4  v4l2src device=/dev/video0 ! videoconvert ! grabcut ! videoconvert ! video/x-raw,width=320,height=240 ! ximagesink

Another example launch line

     gst-launch-1.0 --gst-debug=grabcut=4  v4l2src device=/dev/video0 ! videoconvert ! facedetect display=0 ! videoconvert ! grabcut test-mode=true ! videoconvert ! video/x-raw,width=320,height=240 ! ximagesink

## Hierarchy

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

## Factory details

Authors: – Miguel Casas-Sanchez

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

### scale

    “scale” gfloat

Grow factor for the face bounding box, if present

Flags : Read / Write

Default value : 1.6

### test-mode

    “test-mode” gboolean

If true, the output RGB is overwritten with the segmented foreground. Alpha channel same as normal case

Flags : Read / Write

Default value : false

The results of the search are