Pipeline to extract barcode number from images using OpenCV functions. A simple k-neighbours classifier was trained to detect the numbers present in the barcode.
- convert image to grayscale
- create structure element for extracting vertical lines through morphology operations. (using cv2.getStructuringElement())
- apply morphological operations. (using cv2.erode() and cv2.dilate())
- using binary_inverse and otsu thresholding using cv2.threshold()
Extract digits present in the training set images using cv2.findContours(). Manually segregate the extracted digits to generate the training set images.
Feature extraction is the process of identifying the unique characteristics of an input (digit in our case) which enables in training a Machine Learning algorithm. Histogram of Oriented Gradients(HOG) are feature extractors mainly used in computer vision for object detection. The reason HOG is utilized so heavily is because local object appearance and shape can be characterized using the distribution of local intensity gradients.
The extracted features from HOG are given as input to train a k-neighbours classifier with n_neighbors=1.
- apply the above image processing methods on test images
- extract the digits from the processed image
- extract features for the digits using HOG
- predict on these features using the trained knn model.
- concatenate the predicted digits to obtain the barcode number
https://towardsdatascience.com/scanned-digits-recognition-using-k-nearest-neighbor-k-nn-d1a1528f0dea https://gurus.pyimagesearch.com/lesson-sample-histogram-of-oriented-gradients-and-car-logo-recognition/ https://stackoverflow.com/questions/9413216/simple-digit-recognition-ocr-in-opencv-python