eyeDetector =愿景。CascadeObjectDetector (“EyePairBig”);
pointTracker =愿景。PointTracker (“MaxBidirectionalError”2);
凸轮=摄像头();
videoFrame =快照(cam);
frameSize =大小(videoFrame);
放像机=愿景。放像机(“位置”, [100 100 [frameSize(2), frameSize(1)]+30]);
runLoop = true;
numPts = 0;
frameCount = 0;
而runLoop && frameCount < 400
videoFrame =快照(cam);
videoFrameGray = rgb2gray (videoFrame);
frameecount = frameecount + 1;
如果numPts < 10
bboxeye = eyeDetector.step (videoFrameGray);
如果~ isempty (bboxeye)
点= detectMinEigenFeatures (videoFrameGray,“投资回报”bboxeye (:));
xyPoints = points.Location;
numPts =大小(xyPoints, 1);
释放(pointTracker);
初始化(pointTracker xyPoints videoFrameGray);
oldPoints = xyPoints;
bboxPoints = bbox2points(bboxeye(1,:)));
bboxPolygon =重塑(bboxPoints', 1, []);
videoFrame = insertShape (videoFrame,“多边形”bboxPolygon,“线宽”3);
= insertMarker(videoFrame, xyPoints,)“+”,“颜色”,“白色”);
结束
其他的
[xyPoints, isFound] = step(pointTracker, videoFrameGray);
visiblePoints = xyPoints(isFound,:);
olddinliers = oldPoints(isFound,:);
numPts = size(visiblePoints, 1); / /显示时间
如果numPts > = 10
[xform, inlierIdx] = estimateGeometricTransform2D(...
oldInliers visiblePoints,“相似”,“MaxDistance”4);
oldInliers = oldInliers(inlierIdx,:); / / / / / /
visiblePoints = visiblePoints(inlierIdx,:);
bboxPoints = transformpointforward (xform, bboxPoints);
bboxPolygon =重塑(bboxPoints', 1, []);
videoFrame = insertShape (videoFrame,“多边形”bboxPolygon,“线宽”3);
videoFrame = insertMarker(videoFrame, visiblePoints,“+”,“颜色”,“白色”);
oldPoints = visiblePoints;
选点(pointTracker oldPoints);
结束
结束
步骤(放像机、videoFrame);
runLoop = isOpen(放像机);
结束
清晰的凸轮;
释放(放像机);
释放(pointTracker);
释放(eyeDetector);