【问题标题】:MATLAB - Detect double mouse click on figureMATLAB - 检测鼠标双击图
【发布时间】:2017-11-30 20:48:33
【问题描述】:

我使用impoly 允许用户编辑图形上的多边形。现在,我使用pause() 来检测用户何时完成操作,但我宁愿它是双击鼠标(类似于roipoly 所做的)。

我不能使用roipoly,因为它不允许绘制初始多边形,这是必要的。

关于如何获得它的任何想法?

【问题讨论】:

  • 您是否尝试在完成编辑后调用某些操作?说“完成”的按钮还不够好吗?
  • 不,这还不够好,因为它逐帧编辑视频,我想尽量减少鼠标移动或 alt+tab

标签: matlab image-processing matlab-figure video-processing figure


【解决方案1】:

impoly 工具似乎修改了figure windowWindowButtonDownFcnWindowButtonMotionFcnWindowButtonUpFcnWindowKeyPressFcnWindowKeyReleaseFcn 回调。我原本以为你不能修改其中的任何一个,因为它们会被impoly 用于其功能的回调函数覆盖。但是,事实证明它们仍然可以正确调用。这为您提供了更多选择:


修改WindowButtonDownFcn:

要添加检测双击的功能,您必须使用WindowButtonDownFcn 回调。例如:

set(gcf, 'WindowButtonDownFcn', @double_click_fcn);
h = impoly();

% Define this function somewhere (nested, local, etc.):
function double_click_fcn(hSource, ~)
  if strcmp(get(hSource, 'SelectionType'), 'open')
    % Advance to next frame
  end
end


修改WindowScrollWheelFcn:

每当我创建一个必须滚动浏览多个时间点/绘图/图像的 GUI 时,我喜欢使用 WindowScrollWheelFcn 回调来推进(向上滚动)或倒回(向下滚动)数据。您可以使用它从帧滚动到帧,显示已经绘制的任何多边形(如果有的话)或允许用户创建一个新多边形。例如:

set(gcf, 'WindowScrollWheelFcn', @scroll_fcn)
h = impoly();

% Define this function somewhere (nested, local, etc.):
function scroll_fcn(~, eventData)
  if (eventData.VerticalScrollCount < 0)
    % Mouse has been scrolled up; move to next frame
  else
    % Mouse has been scrolled down; move to previous frame
  end
end


修改WindowKeyPressFcn

您还可以使用WindowKeyPressFcn 回调来允许您使用键盘按钮(例如左右箭头键)前进帧。例如:

set(gcf, 'WindowKeyPressFcn', @keypress_fcn)
h = impoly();

% Define this function somewhere (nested, local, etc.):
function keypress_fcn(~, eventData)
  switch eventData.Key
    case 'rightarrow'
      % Right arrow pressed; move to next frame
    case 'leftarrow'
      % Left arrow pressed; move to previous frame
  end
end


有关创建所有这些回调的更多信息,see here

【讨论】:

  • 感谢您的帮助。不过,我仍然没有完全能够让它运行,也许是因为我不熟悉这种函数定义。查看建议的按钮向下功能-如何使用更多参数调用它?我需要双击,多边形的坐标将被保存
  • @guyts:听起来你需要sharing data among callbacks 的帮助。链接中描述了许多选项,但我认为嵌套函数方法可能最适合您的特定问题。在没有看到您的任何代码的情况下,我能提供的帮助不多了。
猜你喜欢
  • 1970-01-01
  • 2010-09-24
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2020-04-18
  • 2021-09-06
相关资源
最近更新 更多