萌新求解,希望各位帮我注释一下下面程序的意思

xjiuyuan 2020-02-25 04:07:21
clc;
clear all;
close all;

filename = 'people_net.mp4';
video = VideoReader(filename);
player = vision.DeployableVideoPlayer('FrameRate', 30);
for cnt = 30 : video.NumFrames - 20
img = read(video, cnt);
prev_img = read(video, cnt - 1);

height = size(img,1);
width = size(img,2);

out = img;
bin = zeros(height,width);
diff = rgb2gray(img) - rgb2gray(prev_img);
diff = abs(diff);
level = graythresh(diff);
diff_bin = im2bw(diff, level);
diff_dilate = imdilate(diff_bin, strel('rectangle', [10, 10]));

img_ycbcr = rgb2ycbcr(img);
Y = img_ycbcr(:,:,1);
Cb = img_ycbcr(:,:,2);
Cr = img_ycbcr(:,:,3);

target = Y >= 100 & Y <=150 & Cb >= 109 & Cb <= 110 & Cr >= 149 & Cr <= 150 & diff_dilate;
%target = Cb >= 108 & Cb <= 113 & Cr >= 145 & Cr <= 153 & diff_close;
[r,c,v] = find(target);
numind = size(r,1);

for i=1:numind
out(r(i),c(i),:) = [0 0 255];
bin(r(i),c(i)) = 1;
end

[x1,y1] = find(out(:,:,3) == 255, 1,'first');
[x2,y2] = find(out(:,:,3) == 255, 1, 'last');
if isempty(y1) && isempty(y2)
y1 = 2; y2 = 0;
end

hits = 0;
hitsArr = zeros(1,height);
for i = 1:height
hits = numel(find(bin(i,:) == 1));
hitsArr(i) = hits;
end
maxHitr = max(hitsArr);
y = find(hitsArr == maxHitr,1,'first');
hitsArr = zeros(1,width);
for i = 1:width
hits = numel(find(bin(:,i) == 1));
hitsArr(i) = hits;
end
maxHitc = max(hitsArr);
x = find(hitsArr == maxHitc,1,'first');
label = 'Hand';
position = [x y abs(y2-y1)/7; x y 1];

param = getDefaultParameters();
initialLocation = computeInitialLocation(param, position);
img_out = insertObjectAnnotation(img, 'Circle', position,label);
step(player, img_out);
end
release(player);

function param = getDefaultParameters
param.motionModel = 'ConstantAcceleration';
param.initialLocation = 'Same as first detection';
param.initialEstimateError = 1E5 * ones(1, 3);
param.motionNoise = [25, 10, 1];
param.measurementNoise = 25;
param.segmentationThreshold = 0.05;
end

function loc = computeInitialLocation(param, detectedLocation)
if strcmp(param.initialLocation, 'Same as first detection')
loc = detectedLocation;
else
loc = param.initialLocation;
end
end
...全文
115 回复 打赏 收藏 转发到动态 举报
写回复
用AI写文章
回复
切换为时间正序
请发表友善的回复…
发表回复

256

社区成员

发帖
与我相关
我的任务
社区描述
其他产品/厂家
社区管理员
  • 其他
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧