'How to extract text from a photo with Pytesseract and Python 3?
I know this question has been posted here several times. But it was always for some kind of captcha where the background was only one color.
My case is more complicated where the background is a photo with many stuff (people, house, garden, etc...). There is various shapes with various colors.
At least, the font color is the same for all the characters. The problem is I am a newbie in this OCR Python technology with cv2 and numpy and pytesseract.
I did test all the source code proposed here in Stackoverflow without success.
Here are some photos samples where I am trying to get the domain name and phone number of the photo.
Does anyone know the magic OCR formula for this kind of photo, please?
Solution 1:[1]
I haven't done this type of extraction, but I have tried to do something like this. Since the text color is the same across all the pictures,You will need to use thresholding to make only the text color(green) visible. However this can be achieved only if there is no green object on the picture. After filtering out the image color, so,leaving the text , you will then use pytesseract to extract the text. This is just a way I'm thinking would work, but I have actually done it before but not this exact one. The problem I faced then was choosing the right color to segment by. I think by converting this image to have color space you can implement a mouse click event to know the color you will use for thresholding
Solution 2:[2]
Tesseract is not the solution for your case. Tesseract uses something called OTSU thresholding that converts images to black and white (binarize it). You will lose data and get nothing as an output if you use Tesseract. You may try an OCR engine called PaddleOCR but keep in mind that these designs are already poor because the visibility of the text is not good at all. In general, don't expect to get fancy results for these designs.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Benedict Gab |
| Solution 2 | Esraa Abdelmaksoud |




