Effacer les filtres
Effacer les filtres

Can I choose point with mouse from video?

3 vues (au cours des 30 derniers jours)
Ahmad
Ahmad le 1 Fév 2015
Réponse apportée : Ahmad le 3 Fév 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.

Réponses (3)

Chris Barnhart
Chris Barnhart le 1 Fév 2015
Modifié(e) : Chris le 1 Fév 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 le 2 Fév 2015
This is realy amazing. Thank you Chris very much. I'll try this soon, but I should install the 2014 edition first.
  1 commentaire
Chris Barnhart
Chris Barnhart le 2 Fév 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

Connectez-vous pour commenter.


Ahmad
Ahmad le 3 Fév 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?

Catégories

En savoir plus sur Interactive Control and Callbacks dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by