2

我意识到应用程序设计器不支持交互式图形操作,但我想知道是否可以打开一个单独的图形窗口(不是 UI 窗口)并在其上显示我的图形,以便我仍然可以获得鼠标点击的位置。目前,下面的代码在我的 GUI 上显示该图,然后打开另一个记录我的鼠标点击的空白图。这很好,但我还需要在新窗口中显示该图形,并且在这样做时遇到了麻烦。

first frame = vid(:,:,:,1);
imshow(firstframe,'Parent',app.UIAxes); 
[centers_X centers_Y]=getpts;
4

1 回答 1

0

对我有用的是在图像而不是轴上设置回调:

ih = imshow(firstframe,'Parent',app.UIAxes);
ih.ButtonDownFcn = {@im_ButtonDownFcn, app}; %app will be passed to the callback

然后在同一文件夹中的单独文件中(或作为应用程序设计器中的私有函数......它应该可以工作,但我还没有尝试过):

function im_ButtonDownFcn(im, hit, app)
mouse_pos = flip(hit.IntersectionPoint(1:2)); %gives floats. Round if you want integers e.g. for indexing pixels
于 2018-07-03T03:23:53.273 回答