Используйте обучающие данные, чтобы обучить ACF на основе детектора объектов знакам Стоп
Добавьте папку, содержащую изображения к пути MATLAB.
imageDir = fullfile(matlabroot, 'toolbox', 'vision', 'visiondata', 'stopSignImages'); addpath(imageDir);
Загрузите достоверные данные, который содержит данные для знаков остановок и автомобилей.
load('stopSignsAndCarsGroundTruth.mat','stopSignsAndCarsGroundTruth')
Просмотрите определения метки, чтобы видеть типы метки в основной истине.
stopSignsAndCarsGroundTruth.LabelDefinitions
Выберите данные о знаке Стоп для обучения.
stopSignGroundTruth = selectLabels(stopSignsAndCarsGroundTruth,'stopSign');
Создайте обучающие данные для детектора объектов знака Стоп.
trainingData = objectDetectorTrainingData(stopSignGroundTruth); summary(trainingData)
Variables: imageFilename: 41×1 cell array of character vectors stopSign: 41×1 cell
Обучите ACF на основе детектора объектов.
acfDetector = trainACFObjectDetector(trainingData,'NegativeSamplesFactor',2);
ACF Object Detector Training The training will take 4 stages. The model size is 34x31. Sample positive examples(~100% Completed) Compute approximation coefficients...Completed. Compute aggregated channel features...Completed. -------------------------------------------- Stage 1: Sample negative examples(~100% Completed) Compute aggregated channel features...Completed. Train classifier with 42 positive examples and 84 negative examples...Completed. The trained classifier has 19 weak learners. -------------------------------------------- Stage 2: 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 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 30.3579 seconds.
Протестируйте основанный на ACF детектор на демонстрационном изображении.
I = imread('stopSignTest.jpg');
bboxes = detect(acfDetector,I);
Отобразите обнаруженный объект.
annotation = acfDetector.ModelName;
I = insertObjectAnnotation(I,'rectangle',bboxes,annotation);
figure
imshow(I)
Удалите папку изображений из пути.
rmpath(imageDir);