필터 지우기
필터 지우기

Can I choose point with mouse from video?

조회 수: 3 (최근 30일)
Ahmad
Ahmad 2015년 2월 1일
답변: Ahmad 2015년 2월 3일
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