cvml's Blog

Computer Vision and Machine Learning

【error】LNK2038: mismatch detected for '_ITERATOR_DEBUG_LEVEL': value '0' doesn't match value '2'

Matlab鼠标按下并移动选取图像上的坐标,放开时停止

cvml posted @ 2013年10月21日 22:32 in Matlab , 8211 阅读

功能:按下鼠标后并拖动鼠标,记录鼠标移动过的像素坐标,放开鼠标时结束。

设置鼠标响应

set(gcf,'WindowButtonDownFcn',@ButtonDownFcn);

set(gcf,'WindowButtonUpFcn',@ButtonUpFcn);

set(gcf,'WindowButtonMotionFcn',@ButtonMotionFcn);

gcf为当前figure的句柄;gca为当前坐标轴的句柄。

下面为示例代码:

function test_mouse_track()
% I = imread('1.bmp');
% imshow(I); hold on
figure;hold on
axis([-10,10,0,5]);
set(gcf,'WindowButtonDownFcn',@ButtonDownFcn);
set(gcf,'WindowButtonUpFcn',@ButtonUpFcn);

% set(gcf,'WindowButtonDownFcn',@ButttonDownFcn);

function ButtonDownFcn(src,event)
pt = get(gca,'CurrentPoint');    %获取当前点坐标
x = pt(1,1);
y = pt(1,2);
set(gcf,'WindowButtonMotionFcn',@ButtonMotionFcn); %设置鼠标移动响应
fprintf('x=%f,y=%f\n',x,y);
plot(x,y,'*');

function ButtonMotionFcn(src,event)
pt = get(gca,'CurrentPoint');
x = pt(1,1);
y = pt(1,2);
plot(x,y,'*');
fprintf('x=%f,y=%f\n',x,y);

function ButtonUpFcn(src,event)
set(gcf, 'WindowButtonMotionFcn', '');    %取消鼠标移动响应

 

最后,这篇博客貌似不错,记录一下,以备不时之需。http://blog.sina.com.cn/s/blog_6163bdeb0100q7iu.html


登录 *


loading captcha image...
(输入验证码)
or Ctrl+Enter