OPENCV connected domain related operations

Source: Internet
Author: User

    1. Connected domain Inverse selection

When you use the Findcontours function of OpenCV to find a connected domain outline, you may need to use a selection counter-selection function similar to PS.

This section is described below:

In the Findcontours function, select the Cv_retr_ccomp two-level contour lookup in the mode parameter,

To construct a selection range for an inverse selection of image size

    VECTOR<CV::P oint> boundcontours (4);    boundcontours[0] = CV::P oint (00);    boundcontours[1] = CV::P oint (0, src.rows-1);    boundcontours[2] = CV::P oint (src.cols-1, src.rows-1);    boundcontours[3] = CV::P oint (src.cols-10);

intMain () {cv::mat src= Imread ("original. PNG",0); Vector&LT;VECTOR&LT;CV::P oint>>linecontours; Vector<cv::Vec4i>hierarchy;    Findcontours (SRC, linecontours, hierarchy, Cv_retr_ccomp, cv_chain_approx_simple); linecontours[0].clear (); Vector&LT;CV::P oint> boundcontours (4); boundcontours[0] = CV::P oint (0,0); boundcontours[1] = CV::P oint (0, src.rows-1); boundcontours[2] = CV::P oint (src.cols-1, src.rows-1); boundcontours[3] = CV::P oint (src.cols-1,0); linecontours[0] =boundcontours; Cv::mat temptimg (Scr.size (), Cv_8uc1,scalar (0)); Drawcontours (temptimg, Linecontours,-1, Scalar (255), -1);}

Original:

The results are as follows:

OPENCV connected domain related operations

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.