DrawingFinished event No response

33 visualizaciones (últimos 30 días)
Roche de Guzman
Roche de Guzman el 30 de En. de 2021
Comentada: cui,xingxing el 27 de Abr. de 2023
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!

Respuesta aceptada

Tim Jackman
Tim Jackman el 10 de Feb. de 2021
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 comentarios
Petr Kryze
Petr Kryze el 30 de Mzo. de 2022
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 el 27 de Abr. de 2023
@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!

Iniciar sesión para comentar.

Más respuestas (0)

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by