Can I choose point with mouse from video?

3 次查看(过去 30 天)
I am thinking of live video from cam as background, I want to choose point by mouse click so I can focus on this point with servo motor to put it in the center . the problem: it seems I can't use "ginput" on video, can I?, I thought maybe I could press key in realtime so I get screenshot "imshow" which I can choose point from! but I couldn't achieve this code.

回答(3 个)

Chris Barnhart
Chris Barnhart 2015-2-1
编辑:Chris 2015-2-1
If the live video is placed into a matlab figure object - then it might be easy. This code tracks the mouse and shows the click points.
function gui_test()
hf = figure(1)
set(hf,'WindowButtonMotionFcn',cb_mm);
set(hf,'WindowButtonDownFcn',@cb_fig);
set(hf,'WindowButtonUpFcn',@cb_fig);
function cb_mm(h,e)
%disp(e.Source)
disp(h.CurrentPoint)
end
function cb_fig(hobj,e)
%disp(e.Source)
disp(hobj.CurrentPoint);
end
end
For more details see figure properties

Ahmad
Ahmad 2015-2-2
This is realy amazing. Thank you Chris very much. I'll try this soon, but I should install the 2014 edition first.
  1 个评论
Chris Barnhart
Chris Barnhart 2015-2-2
I just checked 2007 as follows:
h=figure(1)
inspect(h)
It also has the Window... Fcn for callback.
However, the dot notation is possibly only 2014b, use get(hobj,'CurrentPoint') instead. This runs in 2007.
function gui_test()
function cb_mm(hobj,e)
%disp(e.Source)
disp(get(hobj,'CurrentPoint'));
end
function cb_fig(hobj,e)
%disp(e.Source)
disp(sprintf('click at %d %d', get(hobj,'CurrentPoint')));
end
hf = figure(1)
findfigs
set(hf,'WindowButtonMotionFcn',@cb_mm);
set(hf,'WindowButtonDownFcn',@cb_fig);
set(hf,'WindowButtonUpFcn',@cb_fig);
end

请先登录,再进行评论。


Ahmad
Ahmad 2015-2-3
this is very simple way to preview live video into figure:
vid = videoinput('winvideo');
figure('Toolbar','none',...
'Menubar', 'none',...
'NumberTitle','Off',...
'Name','My Preview Window');
vidRes = get(vid, 'VideoResolution');
nBands = get(vid, 'NumberOfBands');
hImage = image( zeros(vidRes(2), vidRes(1), nBands) );
% Display the video data in your GUI.
preview(vid, hImage);
but I couldn't merge the WindowButtonDownFcn with it, I tried different ways but it keeps giving me mistakes, sorry but I am new to matlab, if you can help me please?

类别

Help CenterFile Exchange 中查找有关 Interactive Control and Callbacks 的更多信息

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by