Contrast Detection - Picking the right Font color [closed]
Hello,
I hope this not off topic. For a data augmentation task (i need to generate a ocr dataset - and yes i already tried some public dataset) i want to generate text on images.
The text must still be readable. Is there some opencv algorithm which would help me deteremine the font color or areas in the picture where i can safly render the fonts?
Doing this manually take a some time for me and i want to automate this. Any ideas(no code needed) are highly welcome.
Greetings, Holger
Well i guess you just dont need a fancy algorithm to do this.
I think ill just go for that cheap solution. I am still interested if i can solve this otherwise.
Well how about this:
Maybe my question is too special or commercial. I will try this out and let you know and post what i did in the end.
Are you doing silmilar mirc colour?
I dont quite understand what this means (i did a quick google) - i am trying to generate synthetic text data on random background images so i can build a ocr / text detection dataset.
Ok so this is what i did in the end :
How to compute brightness (taken from the internet....)
So in the end it was not complicated - it just took me some time to get the right idea.
Ok - so after doing what i wrote and having some good first results - i noticed that my approach fails sometimes.
So after googling a while - i found something official from the w3c. https://www.w3.org/TR/WCAG20-TECHS/G1...
I implemented this algorithm(computing contrast ratio >= 4.5) and its finally working now. On remark:
Just dive the bigger value by the lower value! (Math.max(L1, L2) + 0.05) / (Math.min(L1, L2) + 0.05);
Finally!!!