Ask Your Question
0

Removing certain pixels with threshold

asked 2015-08-01 14:17:00 -0600

active92 gravatar image

updated 2015-08-01 17:44:13 -0600

For example, there are 9 region of interest. I need to remove those that are bigger than 1000 and smaller than 65. What is the best way to do it? I was using this method but it is not working.

image description

edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted
3

answered 2015-08-01 14:30:54 -0600

updated 2015-08-01 14:53:30 -0600

The following code snippet works here

// This vector contains your original data
// The second one will contain the selected ones
vector<Rect> contours, filtered;
// Now apply the thresholding
for(size_t i=0; i<contours.size(); i++){
   double area = contourArea(contours[i]);
   if( if( (area > 65.0) && (area < 1000.0))  ){
      filtered.push_back(contours[i]);
   }
}

My guess is that your are incorrectly using the erase function.

edit flag offensive delete link more

Comments

Shouldn't it be if( (area > 65.0) && (area < 1000.0))? (he wants to remove smaller than 65 and bigger than 1000). Anyway, the error is indeed in the erase function, as it resizes the vector in every call.

LorenaGdL gravatar imageLorenaGdL ( 2015-08-01 14:43:05 -0600 )edit

@Lorena GdL: oh i indeed forgot that he wanted to remove those :D

StevenPuttemans gravatar imageStevenPuttemans ( 2015-08-01 14:53:07 -0600 )edit

Question Tools

1 follower

Stats

Asked: 2015-08-01 14:17:00 -0600

Seen: 578 times

Last updated: Aug 01 '15