title: What causes pytesseract to read either the top or bottom text-line of a dual-line image depending on whether opencv or pillow is used?
body: <p><strong>EDIT:</strong> I forgot to process the image which solves the reading issue, thanks to Nathancy. Still wondering what makes Tesseract read only the top OR the bottom line of an unprocessed image (same image, two different outcomes)</p>
  
  <p><strong>Orignal:</strong><br>
  I have an image that contains two lines of text:
  <a href="https://i.stack.imgur.com/Hf9jd.png" rel="nofollow noreferrer">random test image for pytesseract</a>
  <br><br>When I open the image within python (IDLE Python 3.6) with PIL Image and use pytesseract to extract a string, it only extracts the last/bottom line correctly. The upper line of text is scrambled garbage.(see code section below)<br>However, when I use opencv to open the image and use pytesseract to extract a string, it only extracts the top/upper line correctly whilst making a mess of the second/bottom line of text.(see also code section below)
  <br><br>Here is the code:<br></p>
  
  <pre><code>&gt;&gt;&gt; from PIL import Image, ImageFilter
  &gt;&gt;&gt; import pytesseract
  &gt;&gt;&gt; pytesseract.pytesseract.tesseract_cmd = r"C:\Program Files\Tesseract-OCR\tesseract.exe"
  &gt;&gt;&gt; import cv2
  
  &gt;&gt;&gt; img = Image.open(r"C:\Users\user\MyImage.png")
  &gt;&gt;&gt; img2 = cv2.imread(r"C:\Users\user\MyImage.png", cv2.IMREAD_COLOR)
  
  
  &gt;&gt;&gt; print(pytesseract.image_to_string(img2))
  Pet Sock has 448/600 HP left
  A ae eee PER eats ae
  
  &gt;&gt;&gt; print(pytesseract.image_to_string(img))
  Le TL
  JHE has 329/350 HP left.
  </code></pre>
  
  <p>When I use <code>pytesseract.image_to_boxes</code> on both <code>img</code> and <code>img2</code> it will show the same bounding box for certain locations with a different letter (only showing 2 extracted lines which contain an identical box)</p>
  
  <pre><code>&gt;&gt;&gt; print(pytesseract.image_to_boxes(img2))
  A 4 6 10 16 0
  
  &gt;&gt;&gt; print(pytesseract.image_to_boxes(img))
  J 4 6 10 16 0
  </code></pre>
  
  <p>When I use the <code>pytesseract.image_to_data</code> on both <code>img</code> and <code>img2</code> it shows very high (95+) confidence on the line it reads correctly and very low (30-) on the garbled line.<br><a href="https://i.stack.imgur.com/SJ057.png" rel="nofollow noreferrer">Excel table output of image_to_data</a> <br><em>edit: excel tables are img2 and img accordingly</em>
  <br><br> I fiddled around with the psm config values (I have tried them all) and except for creating more garbage on settings: 5, 7, 8, 9, 10, 13; and some giving an error: 0, 2; it gave no different results than the default (which is 3 I believe)<br><br>
  I must be making some rookie mistake but I can't get my head around why this is happening. If anyone can shine a light in the right direction it would be awesome.
  <br><br><em>The image was just a fitting, but random, image for an OCR test that I had laying around. No further intentions than experimenting with pytesseract.</em></p>