How to Scan a Text From the IMAGE

 Python Project

to run from cmd


python className.py

import easyocr
import cv2
from matplotlib import pyplot as plt
import numpy as np

#gets Picture input from ScanProject (java) project
IMAGE_PATH = "//Users//Documents//NewTest//ScanProject//image1.png"
reader = easyocr.Reader(['en'],gpu=False)
result = reader.readtext(IMAGE_PATH)
print(result)

top_left = tuple(result[0][0][0])
bottom_right = tuple(result[0][0][2])
text = result[0][1]
print("The text is :"+text)


#To print the image
font = cv2.FONT_HERSHEY_SIMPLEX
img = cv2.imread(IMAGE_PATH)
img = cv2.rectangle(img,top_left,bottom_right,(0,255,0),2)
# img = cv2.putText(img,text,top_left,font,0.5,(255,0,0),1,cv2.LINE_AA)
plt.figure(figsize=(10,10))
plt.imshow(img)
plt.show()


# To show details on multiple text
# img = cv2.imread(IMAGE_PATH)
# for detection in result:
# top_right = tuple([int(val) for val in detection[0][0]])
# bottom_right = tuple([int(val) for val in detection[0][2]])
# text = detection[1]
# img = cv2.rectangle(img, top_left, bottom_right,(0,255,0),5)
# img = cv2.putText(img,text,top_left,font,0.2,(255,0,0),0.5,cv2.LINE_AA)
# plt.figure(figsize=(100,50))
# plt.imshow(img)
# plt.show()


Comments

Popular posts from this blog

The self healing automation framework - Healenium Updated Dec2023

Heleanium - Web without using Docker