Reputation: 13683
I'm building a smile detection system, and I need to plot the probability of smile (from video input) like the graphs on the right in this video.
How can I do this in MATLAB?
I'm currently displaying the video frames with OpenCV & IntraFace default code, which looks something like this :
cf = 0; % Current Frame.
% create a figure to draw upon
S.fh = figure('units','pixels',...
'position',[100 150 frame_w frame_h],...
'menubar','none',...
'name','Smile Detector',...
'numbertitle','off',...
'resize','off',...
'renderer','painters');
% create axes
S.ax = axes('units','pixels',...
'position',[1 1 frame_w frame_h],...
'drawmode','fast');
set(S.fh,'KeyPressFcn',@pb_kpf);
S.im_h = imshow(zeros(frame_h,frame_w,3,'uint8'));
hold on;
S.frame_h = text(50,frame_h-50,['Frame ' int2str(cf)] , 'fontsize', 15, 'Color' , 'c');
while true && ~stop_pressed
tic;
im = cap.read;
cf = cf + 1;
if isempty(im),
warning('EOF');
break ;
end
set(S.im_h,'cdata',im); % update frame
set(S.frame_h , 'string' ,['Frame ' int2str(cf)]);
do_something_with_frame(im);
if isempty(output.pred) % if lost/no face, delete all drawings
if drawed, delete_handlers(); end
else % face found
update_GUI();
end
drawnow;
end
close;
end
And I want to add a live / moving graph like in the video. The graph will display a single value (a probability) between 0 and 1. And it should be updated with every new frame, therefore the plot should "flow" as the video flows.
I tried creating a new figure just like S
in the code. But I cannot plot into it. I am also ok with adding the live graph in the same figure (S.fh
), preferrably under the scene.
Upvotes: 1
Views: 1507
Reputation: 808
Using linkdata and refreshdata will refresh a graph plot as you have new data.
%some pretend data
pX1 = rand;
pX2 = 1-pX1;
p = [pX1,pX2];
bar(p)
%link the data to the plot
linkdata on
for i=1:100
pX1 = rand;
pX2 = 1-pX1;
p = [pX1,pX2];
%refresh the linked data and draw
refreshdata
drawnow
end
http://www.mathworks.co.uk/help/matlab/ref/linkdata.html
Hope it helps...
Upvotes: 1