title: How to find number from image in OCR?
body: <p>I'm trying to get the number contours from an image. 
  Original image is in number_img:</p>
  
  <p><a href="https://i.stack.imgur.com/DSYEW.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/DSYEW.png" alt="enter image description here"></a></p>
  
  <p>After I've used the following code:</p>
  
  <pre><code>gray = cv2.cvtColor(number_img, cv2.COLOR_BGR2GRAY)
  blur = cv2.GaussianBlur(gray, (1, 1), 0)
  ret, thresh = cv2.threshold(blur, 70, 255, cv2.THRESH_BINARY_INV)
  
  img2, contours, _ = cv2.findContours(thresh, cv2.RETR_TREE, cv2.CHAIN_APPROX_SIMPLE)
  
  for c in contours:
      area = cv2.contourArea(c)
      [x, y, w, h] = cv2.boundingRect(c)
  
      if (area &gt; 50 and area &lt; 1000):
          [x, y, w, h] = cv2.boundingRect(c)
          cv2.rectangle(number_img, (x, y), (x + w, y + h), (0, 0, 255), 2)
  </code></pre>
  
  <p><a href="https://i.stack.imgur.com/8lb0D.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/8lb0D.png" alt="enter image description here"></a></p>
  
  <p>Since there are small boxes in between, I tried to limit with height:</p>
  
  <pre><code>if (area &gt; 50 and area &lt; 1000) and h &gt; 50:
      [x, y, w, h] = cv2.boundingRect(c)
      cv2.rectangle(number_img, (x, y), (x + w, y + h), (0, 0, 255), 2)
  </code></pre>
  
  <p><a href="https://i.stack.imgur.com/gyC8N.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/gyC8N.png" alt="enter image description here"></a></p>
  
  <p>What other ways should I do to get the best contours of number to do OCR?</p>
  
  <p>Thanks.</p>