我正在U.I中显示鼠标的视频,我有一个文件,其头部的坐标随着时间的推移而变化。我想使用标记为每个帧显示头部的位置。
这是我实际做的事情:
% --- Get the current frame, display it and set axes properties
setDirectory(handles.video,handles.numFrame);
I = handles.video.read();
imagesc(I,'Parent',handles.axes1);
hold on
plot(handles.xHead(handles.numFrame),handles.yHead(handles.numFrame),...
'o','MarkerFaceColor','b','MarkerSize',10,'Parent',handles.axes1);
colormap(gray);
handles.axes1.Visible = 'off';
drawnow
hold off
问题是它只显示视频,当我暂停进程时(带回调按钮),它只显示没有当前帧的点......
我环顾四周但却一无所获。任何帮助将是欣赏:))谢谢!
编辑:
这里是button_callback按钮的代码:
% --- Executes on button press in play.
function play_Callback(hObject, ~, handles)
% hObject handle to play (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% --- Inverse the value of the button Play/Pause when it is clicked
if strcmp(hObject.String,'Play')
hObject.String = 'Pause';
else
hObject.String = 'Play';
end
% --- Algorithm to read the video and graphics
while strcmp(hObject.String,'Pause')
% --- Get the way of reading of the video
handles.sens = get(handles.listbox3, 'Value');
if handles.sens == 1
% Go forward
handles.defilement = 1;
elseif handles.sens == 2
% Go back
handles.defilement = -1;
end
% --- Get the speed of the video
tPause = get(handles.edit2,'String');
tPause = str2num(tPause);
if isempty(tPause)
set(handles.edit2,'String','1');
warndlg('Vous devez entrer une valeur num�rique non nulle !');
elseif tPause ~= handles.speedBase
handles.speedBase = tPause;
end
% --- Check if there is still a frame in the video
if handles.numFrame > 0 && handles.numFrame < (handles.nbrFrames + 1)
% --- Get the current frame, display it and set axes properties
setDirectory(handles.video,handles.numFrame);
I = handles.video.read();
imagesc(I,'Parent',handles.axes1);
colormap(gray);
handles.axes1.Visible = 'off';
pause(0.001);
% --- Assign the new position of the marker
handles.xMV = handles.numFrame;
handles.yMV = handles.yGV(handles.xMV);
handles.xMR = handles.numFrame;
handles.yMR = handles.yGR(handles.xMR);
handles.xMRat = handles.numFrame;
handles.yMRat = handles.yGRat(handles.xMRat);
if handles.angle.Value==1
handles.xMAng = handles.numFrame;
handles.yMAng = handles.yGAng(handles.xMAng);
end
% --- Assign the new scale for Y
if mod(handles.numFrame,(handles.ecart/10)) == 0 && handles.autoscale.Value == 1
[handles.YminV, handles.YmaxV] = autoscale(handles.yGVsmooth,handles.ecart,handles.numFrame,handles.nbrFrames);
handles.yminV.String = handles.YminV;
handles.ymaxV.String = handles.YmaxV;
[handles.YminR, handles.YmaxR] = autoscale(handles.yGRsmooth,handles.ecart,handles.numFrame,handles.nbrFrames);
handles.yminR.String = handles.YminR;
handles.ymaxR.String = handles.YmaxR;
[handles.YminRat, handles.YmaxRat] = autoscale(handles.yGRat,handles.ecart,handles.numFrame,handles.nbrFrames);
handles.yminRat.String = handles.YminRat;
handles.ymaxRat.String = handles.YmaxRat;
if handles.angle.Value==1
[handles.YminAng, handles.YmaxAng] = autoscale(handles.yGAng,handles.ecart,handles.numFrame,handles.nbrFrames);
handles.yminAng.String = handles.YminAng;
handles.ymaxAng.String = handles.YmaxAng;
disp(handles.YminAng);
disp(handles.YmaxAng);
end
end
% --- Refresh graphics
if handles.numFrame < handles.ecart
% --- Display the graphics
% Graph of red fluorescence
plot(handles.xGV(1:(handles.ecart*2)),handles.yGV(1:(handles.ecart*2)),...
handles.xMV,handles.yMV,'o','MarkerFaceColor','r','MarkerSize',3, ...
'Color','g','Parent',handles.axes2);
% Graph of green fluorescence
plot(handles.xGR(1:(handles.ecart*2)),handles.yGR(1:(handles.ecart*2)),...
handles.xMR,handles.yMR,'o','MarkerFaceColor','g','MarkerSize',3, ...
'Color','r','Parent',handles.axes3);
% Graph of ratio
plot(handles.xGRat(1:(handles.ecart*2)),handles.yGRat(1:(handles.ecart*2)),...
handles.xMRat,handles.yMRat,'o','MarkerFaceColor','g','MarkerSize',3, ...
'Color','b','Parent',handles.axes4);
% Graph of the angle
if handles.angle.Value==1
plot(handles.xGAng(1:(handles.ecart*2)),handles.yGAng(1:(handles.ecart*2)),...
handles.xMAng,handles.yMAng,'o','MarkerFaceColor','g','MarkerSize',3, ...
'Color','y','Parent',handles.axes6);
set(handles.axes6,'xLim',[1 (handles.ecart*2)],'yLim',[handles.YminAng handles.YmaxAng]);
set(handles.axes6.Title,'String','Angle');
end
% --- Set the properties of the axis
% Graph of red fluorescence
set(handles.axes2,'xLim',[1 (handles.ecart*2)],'yLim',[handles.YminV handles.YmaxV]);
set(handles.axes2.Title,'String','Fluorescence Verte');
% Graph of green fluorescence
set(handles.axes3,'xLim',[1 (handles.ecart*2)],'yLim',[handles.YminR handles.YmaxR]);
set(handles.axes3.Title,'String','Fluorescence Rouge');
% Graph of ratio
set(handles.axes4,'xLim',[1 (handles.ecart*2)],'yLim',[handles.YminRat handles.YmaxRat]);
set(handles.axes4.Title,'String','Ratio');
elseif handles.numFrame > handles.ecart && handles.numFrame < (handles.nbrFrames - handles.ecart-1)
% --- Display the graph and the marker and make the graph dynamic
% Graph of red fluorescence
plot(handles.xGV((handles.numFrame-handles.ecart):(handles.numFrame+handles.ecart)), ...
handles.yGV((handles.numFrame-handles.ecart):(handles.numFrame+handles.ecart)),...
handles.xMV,handles.yMV,'o','MarkerFaceColor','r','MarkerSize',3, ...
'Color','g','Parent',handles.axes2);
% Graph of green fluorescence
plot(handles.xGR((handles.numFrame-handles.ecart):(handles.numFrame+handles.ecart)), ...
handles.yGR((handles.numFrame-handles.ecart):(handles.numFrame+handles.ecart)),...
handles.xMR,handles.yMR,'o','MarkerFaceColor','g','MarkerSize',3, ...
'Color','r','Parent',handles.axes3);
% Graph of ratio
plot(handles.xGRat((handles.numFrame-handles.ecart):(handles.numFrame+handles.ecart)), ...
handles.yGRat((handles.numFrame-handles.ecart):(handles.numFrame+handles.ecart)),...
handles.xMRat,handles.yMRat,'o','MarkerFaceColor','g','MarkerSize',3, ...
'Color','b','Parent',handles.axes4);
if handles.angle.Value==1
plot(handles.xGAng((handles.numFrame-handles.ecart):(handles.numFrame+handles.ecart)), ...
handles.yGAng((handles.numFrame-handles.ecart):(handles.numFrame+handles.ecart)),...
handles.xMAng,handles.yMAng,'o','MarkerFaceColor','g','MarkerSize',3, ...
'Color','b','Parent',handles.axes6);
set(handles.axes6,'xLim',[(handles.numFrame-handles.ecart) (handles.numFrame+handles.ecart-1)],...
'yLim',[handles.YminAng handles.YmaxAng]);
set(handles.axes6.Title,'String','Angle');
end
% --- Set the properties of the axis
% Graph of red fluorescence
set(handles.axes2,'xLim',[(handles.numFrame-handles.ecart) (handles.numFrame+handles.ecart-1)],...
'yLim',[handles.YminV handles.YmaxV]);
set(handles.axes2.Title,'String','Fluorescence Verte');
% Graph of green fluorescence
set(handles.axes3,'xLim',[(handles.numFrame-handles.ecart) (handles.numFrame+handles.ecart-1)],...
'yLim',[handles.YminR handles.YmaxR]);
set(handles.axes3.Title,'String','Fluorescence Rouge');
% Graph of ratio
set(handles.axes4,'xLim',[(handles.numFrame-handles.ecart) (handles.numFrame+handles.ecart-1)],...
'yLim',[handles.YminRat handles.YmaxRat]);
set(handles.axes4.Title,'String','Ratio');
elseif handles.numFrame > (handles.nbrFrames - handles.ecart)
% --- Display the graph and the marker
% Graph of red fluorescence
plot(handles.xGV((handles.nbrFrames-(handles.ecart*2)):handles.nbrFrames-1), ...
handles.yGV((handles.nbrFrames-(handles.ecart*2)):handles.nbrFrames-1),...
handles.xMV,handles.yMV,'o','MarkerFaceColor','r','MarkerSize',3, ...
'Color','g','Parent',handles.axes2);
% Graph of green fluorescence
plot(handles.xGR((handles.nbrFrames-(handles.ecart*2)):handles.nbrFrames-1), ...
handles.yGR((handles.nbrFrames-(handles.ecart*2)):handles.nbrFrames-1),...
handles.xMR,handles.yMR,'o','MarkerFaceColor','g','MarkerSize',3, ...
'Color','r','Parent',handles.axes3);
% Graph of ratio
plot(handles.xGRat((handles.nbrFrames-(handles.ecart*2)):handles.nbrFrames-1), ...
handles.yGRat((handles.nbrFrames-(handles.ecart*2)):handles.nbrFrames-1),...
handles.xMRat,handles.yMRat,'o','MarkerFaceColor','g','MarkerSize',3, ...
'Color','b','Parent',handles.axes4);
if handles.angle.Value==1
plot(handles.xGAng((handles.nbrFrames-(handles.ecart*2)):handles.nbrFrames-1), ...
handles.yGAng((handles.nbrFrames-(handles.ecart*2)):handles.nbrFrames-1),...
handles.xMAng,handles.yMAng,'o','MarkerFaceColor','g','MarkerSize',3, ...
'Color','b','Parent',handles.axes6);
set(handles.axes6,'xLim',[((handles.nbrFrames-1)-(handles.ecart*2)) handles.nbrFrames],...
'yLim',[handles.YminAng handles.YmaxAng]);
set(handles.axes6.Title,'String','Angle');
end
% --- Set the properties of the axis
% Graph of red fluorescence
set(handles.axes2,'xLim',[((handles.nbrFrames-1)-(handles.ecart*2)) handles.nbrFrames],...
'yLim',[handles.YminV handles.YmaxV]);
set(handles.axes2.Title,'String','Fluorescence Verte');
% Graph of green fluoresence
set(handles.axes3,'xLim',[((handles.nbrFrames-1)-(handles.ecart*2)) handles.nbrFrames],...
'yLim',[handles.YminR handles.YmaxR]);
set(handles.axes3.Title,'String','Fluorescence Rouge');
% Graph of ratio
set(handles.axes4,'xLim',[((handles.nbrFrames-1)-(handles.ecart*2)) handles.nbrFrames],...
'yLim',[handles.YminRat handles.YmaxRat]);
set(handles.axes4.Title,'String','Ratio');
end
% --- Manage the speed of the video
pause(tPause);
% --- Conditions whiwh prevent to assign a wrong value to
% --- handles.numFrame
if handles.numFrame == 1 && handles.sens == 1
handles.numFrame = handles.numFrame + handles.defilement;
elseif handles.numFrame > 1 && handles.numFrame < handles.nbrFrames
handles.numFrame = handles.numFrame + handles.defilement;
elseif handles.numFrame == handles.nbrFrames && handles.sens == 2
handles.numFrame = handles.numFrame + handles.defilement;
end
end
% --- Refresh the UI
set(handles.text14,'String',handles.numFrame);
% --- Manage the case we went back to the beginning
if handles.numFrame == 1 && handles.sens == 2
if strcmp(hObject.String,'Pause')
% reset status of the button
hObject.String = 'Play';
end
break
end
% --- Manage the case we arrived to the end of the video
if handles.numFrame == handles.nbrFrames
if strcmp(hObject.String,'Pause')
% reset status of the button
hObject.String = 'Play';
end
break
end
end
% Update handles structure
guidata(hObject,handles);
请原谅我的缩进不好但是我不知道如何在堆栈溢出中快速解决它。
答案 0 :(得分:0)
这个问题与matlab如何使用事件队列以及drawow如何影响这些队列有关。我会试试
drawow曝光
这应该立即更新图形,而不允许事件队列中已有的其他回调在更新之前进行处理。