title: Adjust image using opencv for tesseract
body: <p>I'm trying to get 3 numbers contained in some dynamically generated images using <a href="https://pypi.org/project/pytesseract/" rel="nofollow noreferrer">pytesseract</a> and <a href="https://pypi.org/project/opencv-python/" rel="nofollow noreferrer">opencv</a>, some of these images I get the correct numbers, others I can't get any number, or just 1 or 2, the biggest difference between correct and wrong images is the vertical alignment, I already tried to increase the image size, or cut the numbers, and try 1 by 1, all the images are readable.</p>
  <p><strong>images processed correctly</strong>:</p>
  <p><a href="https://i.stack.imgur.com/WejPy.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/WejPy.png" alt="ok" /></a> <a href="https://i.stack.imgur.com/Xa24z.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/Xa24z.png" alt="ok" /></a> <a href="https://i.stack.imgur.com/gmB4D.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/gmB4D.png" alt="ok" /></a> <a href="https://i.stack.imgur.com/P2i5s.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/P2i5s.png" alt="ok" /></a> <a href="https://i.stack.imgur.com/tq4Ra.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/tq4Ra.png" alt="ok" /></a></p>
  <p><strong>unprocessed or wrong images</strong>:</p>
  <p><a href="https://i.stack.imgur.com/H6O1M.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/H6O1M.png" alt="err" /></a> <a href="https://i.stack.imgur.com/igQt9.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/igQt9.png" alt="err" /></a> <a href="https://i.stack.imgur.com/nVecL.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/nVecL.png" alt="err" /></a> <a href="https://i.stack.imgur.com/6jXBq.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/6jXBq.png" alt="err" /></a> <a href="https://i.stack.imgur.com/SbVnf.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/SbVnf.png" alt="err" /></a></p>
  <p>The only correction I'm making to the original image is:</p>
  <pre><code>cv2.medianBlur(image, 3)
  </code></pre>
  <p>this improved edges and assertiveness.</p>
  <p>I'm using the following settings for tesseract:</p>
  <pre><code>txt = image_to_string(img, config='--psm 3 --oem 1 -c tessedit_char_whitelist=0123456789')
  </code></pre>
  <p>I don't have much knowledge with opencv, and what I found information was not enough to solve the problem, if anyone can give me a tip on how to improve the images for the correct return of the tesseract.
  thanks in advance!</p>