フィルターのクリア

Update the ROI with drawrectangle change

7 ビュー (過去 30 日間)
Mert Karakaya
Mert Karakaya 2019 年 9 月 6 日
回答済み: Mert Karakaya 2019 年 9 月 16 日
Hi,
I'm trying to draw a shape (rectangle, circle etc.) to determine region of interest (ROI) in an image. When I use the drawrectangle function, I can get the corners of the first instance that the rectangle is drawn, however when I edit the rectangle on the figure (change size/position), it does not update the roi variable. How can I update the roi variable when the rectangle is altered in a script?
Code I use is below and I use R20109a;
temp = snapshot(cam1);
imshow(temp);
rect = drawrectangle;
roi = rect.Position;
  4 件のコメント
Dheeraj Singh
Dheeraj Singh 2019 年 9 月 13 日
You can try running the code in the loop for the required functionality
while true
%when you receive an update
x=input()
rect = drawrectangle;
%update roi
roi = rect.Position;
end
Mert Karakaya
Mert Karakaya 2019 年 9 月 16 日
Thanks for your answer Mr. Singh,
Unfortunately, I couldn't get it to work. However, I have found a way that might be possible.
imshow(snapshot(camL)); %Show image
rect = drawrectangle; %Start draw rectangle
roi = rect.Position; %Get inital position
addlistener(rect,'ROIMoved',@roiChange); %Update if there is a change to the rectangle
function roi = roiChange(src,evt)
evname = evt.EventName;
if isequal(evname,'ROIMoved')
roi = evt.CurrentPosition; %Update roi
end
end
My only problem is that, I cannot get the roi output with the addlistener. I have searched the documentation for a few hours now, and I cannot figure out. How can I get the output with the addlistener?
Thanks.

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

採用された回答

Mert Karakaya
Mert Karakaya 2019 年 9 月 16 日
For anyone who is wondering how to solve this issue; here is my solution that works;
This is the main code
imshow(snapshot(camL));
rect = drawrectangle;
roiL = rect.Position;
addlistener(rect,'ROIMoved',@(src, evt) roiChange(src,evt,'roiL'));
And the function
function roi = roiChange(src,evt,roi)
assignin('base',roi,evt.CurrentPosition);
end
Thanks for all the help.

その他の回答 (0 件)

製品


リリース

R2019a

Community Treasure Hunt

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

Start Hunting!

Translated by