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 6613067
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T20:10:27+00:00 2026-05-25T20:10:27+00:00

The minimum bounding rectangle of a contour is returned by OpenCv as a CvRect

  • 0

The minimum bounding rectangle of a contour is returned by OpenCv as a CvRect structure. I’m trying to have an m pixel thick margin/border around the sub-image that corresponds to this CvRect on the original image, i.e. instead of the exact bounding rectangle of a component(contour) we get something larger containing the component and also its immediately surrounding pixels.

Taking care of the image bounds, I’m using the following code to increase size of the CvRect which is later applied with CvSetImageROI() to get the sub-image:

//making m px border around subimg
CvRect box_swt = box1;
box_swt.x = (box1.x)>m ? box1.x-m : box1.x;
box_swt.y = (box1.y)>m ? box1.y-m : box1.y;
box_swt.width = (box1.x + box1.width) < img->width-m ? box1.width+m : box1.width;
box_swt.height = (box1.y + box1.height) < img->height-m ? box1.height+m : box1.height;

Here, box1 stores the return from cvBoundingRect(ptr, 0) where ptr is a pointer to detected contours.

The problem is that the resulting sub-image is larger only in the upper and left borders, the others remain unchanged. I’m not getting a sub-image with a uniform m pixel thick border around all its sides. This happens for all cases, not just for those on the boundary. Is there any logical error?

  • 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-05-25T20:10:27+00:00Added an answer on May 25, 2026 at 8:10 pm

    When you are modifying the x and y of the rectangle you are not increasing it’s size, just moving it, and then you increase the width and the height by just m. I think what you want is to increase it by 2m to have the desired effect.

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

Sidebar

Related Questions

I am trying to convert a Minimum Bounding Rectangle from double values to float
The cvBoundingRect() function can return the minimum bounding rectangle when I pass it a
Context: I'm trying to clip a topographic map into the minimum-size ellipse around a
Given a list of coordinates, how do I calculate the minimum bounding rectangle (MBR),
I have complex polygons which I know the minimum x, minimum y, maximum x
If I have a minimum salary field and a maximum salary field saved on
I want Minimum and Maximum Latitude and Longitude Using Current Location.Suppose i have give
I generated this Minimum Spanning Tree using Kruskal algorithm and I have a hard
I have generated a minimum spanning tree using Kruskal's algorithm and I wanted to
If I have minimum 2 classes. One class creates the Bitmap and the other

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.