Professional Documents
Culture Documents
% Track the face over successive video frames until the video is finished.
%You could set here a finite number of frames to capture
while 1
% Extract the next video frame
videoFrame = step(vidDevice);
% RGB -> HSV
[hueChannel,~,~] = rgb2hsv(videoFrame);
% Track using the Hue channel data
bbox = step(tracker, hueChannel);
% Insert a bounding box around the object being tracked
videoOut = insertObjectAnnotation(videoFrame,'rectangle',bbox,'Face');
%Insert text coordinates
text = ['x: ',num2str(bbox(1)),' y: ',num2str(bbox(2)),' Width: ',num2str(bbox(3)), ' Height:
',num2str(bbox(4))];
textInserter = vision.TextInserter(text,'Color', textColor, 'FontSize', 12, 'Location', textLocation);
videoOut = step(textInserter,videoOut);
% Display the annotated video frame using the video player object
step(videoPlayer, videoOut);
end
% Release resources
release(vidDevice);
release(videoPlayer);
end