Обучите основанный на ACF детектор знака Стоп

Используйте обучающие данные, чтобы обучить ACF на основе детектора объектов знакам Стоп

Добавьте папку, содержащую изображения к пути MATLAB.

imageDir = fullfile(matlabroot, 'toolbox', 'vision', 'visiondata', 'stopSignImages');
addpath(imageDir);

Загрузите достоверные данные, который содержит данные для знаков остановок и автомобилей.

load('stopSignsAndCarsGroundTruth.mat','stopSignsAndCarsGroundTruth')

Просмотрите определения метки, чтобы видеть типы метки в основной истине.

stopSignsAndCarsGroundTruth.LabelDefinitions
ans=3×3 table
        Name          Type        Group  
    ____________    _________    ________

    {'stopSign'}    Rectangle    {'None'}
    {'carRear' }    Rectangle    {'None'}
    {'carFront'}    Rectangle    {'None'}

Выберите данные о знаке Стоп для обучения.

stopSignGroundTruth = selectLabelsByName(stopSignsAndCarsGroundTruth,'stopSign');

Создайте обучающие данные для детектора объектов знака Стоп.

trainingData = objectDetectorTrainingData(stopSignGroundTruth);
summary(trainingData)
Variables:

    imageFilename: 41x1 cell array of character vectors

    stopSign: 41x1 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 12.9952 seconds.

Протестируйте основанный на ACF детектор на демонстрационном изображении.

I = imread('stopSignTest.jpg');
bboxes = detect(acfDetector,I);

Отобразите обнаруженный объект.

annotation = acfDetector.ModelName;
I = insertObjectAnnotation(I,'rectangle',bboxes,annotation);

figure 
imshow(I)

Figure contains an axes object. The axes object contains an object of type image.

Удалите папку изображений из пути.

rmpath(imageDir); 
Для просмотра документации необходимо авторизоваться на сайте