Post

Barcode Detection on GPU

Barcode Detection on GPU
1
CUDA, GPU Programming, Detection, Image Processing

Project

Implementing Local Binary Patterns Hitograms algorithm on GPU, then get the resulting images in a KMeans to extract a class containing all pixels related to the barcode.

Various images were given, bellow an example of input image:

LBP

The LBP is a simple yet very efficient texture operator which labels the pixels of an image by thresholding the neighborhood of each pixel and considers the result as a binary number:

LBP algorithm detailed

(Image from Towards Data Science)

Histograms

After calculating each pixel new value with LBP, the next step was to divide the image in patches, and calculate the patches’ histograms. Each histogram is an entry to the following classification step.

Histogram part detailed

(Image from Towards Data Science)

GPU Implementation

The final strategy has been to launch only one kernel that would load a patch (16x16 pixels + borders needed to have neighboorhood) in shared memory and apply the LBP algorithm, finishing each thread job with a direct update of the histogram.

This histogram update need an atomic operation, as multiple thread could be modifying the same value at the same time. Therefore, the depicted method was a bit slower than a more straight forward one, without the use of shared memory. However, the memory is managed more properly and the implementation of a strategy like parallel reduction to avoid atomics could be a great improvement.

Classification Results

Resulting histograms are handed over to a pretrained KMeans (with clusters centers already known) with arbitrary number of classes (here 16, which should be enough)

Results of histograms classification

Here we can see in which classes each patch was classified. Testing with multiple images, including some without barcode, the 12th class stands out as a quite good detection of the barcode.

This post is licensed under CC BY 4.0 by the author.

Trending Tags