MATLAB Answers

Why can't the 'readBarcode' function read my barcode?

68 views (last 30 days)
I am using 'readBarcode' from the Computer Vision Toolbox to read an Aztec barcode. The function appears to execute properly, and no error messages appear. However, the output string, the detected format and the location returned by the function are empty. What are the troubleshooting steps for this issue?

Accepted Answer

MathWorks Support Team
MathWorks Support Team on 1 Feb 2021
Please follow the steps below to troubleshoot 'readBarcode' issues:
1.    If the barcode is not clear, then preprocessing steps will help enhancing the barcode to improve reading. For poorly aligned barcodes, you can use 'imrotate' and for noisy barcodes you can use 'imsharpen'. In case of poor contrast you can try the following:
I = imread("Figure2.jpg");
Igray = rgb2gray(I);
BW = imbinarize(I, 0.3);
readBarcode(BW)
2.    If your image is an indexed image, then the barcode may not be detected directly.
You should do the following:
[X, cmap] = imread("6.png"); % Get the colormap as well
% Notice the difference
figure; imshow(X);
figure; imshow(X. cmap);
% Convert to RGB
RBG = ind2rgb(X, cmap);
While specifying the formats, they can be a barcode family ('1D', '2D'), or a string vector of format names, but not a mix of both, as done in test.m. Changing the call to:
[msg, format, loc] = readBarcode(I,"AZTEC");
or
[msg, format, loc] = readBarcode(I);
should work.
3.    If the output string of the 'readBarcode' is empty then the barcode reader could not detect the barcode and it could be because of various reasons like: the barcode is not a valid one, it is not in a supported format or the reader is simply unable to find it. Please check if the barcode is a valid one, if the barcode reader returns an empty string.

Products


Release

R2020b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!