Get the App
SLTechnology News&Howtos  ›  Internet Technology  › 

How to use OpenCV to realize Image Segmentation in C++

Shulou Source: shulou.com Published: 2022-06-02 08:08:53 09月29日 Update

This article will explain in detail how to use OpenCV to achieve image segmentation in C++. The content of the article is of high quality, so the editor shares it for you as a reference. I hope you will have a certain understanding of the relevant knowledge after reading this article.

Parameter description:

Img: input ima

Result: segmentation result

The values for mask images can only be the following four values (PR,probably indicates possible):

GC_BGD = 0, / / background

GC_FGD = 1, / / Prospect

GC_PR_BGD = 2, / / possible background

GC_PR_FGD = 3 / / possible prospect

Rect: a rectangle containing the foreground

BgdModel: background

FgdModel: prospect

IterCount: iterations, which must be greater than 0

Mode: used to instruct grabcut what function to use to operate

GC_INIT_WITH_RECT / / initialized with a rectangular box

GC_INIT_WITH_MASK / / initialize with mask image

GC_EVAL / / perform split

Code demonstration

We used the project opencv--Grabcut of the mouse callback event from last class.

The basic parameters and methods used in GrabCut are defined.

Initialize mask, set as background

Then set the N key to segment the GrabCut image.

The initialization of two parameters is added to the mouse press event.

Redefine Mask in the mouse release event

Initialize the method setROIMask of Mask

Execute the GrabCut method

Display image method modification

On C++ on how to use OpenCV to achieve image segmentation to share here, I hope the above content can be of some help to you, can learn more knowledge. If you think the article is good, you can share it for more people to see.

Tags: Image foreground method background event parameter mouse Clippers content article more knowledge rectangle article yes two code function indication display diagram Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Shulou Tech Info OPPO Reno MariaDB macOS Huawei