imcrop a specific bounding box

4 ビュー (過去 30 日間)
Oliver Ferenczi
Oliver Ferenczi 2020 年 2 月 24 日
回答済み: Josep Llobet 2022 年 3 月 24 日
Hi, I am trying to write code that will crop around a specific bounding box on appdesigner. It currently works when there is only a single bounding box in the image. However when there are several it wouldn't know which box to crop around.
This is the current code.
bboxes = step(faceDetector, faceimage);
CroppedFaces = imcrop(app.Faces,bboxes);
Thank you
  1 件のコメント
Chaitanya Mallela
Chaitanya Mallela 2020 年 3 月 3 日
if the faceDetector object has Bounding Box property, try to Label every Bounding Box and execute imcrop command in a loop whose max iteration value equals Number of Labels.

サインインしてコメントする。

回答 (1 件)

Josep Llobet
Josep Llobet 2022 年 3 月 24 日
You can try the next code:
Obtain the image example
% __JUST OBTAIN THE IMAGE__%
% Obtain image
krillin = imread("https://es.mathworks.com/responsive_image/150/150/0/0/0/cache/matlabcentral/profiles/22817879_1627284404454.jpg");
% Process it
krillin_grey = im2gray(krillin);
krillin_grey_imadj = imadjust(krillin_grey);
krillin_BW = imbinarize(krillin_grey_imadj);
krillin_BW_2 = imclearborder(~krillin_BW);
% Labels (not necessary)
% krillin_BW_2_bwlab = bwlabel(krillin_BW_2);
% unique(krillin_BW_2_bwlab(:))
% imshow(krillin_BW_2_bwlab, [])
% Obtain the three major objects
krillin_BW_2_largest = bwpropfilt(krillin_BW_2, "Area", 3, "largest");
imshow(krillin_BW_2_largest)
Crop the Bounding Boxes
% __CROP THE BOUNDING BOXES__%
BB = regionprops(krillin_BW_2_largest,'BoundingBox'); %<--- rellevant
for every_BB = 1:length(BB)
BB(every_BB).BoundingBox;
krillin_BW_BB = imcrop(krillin, BB(every_BB).BoundingBox+[-1 -1 1 1]); %Es retalla la imatge basant-se amb el BoundingBox.
% change v'krillin' for v'krillin_BW_2_largest' for obtain the binary images of bounding box
figure
imshow(krillin_BW_BB)
end
From the image: you must obtain:

カテゴリ

Help Center および File ExchangeDevelop Apps Using App Designer についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by