Ask Your Question
0

Remove contours/bounding rect with an area < n

asked 2014-04-08 20:08:36 -0500

Luek gravatar image

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)
}
edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted
1

answered 2014-04-08 22:09:22 -0500

Haris gravatar image

updated 2014-04-08 23:39:52 -0500

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.

edit flag offensive delete link more

Comments

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

active92 gravatar imageactive92 ( 2015-08-01 14:01:47 -0500 )edit
Login/Signup to Answer

Question Tools

Stats

Asked: 2014-04-08 20:08:36 -0500

Seen: 4,078 times

Last updated: Apr 08 '14