cvloop functions

This notebook shows an overview over all cvloop functions provided in the cvloop.functions module.

cvloop.functions.ForegroundExtractor [[Source](https://github.com/shoeffner/cvloop/blob/develop/cvloop/functions.py#L9)]

Performs background subtraction using the supplied Subtractor and extracts the foreground accordingly.

ForegroundExtractor.__init__(...):

Initializes the ForegroundExtractor.

Uses the supplied BackgroundSubtractor as subtractor to get a mask and apply the mask to the image.

Args:

  • subtractor: A BackgroundSubtractor. Defaults to an instance of BackgroundSubtractorMOG2.

In [ ]:
from cvloop import cvloop, ForegroundExtractor
cvloop(function=ForegroundExtractor(), side_by_side=True)

cvloop.functions.BackgroundSubtractorGMG [[Source](https://github.com/shoeffner/cvloop/blob/develop/cvloop/functions.py#L32)]

Performs background subtraction with a mixture of gaussians.

The method used was described by Godbehere, Matsukawa, and Goldberg in Visual Tracking of Human Visitors under Variable-Lighting Conditions for a Responsive Audio Art Installation (2012).

See also http://docs.opencv.org/3.1.0/db/d5c/tutorial_py_bg_subtraction.html.

BackgroundSubtractorGMG.__init__(...):

Initializes the BackgroundSubtractorGMG.

Note: Requires OpenCV to be built with --contrib as it uses the bgsegm package.

Unless a custom structuring_element is specified, it uses: cv2.getStructuringElement(cv2.MORPH_ELLIPSE, (3, 3))

Args:

  • structuring_element: The structuring element.

In [ ]:
from cvloop import cvloop, BackgroundSubtractorGMG
cvloop(function=BackgroundSubtractorGMG(), side_by_side=True)

cvloop.functions.BackgroundSubtractorMOG [[Source](https://github.com/shoeffner/cvloop/blob/develop/cvloop/functions.py#L68)]

Performs background subtraction with a mixture of gaussians.

The method used was described by KaewTraKulPong and Bowden in An improved adaptive background mixture model for real-time tracking with shadow detection (2001).

See also http://docs.opencv.org/3.1.0/db/d5c/tutorial_py_bg_subtraction.html.

BackgroundSubtractorMOG.__init__(...):

Initializes the BackgroundSubtractorMOG.

Note: Requires OpenCV to be built with --contrib as it uses the bgsegm package.


In [ ]:
from cvloop import cvloop, BackgroundSubtractorMOG
cvloop(function=BackgroundSubtractorMOG(), side_by_side=True)

cvloop.functions.BackgroundSubtractorMOG2 [[Source](https://github.com/shoeffner/cvloop/blob/develop/cvloop/functions.py#L93)]

Performs background subtraction with a mixture of gaussians.

The method used was described in two papers by Zivkovic and van der Heijden, Improved adaptive Gausian mixture model for background subtraction (2004) and Efficient Adaptive Density Estimation per Image Pixel for the Task of Background Subtraction (2006)

See also http://docs.opencv.org/3.1.0/db/d5c/tutorial_py_bg_subtraction.html.

BackgroundSubtractorMOG2.__init__(...):

Initializes the BackgroundSubtractorMOG2.


In [ ]:
from cvloop import cvloop, BackgroundSubtractorMOG2
cvloop(function=BackgroundSubtractorMOG2(), side_by_side=True)

cvloop.functions.Inverter [[Source](https://github.com/shoeffner/cvloop/blob/develop/cvloop/functions.py#L117)]

Inverts the colors of the image.

Inverter.__init__(...):

Initializes the Inverter with a high value.

Args:

  • high: the value from which the image has to be subtracted. Defaults to 255.

In [ ]:
from cvloop import cvloop, Inverter
cvloop(function=Inverter(), side_by_side=True)

cvloop.functions.DrawHat [[Source](https://github.com/shoeffner/cvloop/blob/develop/cvloop/functions.py#L134)]

Draws hats above detected faces.

Uses a Haar cascade for face detection and draws provided hats above the detected faces.

The default hat (examples/hat.png) is taken from https://pixabay.com/en/hat-trilby-black-brim-crease-felt-157581/ and was released unter CC0 Public Domain.

DrawHat.__init__(...):

Initializes a DrawHat instance.

Args:

  • hat_path: The path to the hat file. Defaults to ./hat.png .
  • cascade_path: The path to the face cascade file. Defaults to cvloop.OPENCV_CASCADE_PATH/haarcascades/ haarcascade_frontalface_default.xml
  • w_offset: Hat width additional scaling.
  • x_offset: Number of pixels right to move hat.
  • y_offset: Number of pixels down to move hat.
  • draw_box: If True, draws boxes around detected faces.

In [ ]:
from cvloop import cvloop, DrawHat
cvloop(function=DrawHat(), side_by_side=True)