clc;
clear;
close all;
warning off;
addpath(genpath(pwd));
%****************************************************************************
%更多关于matlab和fpga的搜索“fpga和matlab”的CSDN博客:
%matlab/FPGA项目开发合作
%https://blog.csdn.net/ccsss22?type=blog
%****************************************************************************
% Open video file
videoFileReader = vision.VideoFileReader('MWface.avi');
% Read video frame
videoFrame = step(videoFileReader);
% Detect the face
faceDetector = vision.CascadeObjectDetector('MaxSize',[150 150]);
faceBBox = step(faceDetector,videoFrame);
% Display results
figure; subplot(1,2,1);imshow(videoFrame); hold on;
rectangle('Position',faceBBox(1,:),'LineWidth',2,'EdgeColor',[1 1 0])
[hueChannel,~,~] = rgb2hsv(videoFrame);
subplot(1,2,2);imshow(hueChannel);hold on;
rectangle('Position',faceBBox(1,:),'LineWidth',2,'EdgeColor',[0 1 0])
%% Find a better object for tracking
% Detect the nose
noseDetector = vision.CascadeObjectDetector('Nose');
noseBBox = step(noseDetector,videoFrame);
% Display results
figure; subplot(1,2,1);imshow(videoFrame); hold on;
rectangle('Position',noseBBox(1,:),'LineWidth',2,'EdgeColor',[1 1 0])
subplot(1,2,2); imshow(hueChannel); hold on;
rectangle('Position',noseBBox(1,:),'LineWidth',2,'EdgeColor',[0 1 0])
%% Set up tracking loop
% Create a tracker object.
tracker = vision.HistogramBasedTracker;
% Initialize the tracker histogram
initializeObject(tracker, hueChannel, noseBBox(1,:));
% figure;bar(tracker.ObjectHistogram);
%%
% Create a video player object for displaying video frames.
videoInfo = info(videoFileReader);
videoPlayer = vision.VideoPlayer('Position',[300 300 videoInfo.VideoSize+30]);
boxInserter = vision.ShapeInserter('BorderColor','Custom',...
'CustomBorderColor',[255 255 0]);
% Track the face over successive video frames until the video is finished.
while ~isDone(videoFileReader)
videoFrame = step(videoFileReader); % Extract the next video frame
[hueChannel,~,~] = rgb2hsv(videoFrame); % RGB -> HSV
% Track using the Hue channel data
[bbox, ~, score] = step(tracker, hueChannel);
% Insert a bounding box around the object being tracked
videoOut = step(boxInserter, videoFrame, bbox);
% Display the annotated video frame using the video player object
step(videoPlayer, videoOut);
end
%% Now try to reacquire the face when it reappears
release(tracker);
reset(videoPlayer);
initializeObject(tracker, hueChannel, noseBBox(1,:));
% Track the face over successive video frames until the video is finished.
reset(videoFileReader);
while ~isDone(videoFileReader)
videoFrame = step(videoFileReader); % Extract the next video frame
[hueChannel,~,~] = rgb2hsv(videoFrame); % RGB -> HSV
% Track using the Hue channel data
[bbox, ~, score] = step(tracker, hueChannel);
% Determine if face is still in the scene using score value
if score > 0.4
videoOut = step(boxInserter, videoFrame, bbox);
else
videoOut = videoFrame;
faceBBox = step(faceDetector,videoFrame); % Find face again
if ~isempty(faceBBox)
release(noseDetector);
noseBBox = step(noseDetector,imcrop(videoFrame,faceBBox(1,:)));
noseBBox(1:2) = noseBBox(1:2) + faceBBox(1:2);
release(tracker);
initializeObject(tracker, hueChannel, noseBBox(1,:));
end
end
% Display the annotated video frame using the video player object
step(videoPlayer, videoOut);
end
% Release resources
release(videoFileReader);
release(videoPlayer);
matlab-基于直方图跟踪的人脸检测和跟踪matlab仿真-源码
版权申诉
42 浏览量
2021-09-19
20:47:43
上传
评论
收藏 6.12MB RAR 举报
mYlEaVeiSmVp
- 粉丝: 1858
- 资源: 19万+
最新资源
- React项目基于JavaScript实现的全球新闻发布管理系统源码.zip
- 基于keras+fasterRCNN,在VOC格式的口罩数据集上训练,检测人群中有无戴口罩python源码+模型
- 基于opencv+qt5机器视觉的传统缺陷检测, 即采用标准图片和待测图片进行pixel to pixel的XOR操作源码+文档
- 管道内检测缺陷数据库管理系统源码+文档说明+sln
- 毕业设计-低功耗STM32F411开发板(原理图+PCB源文件+官方例程+驱动等)源码+文档说明+截图
- 基于yolov5-tensorRT检测+发动机缸体内壁缺陷检测系统源码+文档说明
- 基于C++实现的锂电池缺陷检测源码+文档说明
- push_version
- 软件自制图像批量压缩工具
- 经典缺陷检测算法源码整理包含PaDiM(2020ICPR)、PatchCore(2022CVPR)、SimpleNet+文档说明
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈