White text on blue, green background. different result

103 views
Skip to first unread message

L ht

unread,
Oct 2, 2024, 1:35:46 AM10/2/24
to tesseract-ocr

Hi, 

I cropped two buttons from a screenshot. The images contain white text on blue or green backgrounds, but I’m getting different results.
Using Ubuntu Tesseract 5.4.0 with the following commands:
tesseract detected.png - return "SIGNIN WITH FACEBOOK"
tesseract undetected.png -  return empty string

Can anyone explain why this is happening and how to detect both? Thanks.



detected.png
notDetected.png

Zdenko Podobny

unread,
Oct 5, 2024, 2:05:48 PM10/5/24
to tesser...@googlegroups.com
Did you read the tesseract documentation (before asking the forum)?

Zdenko


st 2. 10. 2024 o 7:35 L ht <lhta...@gmail.com> napísal(a):
--
You received this message because you are subscribed to the Google Groups "tesseract-ocr" group.
To unsubscribe from this group and stop receiving emails from it, send an email to tesseract-oc...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/tesseract-ocr/afe1dc25-cebc-43c9-94bc-dcabe6d43c52n%40googlegroups.com.

L ht

unread,
Oct 5, 2024, 2:32:32 PM10/5/24
to tesser...@googlegroups.com

Zdenko Podobny

unread,
Oct 6, 2024, 8:39:46 AM10/6/24
to tesser...@googlegroups.com
Great!  So you know what preprocessing steps you need to take to get correct results.

>tesseract improved.png - --psm 7
SIGNIN


Zdenko


so 5. 10. 2024 o 20:32 L ht <lhta...@gmail.com> napísal(a):

L ht

unread,
Oct 7, 2024, 2:48:06 PM10/7/24
to tesser...@googlegroups.com
Hi Zdenko, 
Thanks
I managed to get the OCR result by cropping out all the white edges from the "SIGN IN" image. Interestingly, I didn’t need to crop the white edges from the "SIGN IN WITH FACEBOOK" image to achieve a successful result. Although both images appear quite similar—white text on a dark background, with some white edges—the results differed between them. Could you please provide more details about how you handled this, so I can better manage similar cases in the future?  

detected_signin.png

Zdenko Podobny

unread,
Oct 11, 2024, 5:59:53 AM10/11/24
to tesser...@googlegroups.com
Hi,

I guess the problem is:
  • the word is short 
  • surrounded by graphics elements (button). 
tesseract does a little image preprocessing (a user is responsible for preprocessing ;-) ) e.g. converting image to binary image(black&white) and it tries to ignore pictures in the provided image... 

Based on your images: you can remove a button with the following Python code:

import cv2
import numpy as np

img = cv2.imread('Images/notDetected.png', cv2.IMREAD_GRAYSCALE)
_, im_th = cv2.threshold(img, 200, 255, cv2.THRESH_BINARY_INV)
im_floodfill = im_th.copy()
h, w = im_th.shape[:2]
mask = np.zeros((h+2, w+2), np.uint8)
cv2.floodFill(im_floodfill, mask, (0, 0), (255, 255, 255))
cv2.imwrite('improved.png', im_floodfill)




Zdenko


po 7. 10. 2024 o 20:47 L ht <lhta...@gmail.com> napísal(a):
Reply all
Reply to author
Forward
0 new messages