필터 지우기
필터 지우기

How to use ginput with live video?

조회 수: 3 (최근 30일)
Mark Golberg
Mark Golberg 2016년 3월 24일
댓글: Mark Golberg 2016년 3월 29일
Hello, I have the following code:
x = [];
while ishandle(h)
if isempty(x) == 1
imagesc(baslerGetData(baslerID,1)); %my function which captures 1 frame from my BASLER camera
colormap(gray);
axis off
drawnow
[x,y] = ginput(1);
else
break
end
end
I want to have live video in my figure, and then when some location is selected with ginput the loop should break. Problem is that once ginput is initiated everything stops until I press the mouse, so I lose the frames refreshing.
Any ideas for a workaround?
THANK YOU

채택된 답변

Joseph Cheng
Joseph Cheng 2016년 3월 24일
I don't really think ginput() would be the best function to use. why not something like
%%live video answers example
function livevideexample()
hfig = figure(1); %gen figure handles
set(hfig,'windowButtonDownFcn',@clicker) %set button down function to clicker (see below)
hfig.UserData=1; %use userdata as a flag.
while hfig.UserData
imagesc(randi(256,512,512)); %my fake basler camera live feed
drawnow, pause(.1) %just here so i can see a "live" feed
end
%what happens when you click on the figure
function clicker(hobject,event)
whichbutton=get(hobject, 'selectiontype'); %this gets what button was pressed
where=get(hobject, 'currentpoint');
switch whichbutton % if anything really but i put this here anyways
case 'normal' %left mouse click
hobject.UserData=0; %set the object's user data to 0 (ie 0 for live feed)
case 'alt' %right mouse click
hobject.UserData=0;
case 'extended' %middle? mouse click
hobject.UserData=0;
end
now this is going to get the click in the figure (not the axis). but i've run out of time so i'll let you figure out how to use my "where" variable to get figure xy and compare it to axis position or do a quick search on how to determine what point in an image is collected by buttondownfunction.
  댓글 수: 3
Mark Golberg
Mark Golberg 2016년 3월 29일
Thank you Walter. As my mission to determine where inside my axes the mouse was clicked, in scaling of the axes I thought of the following procedure:
1. get axes position inside my figure
2. get mouseClick position inside my axis
3. scale result from section 2 (in pixel units) to axes limits (my axes are linear).
so for example, if my XLim = [0 800], then pressing somewhere in the middle of the axes would return mouseClick_X = 400.
Does my logic sounds ok?
THANK YOU

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Graphics Performance에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by