title: Tesseract OCR image recognition failed because of `Warning: Invalid resolution` error
body: <p>I tried to detect text from an image where I draw bounding boxes around select characters and stitch them together to form another image as below : </p>
  
  <p><a href="https://i.stack.imgur.com/iraUG.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/iraUG.jpg" alt="The final stitched image"></a></p>
  
  <p>I used cv2 to draw bounding boxes around the characters using the following code : </p>
  
  <pre><code>cnts = cv2.findContours(inverted, cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_SIMPLE)
  cnts = cnts[0] if len(cnts) == 2 else cnts[1]
  (cnts, bounding_boxes) = sort_contours(cnts)
  ROI_number = 0
  for c in cnts:
      x, y, w, h = cv2.boundingRect(c)
      ROI = inverted[y:y + h, x:x + w]
      # ROI = cv2.erode(ROI, kernel, iterations=1)
      ROI = cv2.filter2D(ROI, -1, sharpen_kernel)
      # ROI = cv2.GaussianBlur(ROI, (5, 5), 0)
      # ROI = cv2.filter2D(ROI, -100, sharpen_kernel)
      ROI = cv2.bitwise_not(ROI)
      ht, wd = ROI.shape
      ww = 26
      hh = 30
      result = np.full((hh, ww), 255, dtype=np.uint8)
      xx = (ww - wd) // 2
      yy = (hh - ht) // 2
      result[yy:yy + ht, xx:xx + wd] = ROI
      cv2.imwrite('ROI_{}.jpeg'.format(ROI_number), result)
      cv2.rectangle(inverted, (x, y), (x + w, y + h), (36, 255, 12), 0)
      ROI_number += 1
  </code></pre>
  
  <p>I have used <strong>hstack from numpy</strong> to stitch the image together using the following code:</p>
  
  <pre><code>def stitch_images(input_path):
  imagePaths = []
  for image_path in glob.glob(os.path.join(input_path, '*.jpeg')):
      imagePaths.append(image_path)
  sorted_paths = sorted(imagePaths)
  list_im = [sorted_paths[0], sorted_paths[1], sorted_paths[2], sorted_paths[3], sorted_paths[4], sorted_paths[5]]
  imgs = [Image.open(i) for i in list_im]
  min_shape = sorted([(np.sum(i.size), i.size) for i in imgs])[0][1]
  imgs_comb = np.hstack((np.asarray(i.resize(min_shape)) for i in imgs))
  imgs_comb = Image.fromarray(imgs_comb)
  imgs_comb.save('stitched.jpeg')
  </code></pre>
  
  <p>The stitched image however cannot be read using tesseract and gives the following error:</p>
  
  <pre><code>Tesseract Open Source OCR Engine v4.1.1-rc2-21-gf4ef with Leptonica
  Warning: Invalid resolution 0 dpi. Using 70 instead.
  Estimating resolution as 334
  Empty page!!
  Estimating resolution as 334
  Empty page!
  </code></pre>