代码
function ROI=LabelBox(filename)
Mat=imread(filename);
imshow(Mat);
mouse=imrect;
pos=getPosition(mouse);% x1 y1 w h
ROI=[pos(1) pos(2) pos(1)+pos(3) pos(2)+pos(4)];
end
效果
>> LabelBox(\'1_1(1).jpg\')
为了快速标注,可以遍历整个文件夹下的图片,标完一张换一张,生成一个table数据表:
function BoxTable=getAllbox(folder)
fileFolder=fullfile(folder);
dirOutput=dir(fullfile(fileFolder,\'*.jpg\'));
filenames={dirOutput.name}\'; %列向量
rois=[];
for i=1:length(filenames)
roi=LabelBox(filenames{i});
rois=[rois;roi];
end
BoxTable=table(filenames,rois);
end