带缩放功能的 Matlab KeyPressFcn
Matlab KeyPressFcn with zooming
基本上我只想使用 getpts 函数获取图像上的一些点坐标。这个想法是使用缩放(在面板上)在图像上找到目标区域,然后在按键上调用 getpts 并指定一个点。
我已经安装了按键回调
fig_h = figure;
set(fig_h,'KeyPressFcn','keypress');
hold on;
imshow(b);
这个回调在我开始缩放之前工作正常。但是在我放大了某个区域后,它停止调用我的回调。我怎样才能达到预期的行为?谢谢
这里有一个懒惰的解决方法可以完成这项工作:
基本上创建一个按钮,其回调执行与代码中的 KeyPressFcn
相同。也就是说,只要您按下按钮,函数 getpts
就会执行,即使您处于缩放模式。那么你不需要按任何键来激活该功能,而是按一个按钮:
function KeyPress(~)
clc
clear
%// Test image
b = imread('peppers.png');
fig_h = figure('Position',[200 200 500 500],'Units','Pixel');
%// Create pushbutton and define its callback
hButton = uicontrol('style','push','Position',[20 20 60 30],'String','Get Points','Callback',@(s,e) keypressCB)
hold on;
imshow(b);
function keypressCB
[x, y] = getpts(fig_h)
end
end
缩放后的屏幕截图,启用 getpts
:
希望对您有所帮助!
基本上我只想使用 getpts 函数获取图像上的一些点坐标。这个想法是使用缩放(在面板上)在图像上找到目标区域,然后在按键上调用 getpts 并指定一个点。 我已经安装了按键回调
fig_h = figure;
set(fig_h,'KeyPressFcn','keypress');
hold on;
imshow(b);
这个回调在我开始缩放之前工作正常。但是在我放大了某个区域后,它停止调用我的回调。我怎样才能达到预期的行为?谢谢
这里有一个懒惰的解决方法可以完成这项工作:
基本上创建一个按钮,其回调执行与代码中的 KeyPressFcn
相同。也就是说,只要您按下按钮,函数 getpts
就会执行,即使您处于缩放模式。那么你不需要按任何键来激活该功能,而是按一个按钮:
function KeyPress(~)
clc
clear
%// Test image
b = imread('peppers.png');
fig_h = figure('Position',[200 200 500 500],'Units','Pixel');
%// Create pushbutton and define its callback
hButton = uicontrol('style','push','Position',[20 20 60 30],'String','Get Points','Callback',@(s,e) keypressCB)
hold on;
imshow(b);
function keypressCB
[x, y] = getpts(fig_h)
end
end
缩放后的屏幕截图,启用 getpts
:
希望对您有所帮助!