The "readBarcode" function appears to be recognizing the colour variations near the text as a barcode, rather than the barcode strip on the left side of the image. Plotting the location yields this information.
I = imread("RP 292 H17.png");
[msg,detectedFormat,loc] = readBarcode(I);
disp("Barcode format: " + detectedFormat)
plot(loc(1,1), loc(1,2), "r|", "MarkerSize", 25, "LineWidth", 2);
plot(loc(2,1), loc(2,2), "r|", "MarkerSize", 25, "LineWidth", 2);
plot(loc(3,1), loc(3,2), "b|", "MarkerSize", 25, "LineWidth", 2);
plot(loc(4,1), loc(4,2), "b|", "MarkerSize", 25, "LineWidth", 2);
Output:
It is not clear what the three barcodes on the left strip are, as there does not seem to be any demarcation. However, if you wish to read barcodes in specific regions of the image, you can specify the ROI in the format [x, y, width, height] as an input to the “readBarcode” function. To determine the ROI, you can adjust "loc" accordingly or use “drawrectangle” to interactively select the region and obtain the parameters as follows:
For more barcode localization methods, please refer to the link below.
The following code snippet demonstrates usage of ROI with “readBarcode” :
I = imread("RP 292 H17.png");
roi = [5.0000 0.5000 33.0000 335.5000]
[msg,detectedFormat,loc] = readBarcode(I, roi);
disp("Barcode format: " + detectedFormat)
Output :
The output string being empty suggests that either the barcode might not be valid, or its format may not be compatible with the “readBarcode” function's capabilities. Troubleshooting steps can be found in a related MATLAB Answers query provided below.
Please refer to the below documentation links for more detail: