Ask Your Question
1

Remove contours/bounding rect with an area < n

asked Apr 9 '14

Luek gravatar image

updated Oct 23 '0

How can I iterate through a list of contours and remove any contours that don't have an area of at least n?

if contour(i).area < 500 {
    contour.remove(i)
}
Preview: (hide)

1 answer

Sort by » oldest newest most voted
2

answered Apr 9 '14

Haris gravatar image

updated Apr 9 '14

Suppose you already found contours,

Then using the code,

 double min_area=500; // area threshold
 for( int i = 0; i< contours.size(); i++ ) // iterate through each contour.
 {
   double area=contourArea( contours[i],false);  //  Find the area of contour
   if(area<min_area)
    contours.erase(contours.begin() + i);
 }

you can iterate through contours and remove. I hope it will work.

Preview: (hide)

Comments

how can I do it with 2 threshold? i tried using || at the if and it stops working.

active92 gravatar imageactive92 (Aug 1 '15)edit

Question Tools

Stats

Asked: Apr 9 '14

Seen: 6,751 times

Last updated: Apr 08 '14