tesserocr icon indicating copy to clipboard operation
tesserocr copied to clipboard

About the bounding box of text

Open Littlew69 opened this issue 1 year ago • 1 comments

I need the bounding box of detected texts. However, because the detected text may not be a complete sentence, I wish the bounding box could be loose. What can I do? Belows are my code. `box_list = [] ocrResult_list = [] conf_list = []

with PyTessBaseAPI() as api:
    api.SetImage(image)
    boxes = api.GetComponentImages(RIL.TEXTLINE, True)
    # print("boxes\n", boxes)
    # print('Found {} textline image components.'.format(len(boxes)))
    for i, (im, box, _, _) in enumerate(boxes):
        # im is a PIL image object
        # box is a dict with x, y, w and h keys
        api.SetRectangle(box['x'], box['y'], box['w'], box['h'])
        ocrResult = api.GetUTF8Text()
        conf = api.MeanTextConf()
        box_list.append(box)
        ocrResult_list.append(ocrResult[0:-1])
        conf_list.append(conf)
        # print(u"Box[{0}]: x={x}, y={y}, w={w}, h={h}, "
        #       "confidence: {1}, text: {2}".format(i, conf, ocrResult, **box))`

Littlew69 avatar Nov 01 '24 03:11 Littlew69

Can you provide example (image and expected output) for better clarity of you expectation?

zdenop avatar Aug 10 '25 15:08 zdenop