How to get contour on specific text on a image using EasyOCR in python

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:
       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)

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.

No, you are not using OpenCV to get the contours. You are using EasyOCR for that.

i have made the changes

this requires working with EasyOCR APIs.

you could split the string and guess the bounding boxes.

in any case, it’s not a problem with OpenCV.


(always declare crossposting and link to your crossposts)