import cv2
import pytesseract
import numpy as np
from PIL import ImageGrab
import time


pytesseract.pytesseract.tesseract_cmd = 'C:\\Program Files\\Tesseract-OCR\\tesseract.exe'
img = cv2.imread("jon-tyson-XNVksxw_68Q-unsplash.jpg")

img = cv2.resize(img, (512, 512))
img1 = img.copy()
img = cv2.cvtColor(img, cv2.COLOR_BGR2RGB) # BGR 2 RGB 


#############################################
#### Detecting Characters  ######
#############################################
hImg, wImg,_ = img.shape
boxes = pytesseract.image_to_boxes(img)
for b in boxes.splitlines():
    b = b.split(' ') # storing box parameters into a list
    print(b)
    x, y, w, h = int(b[1]), int(b[2]), int(b[3]), int(b[4])
    cv2.rectangle(img1, (x,hImg- y), (w,hImg- h), (50, 50, 255), 2)
    cv2.putText(img1,b[0],(x,hImg- y+25),cv2.FONT_HERSHEY_SIMPLEX,1,(50,50,255),2)


cv2.imshow('img', img1)
cv2.waitKey(0)