Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

An API to just perform recognition and get confidence #286

Open
GokulNC opened this issue Jul 20, 2020 · 2 comments
Open

An API to just perform recognition and get confidence #286

GokulNC opened this issue Jul 20, 2020 · 2 comments

Comments

@GokulNC
Copy link

GokulNC commented Jul 20, 2020

By defauly, tesseract does both detection and recognition.
Is it possible to have an API for recognize() which would just perform recognition and return the output text with confidence?
Or atleast simulate it?

The pytesseract.image_to_string() call only gives the recognized text.

For image_recognize(), we could do something like this for output_type dict:

def recognize(img):
    data = pytesseract.image_to_data(img, lang=self.lang_str, output_type='dict')
    texts = []
    avg_confidence = 0
    total_bboxes = 0
    # assert len(data['text']) == 1 # Should contain only 1 bbox
    for i in range(len(data['text'])):
        text, conf = data['text'][i].strip(), float(data['conf'][i]) / 100.0
        if conf < 0 or not text:
            continue
        total_bboxes += 1
        avg_confidence += conf
        texts.append(text)
    
    if not total_bboxes:
        return {}
    return {
        'text': ' '.join(texts),
        'confidence': avg_confidence/total_bboxes
    }

Can you please take this as a feature request?
This would be helpful if someone is using their own detector and want to just perform recognition using tesseract.

@bozhodimitrov
Copy link
Collaborator

bozhodimitrov commented Jul 21, 2020

The only problem might be the fact that tesseract and pytesseract respectively support batch recognition via list of images.
So this should be considered in that use case.

@GokulNC
Copy link
Author

GokulNC commented Jul 21, 2020

Sure, even any direct solution is fine :)

A rough equivalent of only recognition seems to be passing the flag --psm 7.
Any other options?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants