I have let's say the following image:
I've figured out how to get each line using EASYOCR. However, I want to know what color is of the text. I've tried to apply a threshold and use bitmasking, but what would I do if the background color is of anything other color than white?
CodePudding user response:
I came across this problem almost 2 years ago and here's what I did to solve the issue.
I used kmeans on image to cluster it into k = 2
clusters. The output would be 2 most prominent clusters namely the background and the foreground. You can convert this into a binary image by using open-cv
binary thresholding. Now at this point you don't know which one is foreground and which one is background, so you use pixel count on the binary image. In my case the background always had more pixels so that was really easy to distinguish the text (foreground) from the background.
With this method, it doesn't matter which color is the background and which color is the foreground text, it also doesn't matter if you have minor noise cause it would cope up with it.
This technique solved it entirely for me, I hope it does the same for you or at least give you some leads.