Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7809931
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T03:35:32+00:00 2026-06-02T03:35:32+00:00

I am developing some image processing tools in iOS. Currently, I have a contour

  • 0

I am developing some image processing tools in iOS. Currently, I have a contour of features computed, which is of type InputArrayOfArrays.

Declared as:

std::vector<std::vector<cv::Point> > contours_final( temp_contours.size() );

Now, I would like to extract areas of the original RGB picture circled by contours and may further store sub-image as cv::Mat format. How can I do that?

Thanks in advance!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-02T03:35:34+00:00Added an answer on June 2, 2026 at 3:35 am

    I’m guessing what you want to do is just extract the regions in the the detected contours. Here is a possible solution:

    using namespace cv;
    
    int main(void)
    {
        vector<Mat> subregions;
        // contours_final is as given above in your code
        for (int i = 0; i < contours_final.size(); i++)
        {
            // Get bounding box for contour
            Rect roi = boundingRect(contours_final[i]); // This is a OpenCV function
    
            // Create a mask for each contour to mask out that region from image.
            Mat mask = Mat::zeros(image.size(), CV_8UC1);
            drawContours(mask, contours_final, i, Scalar(255), CV_FILLED); // This is a OpenCV function
    
            // At this point, mask has value of 255 for pixels within the contour and value of 0 for those not in contour.
    
            // Extract region using mask for region
            Mat contourRegion;
            Mat imageROI;
            image.copyTo(imageROI, mask); // 'image' is the image you used to compute the contours.
            contourRegion = imageROI(roi);
            // Mat maskROI = mask(roi); // Save this if you want a mask for pixels within the contour in contourRegion. 
    
            // Store contourRegion. contourRegion is a rectangular image the size of the bounding rect for the contour 
            // BUT only pixels within the contour is visible. All other pixels are set to (0,0,0).
            subregions.push_back(contourRegion);
        }
    
        return 0;
    }
    

    You might also want to consider saving the individual masks to optionally use as a alpha channel in case you want to save the subregions in a format that supports transparency (e.g. png).

    NOTE: I’m NOT extracting ALL the pixels in the bounding box for each contour, just those within the contour. Pixels that are not within the contour but in the bounding box are set to 0. The reason is that your Mat object is an array and that makes it rectangular.

    Lastly, I don’t see any reason for you to just save the pixels in the contour in a specially created data structure because you would then need to store the position for each pixel in order to recreate the image. If your concern is saving space, that would not save you much space if at all. Saving the tightest bounding box would suffice. If instead you wish to just analyze the pixels in the contour region, then save a copy of the mask for each contour so that you can use it to check which pixels are within the contour.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm currently developing a camera application for Android on which some problems have occurred.
I'm developing some image processing software in C++ on Intel which has to run
I'm currently developing some things in Python and I have a question about variables
I am developing a small application in android in which i have few image
I am currently developing some user controls so that I can use them at
I am developing some program in C# which will send the mail using outlook
I'm working with an image processing project where I'm trying to locate features on
i'm developing text ads system. Some small clone of Google Ads Updated image so
Hi Iam developing an image viewer application just like irfan-view or acdsee which should
I am developing an android application and created some image buttons(green coloured) using 'AAA

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.