I want to crop multiple parts from the image to make groudtruth using mouse pointer. There are different number of objects in each so I can't run for
loop for specific number of times. However, I can use while
loop. But how can I stop that?
for i=1:10
[tt bb]=imcrop(img);
crop.img{i,:}=tt;
crop.bb(i,:)=bb;
end
You can use an if
condition with waitforbuttonpress
for this. When you're done cropping an image portion and want to crop another portion, click any mouse button and the loop will continue. When you don't want to crop any other portion, press any keyboard button and the loop will break
.
Demo Code:
img = imread('peppers.png');
f = figure;
k = 1;
while 1
[tt, bb] = imcrop(img);
crop.img{k,:} = tt;
crop.bb{k,:} = bb;
if waitforbuttonpress
break;
end
k = k+1;
end
Note that it requires your figure window to be in focus.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With