How to use ginput with live video?
조회 수: 1 (최근 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에서 Graphics Performance에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!