Main Content


Detect objects in monocular camera using YOLO v3 deep learning detector

Since R2023a


The yolov3ObjectDetectorMonoCamera object contains information about a you only look once version 3 (YOLO v3) object detector that is configured for use with a monocular camera sensor. To detect objects in an image captured by the camera, pass the detector to the detect object function.

When you use the detect object function with a yolov3ObjectDetectorMonoCamera object, use of a CUDA®-enabled NVIDIA® GPU is highly recommended. The GPU reduces computation time significantly. Usage of the GPU requires Parallel Computing Toolbox™. For information about the supported compute capabilities, see GPU Computing Requirements (Parallel Computing Toolbox).


  1. Create a yolov3ObjectDetector object by using YOLO v3 deep learning networks trained on a COCO data set (requires Deep Learning Toolbox™ and Computer Vision Toolbox™ Model for YOLO v3 Object Detection).

    detector = yolov3ObjectDetector("darknet53-coco");

    Alternatively, you can create a yolov3ObjectDetector object by using a custom pretrained YOLO v3 network. For more information, see yolov3ObjectDetector.

  2. Create a monoCamera object to model the monocular camera sensor.

    sensor = monoCamera(____);
  3. Create a yolov3ObjectDetectorMonoCamera 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,____);


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 for the object detector, stored as a character vector or string scalar. By default, the name is set to the ModelName property value of yolov3ObjectDetector object specified at the input. You can modify this name after creating the yolov3ObjectDetectorMonoCamera object.

Data Types: char | string

This property is read-only.

Trained YOLO v3 object detection network, stored as a dlnetwork (Deep Learning Toolbox) object. This object stores the layers that are used within the YOLO v3 object detector.

This property is read-only.

Names of the object classes that the YOLO v3 object detector was trained to find, stored as a categorical vector. This property is set by the classes input argument of yolov3ObjectDetector object.

Data Types: categorical

This property is read-only.

Size of anchor boxes, stored as an N-by-1 cell array. N is the number of output layers in the YOLO v3 deep learning network. Each cell contains an M-by-2 matrix, where M is the number of anchor boxes in that layer. Each row in the M-by-2 matrix denotes the size of an anchor box in the form [height width]. This property is set by the aboxes input argument of the yolov3ObjectDetector object.

Data Types: cell

This property is read-only.

Image size used for training, stored as a vector of form [height width] or [height width channels].

Data Types: double

Object Functions

detectDetect objects using YOLO v3 object detector configured for monocular camera


collapse all

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

Load a yolov3ObjectDetector object pretrained on the COCO data set.

detector = yolov3ObjectDetector;

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 a yolov3ObjectDetectorMonoCamera object.

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

Read an image captured by the camera.

I = imread("object-detection-test.png");

Detect the vehicles and stop signs in the image by using the detector. Annotate the image with the bounding boxes for the detections and the class labels.

[bboxes,scores,labels] = detect(detectorMonoCam,I);
I = insertObjectAnnotation(I,"rectangle",bboxes,labels,AnnotationColor="green");

Version History

Introduced in R2023a