matlab get mouse coordinates on image without clicking (on mouse over)

被刻印的时光 ゝ 提交于 2020-01-04 10:17:41

问题


I've been googling for a while to find a solution to this apparently simple problem: getting mouse coordinates in image axes while the mouse is moving (without clicking).

  1. I've found that impixelinfoval does exactly this but I'm not able to extract the pixel coordinates from this uicontrol in the script (are they stored in some field?).

  2. I've also found that ginput gives you the coordinates but only if you click.

Do you know any workaround for one of these two issues?

Are you aware of any solution to accomplish this using MATLAB functions?


回答1:


Check out this callback for the figure window: WindowButtonMotionFcn - http://www.mathworks.com/help/matlab/ref/figure_props.html (you do have to scroll down a decent amount, sorry about that)

This function will fire every time the mouse moves anywhere within the figure. From there, you need to make a call to get the 'CurrentPoint' of the axis you want. If the currentpoint is within the axis bounds, then you know that your mouse is over the axis and currentpoint tells you, well the current point :)

If you are not in the axis, your ButtonMotionFcn will quickly exist and so performance won't be affected noticeably.

The nice thing about this approach is that you can use it for any axes all within the same function.



来源:https://stackoverflow.com/questions/24797795/matlab-get-mouse-coordinates-on-image-without-clicking-on-mouse-over

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!