Filter löschen
Filter löschen

Can I choose point with mouse from video?

3 Ansichten (letzte 30 Tage)
Ahmad
Ahmad am 1 Feb. 2015
Beantwortet: Ahmad am 3 Feb. 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.

Antworten (3)

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

Melden Sie sich an, um zu kommentieren.


Ahmad
Ahmad am 3 Feb. 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?

Kategorien

Mehr zu Interactive Control and Callbacks finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by