How to use ginput with live video?
2 views (last 30 days)
Show older comments
Mark Golberg
on 24 Mar 2016
Commented: Mark Golberg
on 29 Mar 2016
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
0 Comments
Accepted Answer
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.
More Answers (0)
See Also
Categories
Find more on Data Exploration 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!