DrawingFinished event No response

34 次查看(过去 30 天)
imshow(I,[]); % show image from image data
drawroi = drawassisted; evs = events(class(drawroi)); % event source and events list for class
% test for action:
i = 7; % drawing finished
ev = evs{i}; addlistener(drawroi,ev,@(source,data) disp(data)); % event and its listener
Hello,
I'm trying to create a response when the drawing of an ROI is finished, DrawingFinished event, by adding a listener as shown in the commands.
The other events (such as i = 9 for ROI moved, i = 2 for waypoint added, etc.) are working but not for drawing started (i = 6) and finished (i = 7).
Thanks in advance!

采纳的回答

Tim Jackman
Tim Jackman 2021-2-10
drawassisted is a simple wrapper around the image.roi.AssistedFreehand object. The function drawassisted really only constructs the ROI object and calls the draw method on the object so the user can begin drawing immediately. The problem with using drawassisted is that you can't set up listeners for the ROI object until after the object has already been drawn. For most events this isn't an issue but, as you observed, you can't set up DrawingStarted and DrawingFinished because the draw interaction will occur before you get the chance.
My suggestion would be to use the formal interface images.roi.AssistedFreehand directly:
Step 1: Construct the ROI object and parent it to the axes
I = imread('peppers.png');
imshow(I);
ax = gca;
drawroi = images.roi.AssistedFreehand('Parent',ax);
Step 2: Set up the listeners
addlistener(drawroi,'DrawingStarted',@(~,~) disp('Drawing Has Started'));
addlistener(drawroi,'DrawingFinished',@(~,~) disp('Drawing Has Finished'));
Step 3: Call draw method to begin interactively drawing the ROI
draw(drawroi);
  3 个评论
Petr Kryze
Petr Kryze 2022-3-30
This is great. I have huge problems finding a comprehensive list of EventNames for Rectangle ROIs, because I need event callbacks at creation, finish and deletion of ROI. This has helped!
cui,xingxing
cui,xingxing 2023-4-27
@Tim Jackman The official documentation doesn't make this clear, so I hope it can be added to the documentation,Thank you for your advice!

请先登录,再进行评论。

更多回答(0 个)

Community Treasure Hunt

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

Start Hunting!

Translated by