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.
% Read Image
I = imread("RP 292 H17.png");
% Read Barcode
[msg,detectedFormat,loc] = readBarcode(I);
disp("Barcode format: " + detectedFormat)
disp("Message: " + msg)
disp("Location:")
disp(loc)
% Plot detected locations
imshow(I)
hold on
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);
hold off
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:
roi = drawrectangle;
pos = roi.Position;
For more barcode localization methods, please refer to the link below.
The following code snippet demonstrates usage of ROI with “readBarcode” :
% Read Image
I = imread("RP 292 H17.png");
% Read Barcode at ROI
roi = [5.0000 0.5000 33.0000 335.5000]
[msg,detectedFormat,loc] = readBarcode(I, roi);
disp("Barcode format: " + detectedFormat)
disp("Message: " + msg)
disp("Location:")
disp(loc)
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: