title: OpenCV Python: cv2.findContours Returns to many contours
body: <p>I'm working with a little program which will use OpenCV + python's background subtraction to count cars. I'm fine with background subtraction, I already have a background image. But when I use <code>cv2.findContours(fgmask.copy(), cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_SIMPLE)</code>, I get way too many contours. While I can do some basic filtering by checking contour area (<code>cv2.contourArea(contour)</code>), as shown in <a href="http://www.pyimagesearch.com/2015/05/25/basic-motion-detection-and-tracking-with-python-and-opencv/" rel="nofollow">http://www.pyimagesearch.com/2015/05/25/basic-motion-detection-and-tracking-with-python-and-opencv/</a>, not all cars are detected.</p>
  
  <p>I also looked at <code>cv2.groupRectangles(rectList, minNum[, eps])</code>, but I can't seem to create a vector of rectangles (By the way, that's in <a href="http://docs.opencv.org/2.4/modules/objdetect/doc/cascade_classification.html" rel="nofollow">http://docs.opencv.org/2.4/modules/objdetect/doc/cascade_classification.html</a>, last function).</p>
  
  <p>My code to find contours/draw rectangles:</p>
  
  <pre><code>contours, im2 = cv2.findContours(fgmask.copy(), cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_SIMPLE)
  for cnt in contours:
      if MAXAREA &gt;= cv2.contourArea(cnt) &gt;= MINAREA:
          rect = cv2.minAreaRect(cnt)
          points = cv2.cv.BoxPoints(rect)
          cv2.rectangle(img, (int(points[1][0]), int(points[1][1])), (int(points[3][0]), int(points[3][1])), (0, 255, 0), 2)
  </code></pre>
  
  <p>(<code>MINAREA</code> and <code>MAXAREA</code> are the maximum and minimum areas for the contour to be drawn)</p>
  
  <p><strong>My Question:</strong> How can I either group rectangles or use some criteria to draw the correct rectangles (and keep cars from not being recognized)?</p>
  
  <p>Any help is highly appreciated.</p>