Train ACF-Based Stop Sign Detector
Use training data to train an ACF-based object detector for stop signs
Add the folder containing images to the MATLAB path.
imageDir = fullfile(matlabroot, 'toolbox', 'vision', 'visiondata', 'stopSignImages'); addpath(imageDir);
Load ground truth data, which contains data for stops signs and cars.
load('stopSignsAndCarsGroundTruth.mat','stopSignsAndCarsGroundTruth')
View the label definitions to see the label types in the ground truth.
stopSignsAndCarsGroundTruth.LabelDefinitions
ans=3×3 table
Name Type Group
____________ _________ ________
{'stopSign'} Rectangle {'None'}
{'carRear' } Rectangle {'None'}
{'carFront'} Rectangle {'None'}
Select the stop sign data for training.
stopSignGroundTruth = selectLabelsByName(stopSignsAndCarsGroundTruth,'stopSign');
Create the training data for a stop sign object detector.
trainingData = objectDetectorTrainingData(stopSignGroundTruth); summary(trainingData)
trainingData: 41x2 table Variables: imageFilename: cell array of character vectors stopSign: cell Statistics for applicable variables: NumMissing imageFilename 0 stopSign 0
Train an ACF-based object detector.
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 18.4629 seconds.
Test the ACF-based detector on a sample image.
I = imread('stopSignTest.jpg');
bboxes = detect(acfDetector,I);
Display the detected object.
annotation = acfDetector.ModelName;
I = insertObjectAnnotation(I,'rectangle',bboxes,annotation);
figure
imshow(I)
Remove the image folder from the path.
rmpath(imageDir);