Encoder, Scanner
Encoding information into a bar code and Scanner :
In this project I developed an encoder to encode an amateur sportsman’s license in bar code form. After studying the different bar codes that exist and I chose to create a bar code in height and not in width. Especially inspired by the spotify code.
For encoding : I start with information that is a string of ten characters which includes uppercase letters, miniscule letters and numbers .
-
I convert each character into a 6-bit gray code word to form a binary sentence.
(I chose the gray code encoding because it facilitates the management of errors when decoding information especially with the Viterbi Algorithm and the CRC code).
-
Then I separate the binary sentence into a 3-bit word, I associate each binary word into a bar height using a matching table. So I get a list of bar height.
-
I associate each height of the list with a graphic element of the page to form the bar code
Once the license of each user has been encoded, it is now necessary to design a scanner to recover the license from the encoding.
The user will have access to a scan he can take a photo and this one will be processed.
To carry out the image analysis I used the OPEN-CV library : a free library developed by Intel specialized in real-time image processing. I used it to retrieve the image matrix and do some processing there.
//image playback to obtain a pixel matrix
let matriceImage = cv.imread(this.matriceImage);
//conversion from matrix to gray scale
cv.cvtColor(matriceImage, matriceImageNiveauDeGris, cv.COLOR_RGBA2GRAY, 0);
//detect the edges of objects
cv.Canny(matriceImageNiveauDeGris, matriceImageAvecContours, 50, 200, 3, false);
//retrieving contours of image objects
cv.findContours(matriceImageAvecContours, contours, hierarchy, cv.RETR_EXTERNAL, cv.CHAIN_APPROX_NONE);
//<img src="/scaner/.png"/>
We use the two reference balls located before the first bar and after the last bar to rotate if necessary the matrix to obtain values of correct height
To have a more precise processing area, the image matrix is reduced to the height of the logo on the left and the width between the logo and the second reference ball.
Objects of too small size are removed from the matrix. This can be noise on the image or a reflection on the photo.
Using the contours of the objects, we recover the highest and lowest point to have their heights.
-
We calculate for each bar of the bar code the ratio between the reference height which is the logo on the left and the height of the bar. By taking a ratio we are sure that even if the bar code is enlarged or narrowed the difference between the bar heights and the logo height remains the same.
-
All ratios are added to a list.
-
We convert each ratio using a matching table into a binary word
I divide my sentence into binary (gray code) in 6-bit binary word and then convert each word to its associated character using a matching table
So I now have a license number, I check that this number exists in my database using a server request. If the word exists then I want to recover the information of the person with this license number otherwise I restart my image processing
Here is the Result
Selection in a user’s database.
Encoding its license as a bar code.
Scans its barcode to retrieve user information.