# how to Ignore bounding box inside bounding box

when i draw the bounding box with centriod, i got the bounding box inside bounding box like this

Actually i want to ignore the inner bounding box in all my bounding box.

I am using below code with ignoring all circles. link

edit retag close merge delete

3

Just cross reference the corners with eachother. If the topleft corner of the smaller object has an x and y larger then topleft of the larger object AND it has an bottomright corner with an x and y value that is smaller than the x and y of the larger object, then you can simply remove the detection. Seems pretty feasible to me.

( 2014-03-31 07:33:45 -0600 )edit

Ah confused, can you provide some link or code(rough code).

( 2014-03-31 23:48:30 -0600 )edit
1

I find it very strange that you cannot solve this yourself or by the directions given. This is a basic mathematical problem... However @Haris gave you a good indication on how to solve your problem also if you do not want to do it during postprocessing!

( 2014-04-01 01:35:39 -0600 )edit

Sort by ยป oldest newest most voted

You can change findcontour() mode parameter to CV_RETR_EXTERNAL which will retrieves only the extreme outer contours, and sets hierarchy[i][2]=hierarchy[i][3]=-1 for all the contours. That is CV_RETR_EXTERNAL will exclude all child contour(contour inside contour).

And if your code need to extract all contour(including child) you can iterate through only outer contour(first hierarchy level) using below code,

for( int i = 0; i< contours.size(); i=hierarchy[i][0] ) // iterate through outer  contour exclude child

Also see this question, might be helpful.

more

Well, thanks haris for a new concept(really useful), but i use Steven code ie

int cmin= 50;
int cmax= 1000;
vector<vector<Point> >::iterator itc=contours.begin();
while (itc!=contours.end()) {
if (itc->size() < cmin || itc->size() > cmax){
itc= contours.erase(itc);}
else{
vector<Point> pts = *itc;
Mat pointsMatrix = Mat(pts);
Scalar color( 0, 255, 0 );
Rect r0= boundingRect(pointsMatrix);
rectangle(threshold_output,r0,color,2);

above sample code will solve my issue. But @Haris and @steven thanks for immediate reply & good luck

more

Official site

GitHub

Wiki

Documentation

## Stats

Asked: 2014-03-31 07:23:55 -0600

Seen: 6,446 times

Last updated: Apr 02 '14