DrawingFinished event No response

조회 수: 34 (최근 30일)
Roche de Guzman
Roche de Guzman 2021년 1월 30일
댓글: cui,xingxing 2023년 4월 27일
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