필터 지우기
필터 지우기

Specify ROI in readBarcode

조회 수: 2 (최근 30일)
Stephen Marsden
Stephen Marsden 2024년 2월 19일
편집: Abhinav Aravindan 2024년 2월 27일
I have an image with data in text on the image. I expect the same data to be in the barcode at the edge. This should be about 30 decimal digits of data. When I run readBarcode, I get "44083724", format EAN8 and location:
611.5000 40.0000
372.5000 40.0000
264.5000 40.0000
225.0000 40.0000
I think that there are three barcodes at the left of the photo. readBarcode is finding the first and then quitting. I suspect that the location is the end points of the three barcodes.
I ran drawrectangle over the region of the bar codes and got the position 5.0000 0.5000 33.0000 335.5000.
I think the solution is to run readBarcode and specify an ROI for each of the three barcodes on the left edge. I can't seem to do it though. The documentation isn't clear on how to get the ROI from the location or position.

채택된 답변

Abhinav Aravindan
Abhinav Aravindan 2024년 2월 27일
편집: Abhinav Aravindan 2024년 2월 27일
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:

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Recognition, Object Detection, and Semantic Segmentation에 대해 자세히 알아보기

제품


릴리스

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by