Skip to content

Instantly share code, notes, and snippets.

@skt7
Last active March 5, 2021 15:35
Show Gist options
  • Save skt7/f98042c6c9c8bd81095fedadd322094e to your computer and use it in GitHub Desktop.
Save skt7/f98042c6c9c8bd81095fedadd322094e to your computer and use it in GitHub Desktop.
using image_to_boxes function to see how tesseract detect contours
"""
Created on Fri Apr 20 22:21:42 2018
@author: skt
"""
import pytesseract
import cv2
img = cv2.imread('HTYux.jpg')
resizeFactor = 2
img = cv2.resize(img, None, fx=resizeFactor, fy=resizeFactor)
h, w, _ = img.shape
print(pytesseract.image_to_string(img))
letters = pytesseract.image_to_boxes(img)
letters = letters.split('\n')
letters = [letter.split() for letter in letters]
for i, letter in enumerate(letters):
cv2.rectangle(img, (int(letter[1]), h - int(letter[2])), (int(letter[3]), h - int(letter[4])), (0,0,255), 1)
cv2.imshow('', img)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment