how to get pixel coordinates from iptSetPointerBehavior

1 ビュー (過去 30 日間)
Andrew Diamond
Andrew Diamond 2017 年 12 月 25 日
編集済み: Andrew Diamond 2017 年 12 月 25 日
EDIT I can get this to work by using set(handles.figure1,'WindowButtonMotionFcn',@(src,event)overMe(src,event,handles,himage));
vs all the PointerBehavior stuff below. I do call the axes 'currentpoint' to get axes mouse coordinate in the callback (the same one I used below) but now it actually returns good coordinates. I also have to filter out the axes coordinates for ones that are actually in the axes/image limits.
=== Matlab 2016b
Within the context of a GUIDE gui, I create an image object and then I want to create a callback that changes the cursor if it's within a specified region of the image. To accomplish this, after I create the image pointer,
set(himage,'cdata', FilteredFrame);
as you can see, above, I also have a callback associated with image handle's ButtonDownFnc. That works fine giving me the correct coordinates. For the mouse movement callback, as per the documentation, to set the appropriate callback, I then do this:
pointerBehavior.enterFcn = [];
pointerBehavior.exitFcn = [];
pointerBehavior.traverseFcn = @(src,event) overMe(src,event,handles,himage);
iptSetPointerBehavior(hImage, pointerBehavior);
The overMe call function, I thought, would get the coordinates in image space (in event) whenever I moved over it, but that doesn't happen. My callback gets called but I get coordinates nothing like the image coordinates.
Within overMe I tried the following to get mouse/axis coordinates as I thought that would be the same as the image pixel coordinates (note I use the axes handle as 'CurrentPoint' is not an image handle property) but no such luck. Note, I can see that axes limits are in fact correct, i.e. the same as the image coordinates. The coordinates I get back are typically not even in the axes/image limits.
currentPoint = get(handles.axes1, 'CurrentPoint');

回答 (0 件)

Community Treasure Hunt

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

Start Hunting!

Translated by