How to extract x and y values from bounding box?

3 次查看(过去 30 天)
%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??

回答(1 个)

Image Analyst
Image Analyst 2023-1-21
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

类别

Help CenterFile Exchange 中查找有关 Computer Vision with Simulink 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by