handles.pointTracker = vision.PointTracker('MaxBidirectionalError',2);% Create the point tracker object.
videoFrameGray = rgb2gray(videoFrame);bbox =handles.faceDetector.step(videoFrameGray);% Detection mode.
if ~isempty(bbox)points =detectMinEigenFeatures(videoFrameGray, 'ROI', bbox(1, : );% Find corner pointsinside the detected region.
% Re-initialize thepoint tracker.
xyPoints =points.Location;
numPts =size(xyPoints,1);
release(handles.pointTracker);
initialize(handles.pointTracker, xyPoints, videoFrameGray);
oldPoints = xyPoints;%Save a copy of the points.
% Convert therectangle represented as [x, y, w, h] into an
% M-by-2 matrix of[x,y] coordinates of the four corners. This
% is needed to be ableto transform the bounding box to display
% the orientation ofthe face.
bboxPoints =bbox2points(bbox(1, : );
% Convert the boxcorners into the [x1 y1 x2 y2 x3 y3 x4 y4]
bboxPolygon =reshape(bboxPoints', 1, []);% format required by insertShape.
% Display a boundingbox around the detected face.
videoFrame =insertShape(videoFrame, 'Polygon', bboxPolygon, 'LineWidth', 3);
videoFrame =insertMarker(videoFrame, xyPoints, '+', 'Color', 'white');% Display detectedcorners.
end[xyPoints, isFound] =step(handles.pointTracker, videoFrameGray);
visiblePoints =xyPoints(isFound, : );
oldInliers =oldPoints(isFound, : );
numPts =size(visiblePoints, 1);
% Estimate thegeometric transformation between the old points
% and the new points.[xform, oldInliers,visiblePoints] = estimateGeometricTransform(oldInliers, visiblePoints,'similarity', 'MaxDistance', 4);
bboxPoints =transformPointsForward(xform, bboxPoints);% Apply the transformation to thebounding box.
% Convert the boxcorners into the [x1 y1 x2 y2 x3 y3 x4 y4]
% format required byinsertShape.
bboxPolygon =reshape(bboxPoints', 1, []);
videoFrame =insertShape(videoFrame, 'Polygon', bboxPolygon, 'LineWidth', 3);% Display abounding box around the face being tracked.
videoFrame =insertMarker(videoFrame, visiblePoints, '+', 'Color', 'white');% Displaytracked points.
oldPoints =visiblePoints;
setPoints(handles.pointTracker, oldPoints);
endfs =str2num(handles.sf_tag.String);%sample frequency
handles.setTimerFunc =timer('Period',1/fs,'ExecutionMode','fixedRate');%peroid
set(handles.setTimerFunc,'TimerFcn',{@faceDectAndTrackFunc,handles});%timerexecution function
start(handles.setTimerFunc);turnOffScreenFlag =turnOffScreenFlag + 1;
endsystem('c:\windows\system32\Ribbons.scr /s');%turn off screen
% system('c:\windows\system32\rundll32.exeuser32.dll,LockWorkStation');%shut down screen
end欢迎光临 52matlab技术网站,matlab教程,matlab安装教程,matlab下载 (http://www.52matlab.com/) | Powered by Discuz! X3.2 |