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");
figure; imshow(X);
figure; imshow(X. cmap);
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.