% 2018-01-03 created by 一湾清水
% 人脸识别
% 需要下载OS Generic Video Interface工具包
vidDevice = imaq.VideoDevice('winvideo', 1, 'MJPG_320x240', ...
'ROI', [1 1 320 240], ...
'ReturnedColorSpace', 'rgb', ...
'DeviceProperties.Brightness', 8, ...
'DeviceProperties.Sharpness', 8);
hVideoIn = vision.VideoPlayer;
hVideoIn.Name = 'Input Video';
hVideoOut = vision.VideoPlayer;
hVideoOut.Name = 'Output Video';
faceDetector = vision.CascadeObjectDetector();
pointTracker = vision.PointTracker('MaxBidirectionalError', 2);
numPts = 0;
while 1
videoFrame = step(vidDevice);
videoFrameOutput = videoFrame;
videoFrameGray = rgb2gray(videoFrame);
if numPts < 10
% Detection mode.
bbox = faceDetector.step(videoFrameGray);
if ~isempty(bbox)
% Find corner points inside the detected region.
points = detectMinEigenFeatures(videoFrameGray, 'ROI', bbox(1, :));
% Re-initialize the point tracker.
xyPoints = points.Location;
numPts = size(xyPoints,1);
release(pointTracker);