How to overcome the error in the listener function while getting the final positions of an interactive ROI?

1 次查看(过去 30 天)
I am trying to draw an interactive elliptical ROI in an image. I have used the drawellipse function. I have also added a listener to give me the final position of the ellliptical ROI. Here is my code:
imshow(frameraw1);
roi = drawellipse('Color','r');
ell_lis = addlistener(roi,'MovingROI',@allevents_ellipse);
ell_lis = addlistener(roi,'ROIMoved',@allevents_ellipse);
The @allevents_ellipse function is as follows:
function allevents_ellipse(src,evt)
evname = evt.EventName;
switch(evname)
case{'MovingROI'}
disp(['ROI moving previous position: ' mat2str(evt.PreviousPosition)]);
disp(['ROI moving current position: ' mat2str(evt.CurrentPosition)]);
case{'ROIMoved'}
disp(['ROI moved previous position: ' mat2str(evt.PreviousPosition)]);
disp(['ROI moved current position: ' mat2str(evt.CurrentPosition)]);
end
end
However, I am getting the following error:
Error in allevents_ellipse (line 5)
disp(['ROI moving previous position: ' mat2str(evt.PreviousPosition)]);
Error in images.roi.internal.ROI/dragROI
Error in images.roi.internal.ROI
> In images.roi.internal/ROI/dragROI
In images.roi.internal.ROI
Warning: Error occurred while executing the listener callback for event ROIMoved defined for class
images.roi.Ellipse:
Unrecognized method, property, or field 'PreviousPosition' for class
'images.roi.EllipseMovingEventData'.
Error in allevents_ellipse (line 8)
disp(['ROI moved previous position: ' mat2str(evt.PreviousPosition)]);
Error in images.roi.internal.ROI/stopDrag
Error in images.roi.internal.ROI
> In images.roi.internal/ROI/stopDrag
In images.roi.internal.ROI
Could someone please help me overcome this error?
If there are any other methods by which I can get the final position of the ellipse, those would also be appreciated.
Thank you in advance.

采纳的回答

Yazan
Yazan 2021-7-18
If you just need to get the position of the ROI, then you do not need necessary to create a listener. Just access the feature Vertices in the ROI object.
roi.Vertices

更多回答(0 个)

Community Treasure Hunt

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

Start Hunting!

Translated by