White Text instead of Black, green background, how to improve image to string accuracy?

Viewed 31

I'm trying to improve the accuracy of my image to string code, however, the background is constantly changing, from either a darker blue background to a green background while the text remains constantly white. Unfortunately most questions I've found on StackOverflow were all with black text instead of white so most preprocessing I've seen doesn't really work since the text I wish to withdraw is white, not black.

Image: text to withdraw in white

I've tried:

gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
txt = pytesseract.image_to_string(gray,config ='--psm 6')

However, the results are mediocre at best, it more often than not gets it wrong.

1 Answers

Just select the red or blue channel. That's because that distracting background is pure green, i.e. it's dark in the other channels.

Since you say your picture's background varies between green and blue, I'd recommend the red channel then.

blue_channel = im[:, :, 0]

blue channel

Related