acfObjectDetector - Detect objects using aggregate channel features - MATLAB (original) (raw)
Detect objects using aggregate channel features
Description
The acfObjectDetector
object detects objects from an image using the aggregate channel features (ACF) object detector. To use the ACF detector on an image, pass the trained detector to the detect function.
The ACF object detector recognizes specific objects in images, based on the training images and the object ground truth locations used with the trainACFObjectDetector function.
Creation
Create an acfObjectDetector
object by calling the trainACFObjectDetector function with training data.
detector = trainACFObjectDetector(trainingData,...)
Syntax
Description
`detector` = acfObjectDetector([classifier](#mw%5F564e7192-ca47-45b9-af5c-97ff8b149519),[trainingOptions](#mw%5Ffb64c8e6-a951-4ec0-ba62-ae18621e8fe4))
creates an ACF object detector based on the specified pretrainedclassifier
and trainingOptions
. You can use this syntax to recreate an ACF object detector for code generation.
Input Arguments
Pretrained acfObjectDetector
object classifier, specified as a structure of an Adaboost classifier. You can obtain the classifier structure field by converting a pretrained ACF classifier object to a structure by using the toStruct
function.
Pretrained acfObjectDetector
object training options, specified as a structure of feature pyramid parameters. You can obtain the training option structure field by converting a pretrained ACF classifier object to a structure by using thetoStruct
function.
Properties
Name of the classification model, specified as a character vector or string scalar. By default, the name is set to the heading of the second column of thetrainingData
table specified in the trainACFObjectDetector function. You can modify this name after creating your acfObjectDetector
object.
Example: 'stopSign'
This property is read-only.
Size of training images, specified as a [height _width_] vector.
Example: [100 100]
This property is read-only.
Number of weak learners used in the detector, specified as an integer.NumWeakLearners
is less than or equal to the maximum number of weak learners for the last training stage. To restrict this maximum, you can use the 'MaxWeakLearners'
name-value pair in the trainACFObjectDetector function.
Object Functions
detect | Detect objects using ACF object detector |
---|---|
toStruct | Convert a trained aggregate channel features (ACF) object detector into structure |
Examples
Use the trainACFObjectDetector
with training images to create an ACF object detector that can detect stop signs. Test the detector with a separate image.
Load the training data.
load('stopSignsAndCars.mat')
Prefix the full path to the stop sign images.
stopSigns = fullfile(toolboxdir('vision'),'visiondata',stopSignsAndCars{:,1});
Create datastores to load the ground truth data for stop signs.
imds = imageDatastore(stopSigns); blds = boxLabelDatastore(stopSignsAndCars(:,2));
Combine the image and box label datastores.
Train the ACF detector. Set the number of negative samples to use at each stage to 2
. You can turn off the training progress output by specifying Verbose=false
, as a Name-Value
argument.
acfDetector = trainACFObjectDetector(ds,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 17.9982 seconds.
Test the ACF detector on a test image.
img = imread('stopSignTest.jpg'); [bboxes,scores] = detect(acfDetector,img);
Display the detection results and insert the bounding boxes for objects into the image.
for i = 1:length(scores) annotation = sprintf('Confidence = %.1f',scores(i)); img = insertObjectAnnotation(img,'rectangle',bboxes(i,:),annotation); end
figure imshow(img)
Load the ACF stop sign detector from the stopSignDetector.mat
file, which is present in the current working folder as a supporting file.
stopSignDetector = load('stopSignDetectorACF.mat'); detector = stopSignDetector.detector
detector =
acfObjectDetector with properties:
ModelName: 'stopSign'
ObjectTrainingSize: [34 31]
NumWeakLearners: 61
Convert the detector into a structure by using the toStruct
function.
detectorStruct = toStruct(detector);
To generate code, pass the structure to a MATLAB® function. Then inside the MATLAB function, create an identical ACF stop sign detector using the existing detector properties.
detector1 = acfObjectDetector(detectorStruct.Classifier,detectorStruct.TrainingOptions)
detector1 =
acfObjectDetector with properties:
ModelName: 'stopSign'
ObjectTrainingSize: [34 31]
NumWeakLearners: 61
You can pass detector1
to the detect
function as an input to detect stop signs from images.
References
[1] Dollar, P., R. Appel, S. Belongie, and P. Perona. "Fast Feature Pyramids for Object Detection." Pattern Analysis and Machine Intelligence, IEEE Transactions. Vol. 36, Issue 8, 2014, pp. 1532–1545.
Extended Capabilities
Version History
Introduced in R2017a