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

  • SEARCH
  • Home
  • 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 8075339
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T14:57:28+00:00 2026-06-05T14:57:28+00:00

I have a question about how to define a ROI with OpenCV. I know

  • 0

I have a question about how to define a ROI with OpenCV. I know what the definition of the function cvSetImageROI but I want to know if is possible to define a ROI with OpenCV with a different shape than rectangle. For example, define a ROI in a circle or in different form.

It is possible to do this?

cvSetImageROI(img1, cvRect(a, b, c, d));

  • 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-05T14:57:29+00:00Added an answer on June 5, 2026 at 2:57 pm

    The following code, which you could have found here or even here sets a circular ROI using a bit mask on your image.

    #include "cv.h"
    #include "highgui.h"
    
    int main(int argc, char** argv)
    {
        IplImage* src, * res, * roi;
    
        /* usage: <prog_name> <image> */
        if (argc < 2)
        {
            fprintf(stderr, "Usage: %s <image>\n", argv[0]);
            return 1;
        }
    
        src = cvLoadImage(argv[1], 1);
        res = cvCreateImage(cvGetSize(src), 8, 3);
        roi = cvCreateImage(cvGetSize(src), 8, 1);
    
        /* prepare the 'ROI' image */
        cvZero(roi);
    
        /* Note that you can use any shape for the ROI */
        cvCircle(
            roi,
            cvPoint(130, 100),
            50,
            CV_RGB(255, 255, 255),
            -1, 8, 0
        );
    
        /* extract subimage */
        cvAnd(src, src, res, roi);
    
        /*
         * do the main processing with subimage here.
         * in this example, we simply invert the subimage
         */
        cvNot(res, res);
    
        /* 'restore' subimage */
        IplImage* roi_C3 = cvCreateImage(cvGetSize(src), 8, 3);
        cvMerge(roi, roi, roi, NULL, roi_C3);
        cvAnd(res, roi_C3, res, NULL);
    
        /* merge subimage with original image */
        cvNot(roi, roi);
        cvAdd(src, res, res, roi);
    
        /* show result */
        cvNamedWindow(argv[1], 1);
        cvNamedWindow("res", 1);
        cvShowImage(argv[1], src);
        cvShowImage("res", res);
    
        cvWaitKey(0);
    
        /* be tidy */
        cvDestroyAllWindows();
        cvReleaseImage(&src);
        cvReleaseImage(&res);
        cvReleaseImage(&roi);
    
        return 0;
    }
    

    For a pentagon or hexagon just adapt it so to change the geometric shape of the mask. Check this SO Question: Using ROI in OpenCV?.

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

Sidebar

Related Questions

I have a question about how to define the callback for trackbars in OpenCV
I have a question about Java Generics. If I define a class like this:
I have a question about how I define the entries when I work with
I have found this question about the special function or in scheme: Joe Hacker
I have a question about the BPMN notation. Does anybody know if interrupting/non-interrumpting events
I have a question about the: Record and Definition I have this definition: Definition
I have a basic question about MPI programming in C. Essentially what I want
I have question about normalization. Suppose I have an applications dealing with songs. First
I have question about interpreting strings as packed binary data in C++. In python,
i have question about YAJLiOS parser... I have next json data : {{ body

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.