How to use ginput with live video?
2 次查看(过去 30 天)
显示 更早的评论
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 个评论
采纳的回答
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.
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Data Exploration 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!