How to extract x and y values from bounding box?
3 views (last 30 days)
Show older comments
%test image%
img = imread('eufs_00001.png');
[bboxes, scores] = detect(detector, img);
% Display the detection result
for i = 1:length(scores)
annotation = sprintf('Confidence = %.1f', scores(i));
img = insertObjectAnnotation(img, 'rectangle', bboxes(i,:), annotation);
end
figure
imshow(img)
Hi i am trying to extract x and y values from bboxes which is bounding boxes to the editor. i want those x and y values to cotinue my work. so can some one tell me how to extract them??
Answers (1)
Image Analyst
on 21 Jan 2023
See this function to get row and column indexes from a bounding box.
% For each blob measured by regionprops(), this converts the BoundingBox measurements, which lie 0.5 pixels outside the region,
% into coordinates that lie along integer rows and columns for ease of use in indexing images.
function [yRow1, yRow2, xCol1, xCol2] = BoundingBox2Indexes(props)
try
xCol1 = 1;
xCol2 = 1;
yRow1 = 1;
yRow2 = 1;
if isempty(props)
return;
end
if ~isfield(props, 'BoundingBox')
errorMessage = sprintf('Error in function BoundingBox2Indexes():\nYour regionprops output that you sent to function BoundingBox2Indexes()\ndoes not have a field called BoundingBox.');
uiwait(errordlg(errorMessage));
return;
end
allBB = vertcat(props.BoundingBox);
xCol1 = ceil(allBB(:, 1));
yRow1 = ceil(allBB(:, 2));
xCol2 = xCol1 + allBB(:, 3) - 1;
yRow2 = yRow1 + allBB(:, 4) - 1;
catch ME
% Some error happened if you get here.
errorMessage = GetErrorMessage(ME); % Get error message with call traceback and file's date.
WarnUser(errorMessage); % Pop up error message to show user what it is. Also prints to command window or console window (if program is an executable).
end
0 Comments
See Also
Categories
Find more on Computer Vision with Simulink in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!