📜 ⬆️ ⬇️

Recognition of numbers by 4 points

I want to share how I implemented digit recognition without using Delphi OCR libraries. It was necessary to quickly and accurately pull the number out of a rectangle measuring 70 by 10 pixels.

An example of the original image in the approximation of 1600%


The first step is to convert the original image to black and white.
I ran over each pixel and compared its color with the “standard”, if more then we transform into white, otherwise into black.


Thus, hands selected patterns (samples) of all numbers. Each digit has a size of 7 by 10 pixels.

')
Next, we divide each digit into a sequence of zeros and ones. Where 0 is white, 1 is black. For example, for zero


Thus, moving from left to right from top to bottom, we obtain a sequence for each digit:
0: '0011100011011011000111100011110001111000111100011110001111101100111100'
1: '0011000111100000110000011000001100000110000011000001100000110001111110'
2: '0111100111111000001100000110000011000011000011000011000011111101111111'
3: '0111100110111000001100000110011110001111100000110000011100001101111110'
4: '0000110000111000111100110110010011011001101111111111111100001100000110'
5: '1111100111110010000001000000111100000111000001110000111000011001111000'
6: '001111001111101100000110000011111101111111111100011110001111101110111110'
7: '1111110111111000001100001100000100000110000110000011000011100001100000'
8: '0011100011011011000110110110011110001111101100111110001111100110111110'
9: '0011100111111011000111100011110001111111110011011000011100001101111100'

By 4 points you can recognize up to 2 4 = 16 unique values, ten is enough for us.

Calculate the number of possible combinations of four numbers out of 70:
C k n = n! / (K! * (Nk)!) = 70! / (4! * 66!) = 70 * 69 * 68 * 67/4! = 916895 combinations.

We need those combinations that will be different for all digits (from 0 to 9) (to uniquely identify each digit).

I searched the following points: (8,20,57,69)

Their coordinates are:


Now we know 4 points by which we can uniquely identify the number and combinations for each number:
.

Everything. Now I processed the original image as follows: on the left and on the right I found significant pixels (black), cut off the white ends. The remaining picture is divided into blocks of 7 by 10 pixels. And in these blocks I compared combinations in 4 points.

I would be glad if someone come in handy.

Source: https://habr.com/ru/post/148319/


All Articles