How to use ginput with live video?

3 views (last 30 days)
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

Accepted Answer

Joseph Cheng
Joseph Cheng on 24 Mar 2016
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 Comments
Mark Golberg
Mark Golberg on 29 Mar 2016
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

Sign in to comment.

More Answers (0)

Categories

Find more on Graphics Performance in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!