人脸识别 matlab中文论坛,人脸识别追踪完整代码

本帖最后由 eeshin 于 2015-8-8 15:13 编辑

就是官网上的代码,希望和刚入门的朋友一起学习!

% Read a video frame and run the detector.

videoFileReader = vision.VideoFileReader('visionface.avi');

videoFrame      = step(videoFileReader);

bbox            = step(faceDetector, videoFrame);

% Draw the returned bounding box around the detected face.

boxInserter  = vision.ShapeInserter('BorderColor','Custom',...

'CustomBorderColor',[255 255 0]);

videoOut = step(boxInserter, videoFrame,bbox);

figure, imshow(videoOut), title('Detected face');% Get the skin tone information by extracting the Hue from the video frame

% converted to the HSV color space.

[hueChannel,~,~] = rgb2hsv(videoFrame);

% Display the Hue Channel data and draw the bounding box around the face.

figure, imshow(hueChannel), title('Hue channel data');

rectangle('Position',bbox(1,:),'LineWidth',2,'EdgeColor',[1 1 0])

% Detect the nose within the face region. The nose provides a more accurate

% measure of the skin tone because it does not contain any background

% pixels.

noseDetector = vision.CascadeObjectDetector('Nose', 'UseROI', true);

noseBBox     = step(noseDetector, videoFrame, bbox(1,:));

% Create a tracker object.

tracker = vision.HistogramBasedTracker;

% Initialize the tracker histogram using the Hue channel pixels from the

% nose.

initializeObject(tracker, hueChannel, noseBBox(1,:));

% Create a video player object for displaying video frames.

videoInfo    = info(videoFileReader);

videoPlayer  = vision.VideoPlayer('Position',[300 300 videoInfo.VideoSize+30]);

% Track the face over successive video frames until the video is finished.

while ~isDone(videoFileReader)

% Extract the next video frame

videoFrame = step(videoFileReader);

% 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');

% Display the annotated video frame using the video player object

step(videoPlayer, videoOut);

end

% Release resources

release(videoFileReader);

release(videoPlayer);

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值