I am using Easyocr to get the contours of specific text from the image.
Input image:
my code:
image = cv2.imread(img_path+'\\'+str(img))
reader = Reader(['en'])
results = reader.readtext(image)
word = 'Varanasi'
for (bbox, text, prob) in results:
if len(nltk.word_tokenize(text)) > 5:
pass
else:
if word in text:
# unpack the bounding box
(tl, tr, br, bl) = bbox
tl = (int(tl[0]), int(tl[1]))
tr = (int(tr[0]), int(tr[1]))
br = (int(br[0]), int(br[1]))
bl = (int(bl[0]), int(bl[1]))
# cleanup the text and draw the box surrounding the text along
# with the OCR'd text itself
# text = cleanup_text(text)
cv2.rectangle(image, tl, br, (0, 255, 0), 2)
cv2.putText(image, text, (tl[0], tl[1] - 10),
cv2.FONT_HERSHEY_SIMPLEX, 0.7, (0, 255, 0), 2)
else:
pass
I want to get the contour area only on ‘Varanasi’. Is there any way to adjust the space between two consecutive text or what can i do to get this done.