title: Remove bounding rect with an area < n OpenCV
body: <p>I am eroding an image with text blocks on it then using <code>findContours()</code> to find all of the text blocks, then drawing their bounding rect. However sometimes there are very small rects created by noise in the image which either are in a bigger rect or in a place where there is no text. </p>
  
  <p>I am using this code to find the contours and draw them.</p>
  
  <pre><code>double element_size = 20;
  RNG rng(12345);
  Mat element = getStructuringElement( cv::MORPH_ELLIPSE,cv::Size( 2*element_size + 1, 2*element_size+1 ),cv::Point( element_size, element_size ) );
  erode(quad, quad, element);
  vector&lt;vector&lt;cv::Point&gt; &gt; contours;
  vector&lt;Vec4i&gt; hierarchy;
  quad.convertTo(quad, CV_8UC1);
  findContours( quad, contours, hierarchy, CV_RETR_TREE, CV_CHAIN_APPROX_SIMPLE, cv::Point(0, 0) );
  
  vector&lt;vector&lt;cv::Point&gt; &gt; contours_poly( contours.size() );
  vector&lt;cv::Rect&gt; boundRect( contours.size() );
  
  for( int i = 0; i &lt; contours.size(); i++ )
  {
      approxPolyDP( Mat(contours[i]), contours_poly[i], 3, true );
      boundRect[i] = boundingRect( Mat(contours_poly[i]) );
  }
  
  Mat drawing = Mat::zeros( quad.size(), CV_8UC3 );
  for( int i = 0; i&lt; contours.size(); i++ )
  {
      Scalar color = Scalar(0,255, 0 );
      rectangle( drawing, boundRect[i].tl(), boundRect[i].br(), color, 2, 8, 0 );
  }
  </code></pre>
  
  <p>After a sample run here is what I get back:</p>
  
  <p><img src="https://i.stack.imgur.com/gOQRm.jpg" alt="enter image description here"></p>
  
  <p>How can I modify my code so that I can remove any rects that are not greater than <code>n</code> so I can only keep complete text blocks, I also need to remove the largest contour which surrounds the entire card.</p>