Main Content

ssdObjectDetectorMonoCamera

Detect objects in monocular camera using SSD deep learning detector

Since R2020a

Description

The ssdObjectDetectorMonoCamera detects objects from an image, using a single shot detector (SSD) object detector. To detect objects in an image, pass the trained detector to the detect function.

Creation

  1. Create a ssdObjectDetector object by calling the trainSSDObjectDetector function with training data (requires Deep Learning Toolbox™).

    detector = trainSSDObjectDetector(trainingData,____);
  2. Create a monoCamera object to model the monocular camera sensor.

    sensor = monoCamera(____);
  3. Create a ssdObjectDetectorMonoCamera object by passing the detector and sensor as inputs to the configureDetectorMonoCamera function. The configured detector inherits property values from the original detector.

    configuredDetector = configureDetectorMonoCamera(detector,sensor,____);

Properties

expand all

This property is read-only.

Camera configuration, specified as a monoCamera object. The object contains the camera intrinsics, the location, the pitch, yaw, and roll placement, and the world units for the parameters. Use the intrinsics to transform the object points in the image to world coordinates, which you can then compare to the values in the WorldObjectSize property.

This property is read-only.

Range of object widths and lengths in world units, specified as a [minWidth maxWidth] vector or [minWidth maxWidth; minLength maxLength] matrix. Specifying the range of object lengths is optional.

Name of the classification model, specified as a character vector or string scalar. You can modify this name after creating the ssdObjectDetectorMonoCamera object.

This property is read-only.

Trained SSD object detection network, specified as a DAGNetwork (Deep Learning Toolbox) object. This object stores the layers that are used within the SSD object detector.

This property is read-only.

Size of anchor boxes, specified as a P-by-1 cell array for P number of feature extraction layers used for object detection in the SSD network. Each element of the array contains an M-by-2 matrix of anchor box sizes, in the format [height width]. Each cell can contain a different number of anchor boxes. This value is set during training.

This property is read-only.

Names of the object classes that the SSD object detector was trained to find, specified as a cell array of character vectors. This property is set by the trainingData input argument for the trainSSDObjectDetector function. Specify the class names as part of the trainingData table.

Object Functions

detectDetect objects using SSD object detector configured for monocular camera

Examples

collapse all

Configure an SSD object detector for use with a monocular camera mounted on an ego vehicle. Use this detector to detect vehicles within an image captured by the camera.

Load an ssdObjectDetector object pretrained to detect vehicles.

vehicleDetector = load('ssdVehicleDetector.mat','detector');
detector = vehicleDetector.detector;

Model a monocular camera sensor by creating a monoCamera object. This object contains the camera intrinsics and the location of the camera on the ego vehicle.

focalLength = [309.4362 344.2161];    % [fx fy]
principalPoint = [318.9034 257.5352]; % [cx cy]
imageSize = [480 640];                % [mrows ncols]
height = 2.1798;                      % height of camera above ground, in meters
pitch = 14;                           % pitch of camera, in degrees
intrinsics = cameraIntrinsics(focalLength,principalPoint,imageSize);

sensor = monoCamera(intrinsics,height,'Pitch',pitch);

Configure the detector for use with the camera. Limit the width of detected objects to 1.5 – 2.5 meters. The configured detector is an ssdObjectDetectorMonoCamera object.

vehicleWidth = [1.5 2.5];
detectorMonoCam = configureDetectorMonoCamera(detector,sensor,vehicleWidth);

Read an image captured by the camera.

I = imread('highwayCars.png');

Detect the vehicles in the image by using the detector. Annotate the image with the bounding boxes for the detections and the detection confidence scores.

[bboxes,scores,labels] = detect(detectorMonoCam,I,'Threshold',0.6);
I = insertObjectAnnotation(I,'rectangle',bboxes,scores,'AnnotationColor','g');
imshow(I)

Display the labels for detected bounding boxes. The labels specify the class names of the detected objects.

disp(labels)
     vehicle 
     vehicle 

Version History

Introduced in R2020a