How to recognize the text a certain color?

There is a picture: 5dcaf7f00c414115205264.jpeg
Need to get only the text. The text is black, grey or dark-grey colour, my idea is that want to use opencv to process the image to "remove" those parts which do not fall into the range of "gray-black", and then run the converted image through the text recognition algorithm. I want to ask two questions: 1) I Know that cv2 has a method inRange, which you can pass a range of colors, but do not know how to specify those colors (grey, dark grey) that I need. 2) Prompt, what generally it is better to use the approach of pre-processing? I am sure there are options better than mine.
April 1st 20 at 17:15
1 answer
April 1st 20 at 17:17
Solution
You can still binarysignal and then delete the too large items.
In the same imagemagick it is simple.
convert 5d.jpeg -threshold 80% black.tif
convert black.tif -negate -define connected-components:area-threshold=1000 -define connected-components:mean-color=true -connected-components 8 out.tif
convert black.tif out.tif -compose Lighten -composite out3.png

5dd10d2448f12180747509.png - Barry_Skil commented on April 1st 20 at 17:20
@Barry_Skil, wow, thank you so much!!! - ryder.Bayer commented on April 1st 20 at 17:23
@Barry_Skil, please tell me how to do this part
"Convert to HSB space. The channel's binarysoul and use as a mask for the original image to black and white only gray items."
? - ryder.Bayer commented on April 1st 20 at 17:26
@ryder.Bayer,
convert 5d.jpeg -colorspace HSV -separate separate_HSV_%d.tif
 convert separate_HSV_1.tif -blur 3x3 -threshold 10% S. tif
convert separate_HSV_2.S. tif tif -compose Lighten -composite out.tif
- Barry_Skil commented on April 1st 20 at 17:29
@Barry_Skil, thank you very much - ryder.Bayer commented on April 1st 20 at 17:32
@Barry_Skil,convert 5d.jpeg -threshold 80% black.tif
after this command generates 3 images: 1 and 3 all white, 2 all black.
5dd2ad1209582393790017.png - ryder.Bayer commented on April 1st 20 at 17:35
@ryder.Bayer, it is possible that 1.png with transparency, or index colors and imagemagick incorrectly handled it. Try with a jpg version.
Or the version of imagemagick is different, I think, earlier instead of 80% it was necessary to write 20%.
In General, experiment with the percentage that would be black.tif was not pure white. - Barry_Skil commented on April 1st 20 at 17:38
@Barry_Skil, with interest, experimented, GENERALLY does not respond(even if you put 0% or 100% - the result is the same), formats too have tried to change doesn't help. Tell me what's the version of imagemagick? - ryder.Bayer commented on April 1st 20 at 17:41
@ryder.Bayer, throw on file sharing 1.png, try.

Version: ImageMagick 6.9.10-11 Q16 x86_64 2018-09-08
cygwin64 - Barry_Skil commented on April 1st 20 at 17:44
@Barry_Skil,
Tried several versions, from version to version really the result of different, but still did not work as you have. Now with your version I'll try. - ryder.Bayer commented on April 1st 20 at 17:47
@Barry_Skil, https://dropmefiles.com/oFdAo - ryder.Bayer commented on April 1st 20 at 17:50
@ryder.Bayer,
You can try first remove the alpha channel
convert 1.png -background white-alpha remove-alpha off 1.png

With alpha channel and without it all works. black.tif - black-and-white picture. - Barry_Skil commented on April 1st 20 at 17:53
@Barry_Skil, in General, does not want to work, and now writes an error "too many objects in "the name of the image"'. Tried another method which you offered me, something happened. Tell me more please
5dd2cb7e77917053135907.jpeg
How to fill white (clean in General) the selected area? - ryder.Bayer commented on April 1st 20 at 17:56
@Barry_Skil, is a function chopImage, but how to use it in the console version could not naguglit. - ryder.Bayer commented on April 1st 20 at 17:59
@ryder.Bayer,
you can know the coordinates just to paint a rectangular region
convert 1.png -fill white-draw "rectangle 20,10 80,50" 2.png
- Barry_Skil commented on April 1st 20 at 18:02
@Barry_Skil, that's it, thank you very much! - ryder.Bayer commented on April 1st 20 at 18:05

Find more questions by tags TesseractOpenCVNeural networksPython