title: How to extract individual letters from image with PyTesseract?
body: <p>I am teaching myself python and am trying to make a simple program to recognize letters from an image. The letters are not in sentence or paragraph form. I am trying to do this using cv2 + pytesseract for detection, but I just can't seem to get it to work reliably. I am beginning to suspect I am using the wrong tool for the job but I can't find anything else to help me.</p>
  
  <p>This is my reference image with the letters I want to extract:</p>
  
  <p><a href="https://i.stack.imgur.com/xO6JI.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/xO6JI.png" alt="enter image description here"></a></p>
  
  <p>Ideally I would like the letter and also the coordinates of each letter (bounding box). I've been able to apply a mask and threshold to the image to get this:</p>
  
  <p><a href="https://i.stack.imgur.com/IitbJ.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/IitbJ.png" alt="enter image description here"></a></p>
  
  <p>But what I am stuck on is Pytesseract being unable to reliably give me the letters individually or even correctly. Here is my console output...</p>
  
  <pre><code>$ py main.py --image test.png
  D
  C UL
  UO
  </code></pre>
  
  <p>The code I am using is simply taking the black and white text image and running it through pytesseract. I've tried playing around with the <code>--psm</code> flag but because the text is in an odd shape, I haven't had much luck.</p>
  
  <pre><code>text = pytesseract.image_to_string(Image.open(filename), config='-l eng --psm 11')
  os.remove(filename)
  print(text)
  </code></pre>