Issue using imcrop in a script

Hello
I am using imcrop to perform a "live" crop. So
[init_crop,crop]=imcrop(init_img)
So this pops open a figure with the image "init_img" and allows me to draw a box around the bit I want to crop.
init_crop, crop returns the cropped image and the bounding box.
This works fine in isolation. It also works if I am stepping through. If I run the script proper, the live cropping function appears to not work at all. I get shown the image, but I am not able to draw a box around the area I want. The program then just waits around for me to select my crop, but I can't!
Fuller code:
camList = webcamlist
cam = webcam(2)
init_img = snapshot(cam);
init_img = rgb2gray(init_img);
figure
imshow(init_img)
[init_crop,crop]=imcrop(init_img);
disp(crop)
imshow(init_crop)

3 件のコメント

KSSV
KSSV 2021 年 7 月 27 日
If your cropped box is awlays same, you can provide this information in imcrop and it will not pop the figure.
Alex Mason
Alex Mason 2021 年 7 月 27 日
Yes of course. However, this initial bit of code is for setting up the crop. So the user takes a sample image from the webcam and draws the crop box.
This box is then used later to do other things. e.g. I have a loop that periodically takes images from the webcam and the crop box is re-used here to select the area of interest automatically.
But at the start, I do need the user to define where the crop should be.
Jonas
Jonas 2021 年 7 月 28 日
you can try using ginput and round the output data to pixels. unfortunately i can not test your code because i do not have a webcam at the moment

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

回答 (0 件)

カテゴリ

ヘルプ センター および File ExchangeImages についてさらに検索

製品

リリース

R2018b

質問済み:

2021 年 7 月 27 日

コメント済み:

2021 年 7 月 28 日

Community Treasure Hunt

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

Start Hunting!

Translated by