运动物体检测匹配matlab,运动目标检测与跟踪算法

clc;

clear;

nin = 10;

ratio = 1.2;

fprintf('TrainSampleMatData production BEGIN...\n');

posTrainSampleImageDirectory = 'C:\Users\Administrator\Desktop\hog+svm_行人检测matlab程序\hog+svm 行人检测matlab程序\posdata';

negTrainSampleImageDirectory = 'C:\Users\Administrator\Desktop\hog+svm_行人检测matlab程序\hog+svm 行人检测matlab程序\negdata';

pathPosName = [posTrainSampleImageDirectory, '/*.png'];                    %  '/*.png'是什么意思呢!有什么用?

readPosList = dir(pathPosName);

[mpos, n] = size(readPosList);

pathNegName1 = [negTrainSampleImageDirectory, '/*.jpg'];                   % 这一句和下一句又是什么意思呢!

pathNegName2 = [negTrainSampleImageDirectory, '/*.png'];

readNegList1 = dir(pathNegName1);

readNegList2 = dir(pathNegName2);

readNegList = [readNegList1; readNegList2];

[mneg, n] = size(readNegList);

hog_train_data = zeros(mpos+nin*mneg, 3780);                               %下边四句没怎么看懂!为什么neg的数量要乘以nin?

hog_train_label = zeros(mpos+nin*mneg,1);

hog_train_label(1:mpos,:) = 1;

hog_train_label(mpos+1:mpos+nin*mneg,:) = -1;

fprintf('total PosTrainSampleImages number: %d\n', mpos);

%训练正样本

for i=1:mpos

fprintf('generating NO.%d Pos image HOG feature...', i);

imageName = readPosList(i,1).name;                                     %.name是什么啊?

pathPosName = [posTrainSampleImageDirectory, '/', imageName];

image = imread(pathPosName);

% image = image(17:64,17:128,:);                                         %这句是什么意思呢?

hog_train_data(i,:) = hogcalculator(image);

fprintf(' finished\n');

end

maxScaleNum=8;

fprintf('total NegTrainSampleImages number: %d\n', mneg);

%训练负样本

w = 64;

h = 128;

k = 0;

for i=1:mneg

imageName = readNegList(i,1).name;

pathNegName = [negTrainSampleImageDirectory, '/', imageName];

image = imread(pathNegName);

[imgHeight,imgWidth, imgnChannels] = size(image);

newMaxScaleNum = min(floor(log(imgHeight/h)/(log(ratio))),floor(log(imgWidth/w)/log(ratio)));      %这是在做什么呢?

if newMaxScaleNum > maxScaleNum

newMaxScaleNum = maxScaleNum;

end

scale_num = 1+(newMaxScaleNum-1)*rand();

image = imresize(image,1/(ratio^scale_num));

[imgHeight,imgWidth, imgnChannels] = size(image);

xmax = imgWidth - w + 1;

ymax = imgHeight - h + 1;

for j = 1:nin

k = k+1;

fprintf('generating NO.%d sample HOG feature in NO.%d Neg image...', j, i);

x = floor(rand(1)*xmax);                                            %这几句是在干什么啊?

y = floor(rand(1)*ymax);

if x == 0

x = x+1;

end

if y == 0

y = y+1;

end

sampleImage = image(y:(y+h-1),x:(x+w-1),:);                         %sampleImage = image(y:(y+h-1),x:(x+w-1),:);是什么意思呢?为什么要这么做呢

hog_train_data(mpos+k,:) = hogcalculator(image);

fprintf(' finished\n');

end

end

save HOG_TRAIN_DATA.mat hog_train_data;

save HOG_TRAIN_LABEL.mat hog_train_label;

clear;

fprintf('TrainSampleMatData production END...\n');

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值