| OpenCV 5.0.0alpha Open Source Computer Vision

Loading...
Searching...
No Matches
Classes | Functions
Image Segmentation
Image Processing

## Detailed Description

## Classes
class | cv::segmentation::IntelligentScissorsMB
| Intelligent Scissors image segmentation. More...

## Functions
void | cv::grabCut (InputArray img, InputOutputArray mask, Rect rect, InputOutputArray bgdModel, InputOutputArray fgdModel, int iterCount, int mode=GC_EVAL)
| Runs the GrabCut algorithm.
void | cv::watershed (InputArray image, InputOutputArray markers)
| Performs a marker-based image segmentation using the watershed algorithm.

## Function Documentation

## ◆ grabCut()

void cv::grabCut | ( | InputArray | img,
|  | InputOutputArray | mask,
|  | Rect | rect,
|  | InputOutputArray | bgdModel,
|  | InputOutputArray | fgdModel,
|  | int | iterCount,
|  | int | mode = GC_EVAL )

Python:
| cv.grabCut( | img, mask, rect, bgdModel, fgdModel, iterCount[, mode] | ) -> | mask, bgdModel, fgdModel

`#include <opencv2/imgproc.hpp>`

Runs the GrabCut algorithm.

The function implements the GrabCut image segmentation algorithm.

Parameters

  img | Input 8-bit 3-channel image.
  mask | Input/output 8-bit single-channel mask. The mask is initialized by the function when mode is set to GC_INIT_WITH_RECT. Its elements may have one of the GrabCutClasses.
  rect | ROI containing a segmented object. The pixels outside of the ROI are marked as "obvious background". The parameter is only used when mode==GC_INIT_WITH_RECT .
  bgdModel | Temporary array for the background model. Do not modify it while you are processing the same image.
  fgdModel | Temporary arrays for the foreground model. Do not modify it while you are processing the same image.
  iterCount | Number of iterations the algorithm should make before returning the result. Note that the result can be refined with further calls with mode==GC_INIT_WITH_MASK or mode==GC_EVAL .
  mode | Operation mode that could be one of the GrabCutModes

## ◆ watershed()

void cv::watershed | ( | InputArray | image,
|  | InputOutputArray | markers )

Python:
| cv.watershed( | image, markers | ) -> | markers

`#include <opencv2/imgproc.hpp>`

Performs a marker-based image segmentation using the watershed algorithm.

The function implements one of the variants of watershed, non-parametric marker-based segmentation algorithm, described in [191] .

Before passing the image to the function, you have to roughly outline the desired regions in the image markers with positive (>0) indices. So, every region is represented as one or more connected components with the pixel values 1, 2, 3, and so on. Such markers can be retrieved from a binary mask using findContours and drawContours (see the watershed.cpp demo). The markers are "seeds" of the future image regions. All the other pixels in markers , whose relation to the outlined regions is not known and should be defined by the algorithm, should be set to 0's. In the function output, each pixel in markers is set to a value of the "seed" components or to -1 at boundaries between the regions.

Note
  Any two neighbor connected components are not necessarily separated by a watershed boundary (-1's pixels); for example, they can touch each other in the initial marker image passed to the function.

Parameters

  image | Input 8-bit 3-channel image.
  markers | Input/output 32-bit single-channel image (map) of markers. It should have the same size as image .

See also
  findContours