使用训练数据训练一个基于acf的停止标志物体检测器
将包含图像的文件夹添加到MATLAB路径中。
imageDir = fullfile(matlabroot,“工具箱”,“愿景”,“visiondata”,“stopSignImages”);目录(imageDir);
加载地面真相数据,其中包含停止标志和汽车的数据。
负载(“stopSignsAndCarsGroundTruth.mat”,“stopSignsAndCarsGroundTruth”)
查看标签定义以查看基本真理中的标签类型。
stopSignsAndCarsGroundTruth。LabelDefinitions
ans =3×3表名称类型组 ____________ _________ ________ {' stopSign的矩形}{‘没有’}{‘carRear}矩形{‘没有’}{‘carFront}矩形{'没有'}
选择用于训练的停止标志数据。
stopSignsAndCarsGroundTruth = selectLabelsByName(stopSignsAndCarsGroundTruth,“stopSign”);
为停止标志对象检测器创建训练数据。
trainingData = objectDetectorTrainingData(stopSignGroundTruth);总结(trainingData)
变量:imageFilename: 41x1 cell数组字符向量stopSign: 41x1 cell
训练一个基于acf的对象检测器。
acfDetector = trainACFObjectDetector(训练数据,“NegativeSamplesFactor”2);
ACF对象检测器培训培训将分为4个阶段。模型尺寸为34x31。样本正面例子(~100%完成)计算近似系数…完成。计算聚合通道特性…已完成。-------------------------------------------- 阶段1:样本的负面例子(~ 100%)完成计算聚合通道特性…完成。用42个正例和84个反例训练分类器…完成。训练后的分类器有19个弱学习器。-------------------------------------------- 阶段2:样本负面例子(~ 100%完成)发现了84个新的负面例子进行训练。计算聚合通道特性…已完成。用42个正例和84个反例训练分类器…完成。 The trained classifier has 20 weak learners. -------------------------------------------- Stage 3: Sample negative examples(~100% Completed) Found 84 new negative examples for training. Compute aggregated channel features...Completed. Train classifier with 42 positive examples and 84 negative examples...Completed. The trained classifier has 54 weak learners. -------------------------------------------- Stage 4: Sample negative examples(~100% Completed) Found 84 new negative examples for training. Compute aggregated channel features...Completed. Train classifier with 42 positive examples and 84 negative examples...Completed. The trained classifier has 61 weak learners. -------------------------------------------- ACF object detector training is completed. Elapsed time is 28.6919 seconds.
在样本图像上测试基于acf的检测器。
I = imread(“stopSignTest.jpg”);bboxes = detect(acfDetector,I);
显示检测到的对象。
annotation = acfDetector.ModelName;I = insertObjectAnnotation(I,“矩形”、bboxes、注释);图imshow(我)
从路径中删除映像文件夹。
rmpath (imageDir);