Borrar filtros
Borrar filtros

Can I choose point with mouse from video?

3 visualizaciones (últimos 30 días)
Ahmad
Ahmad el 1 de Feb. de 2015
Respondida: Ahmad el 3 de Feb. de 2015
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.

Respuestas (3)

Chris Barnhart
Chris Barnhart el 1 de Feb. de 2015
Editada: Chris el 1 de Feb. de 2015
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 el 2 de Feb. de 2015
This is realy amazing. Thank you Chris very much. I'll try this soon, but I should install the 2014 edition first.
  1 comentario
Chris Barnhart
Chris Barnhart el 2 de Feb. de 2015
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

Iniciar sesión para comentar.


Ahmad
Ahmad el 3 de Feb. de 2015
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?

Categorías

Más información sobre Interactive Control and Callbacks en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by