Barcode Recognition (Pharmacode)
This program can read the pharmacode. It can perform robust and fast detection even when multiple pharmacodes are in the picture.
Best of my knowledge, this is the first public implemantation that can decode a pharmacode, as there no publicly available program. If anyone is familiar with barcode recognition algorithms, please help us improve the program.
- CMake 3.10
- Ubuntu 20.04 LTS
- OpenCV 4.5.2
- TBB
git clone https://github.com/shun74/Barcode-Recognition.git
cd Barcode-Recognition
sh build.sh
Scan one image.
./build/scan_multiple ./config/sample_config.conf ./images/test_1.jpg
Realtime scan with camera. (Necessary to connect camera before run)
./build/real_time ./config/fast_run_config.conf
Preparing two configurations and measured execution times. Also mesured the execution time on edge device. it may be possible to improve the settings for even faster detection.
config | Core i7-10700K | Raspberry-pi 3B |
---|---|---|
sample | 5.4 ms (185 fps) | 104 ms (9.6 fps) |
fast_run | 3.1 ms (322 fps) | 35 ms (28.5 fps) |
You can execute this detection even on devices with limited computing resources.
Test 1
Test 2
Multiple scan sample
To make this program more flexible, some configs exists.
For specific values, see config.
- IMAGE_PROCESS : Conduct image preprocess or not. (Slightly unstable)
- GAMMA : Gamma correlation parameter.
- BLUR_KERNEL : Unsharp masking parameter.
- UNSHARP_K : Unsharp masking parameter.
- NUM_MAX_BARCODE : Max number of barcodes to scan.
- BARCODE_LENGTH : Number of black lines in barcode.
- SKIP_LENGTH : Number of line to skip in source image.
- FILL_WINDOW_SIZE : Window size to fill scan result.
- MIN_BARCODE_SIZE : Min barcode size to recognize.
- OUTPUT : Output images save dir.
- VISUALIZE : Show result image window or not.
Pharmacode, also known as Pharmaceutical Binary Code, is a barcode standard, used in the pharmaceutical industry as a packing control system. Wikipedia
Decoding a pharmacode is very simple.
Pharmacode is a binary code, so that this has only two type of black bar (wide & narrow).
Each bar has position like above image. If position i is narrow just add
For example : position 5 is wide bar -> add
This means that to read these code from the image by program, we only need to obtain something like a frequency component of binarized image.
For more detail. About Laetus/Pharmacodes - Computalabel
Some samples in barcodes.
For more detail. Please check these...