I am looking for an optical character recognition (OCR) function on the display and want the program to work in different lighting conditions. To do this, I need to process the threshold image so that there is no noise around each digit, which allowed me to determine the outline of the digit and perform OCR. I need the threshold value that I use to adapt to these different lighting conditions. I tried the adaptive threshold, but I could not get it to work.
My image processing is simple: upload image (i), grayscale i (g), apply histogram alignment to g (h) and apply binary threshold to h with threshold value = t. I worked with several different data sets and found that the optimal threshold for OCR continuous operation lies in the range of maximum density on the histogram graph (h) (the only part of the graph without spaces). ![A histogram of (h). The values t = [190,220] are optimal for OCR](https://fooobar.com/https://i.imgur.com/6QWtZNA.png)
Histogram (h). The values t = [190, 220] are optimal for OCR. A more complete set of images describing my problem can be found here: http://imgur.com/a/wRgi7
My current solution, which works, but clumsily and slowly, checks:
1. There must be 3 digits 2. The first digit must be reasonably small in size 3. There must be at least one contour recognized as a digit 4. The digit must be recognized in the digit dictionary
The ban is to accept all cases, the threshold is increased by 10 (starting from a low value), and the attempt is made again.
The fact that I can determine the optimal threshold value on the histogram graph (h) may just be an offset bias, but I would like to know if there is a way to extract the value. This is different from the way I worked with histograms before, which was more on finding peaks / valleys.
I use cv2 for image processing and matplotlib.pyplot for histogram plots.
source share