Detect vehicles using YOLO v2 Network



detector = vehicleDetectorYOLOv2 returns a trained you only look once (YOLO) v2 object detector for detecting vehicles. YOLO v2 is a deep learning object detection framework that uses a convolutional neural network (CNN) for detection.

The detector is trained using unoccluded RGB images of the front, rear, left, and right sides of cars on a highway scene. The CNN used with the vehicle detector uses a modified version of the MobileNet-v2 network architecture. You can also fine tune the vehicle detector with additional training data by using the trainYOLOv2ObjectDetector.

For information about creating a YOLO v2 object detector, see Create YOLO v2 Object Detection Network (Computer Vision Toolbox). Use of this function requires Deep Learning Toolbox™.


collapse all

This example shows how to detect cars in an image and annotate the image with the detection scores. To detect the cars, use a YOLO v2 detector that is trained to detect vehicles in an image.

Load the pretrained detector.

detector = vehicleDetectorYOLOv2();

Read a test image into the workspace.

I = imread('highway.png');

Detect vehicles in the test image by using the trained YOLO v2 detector. Pass the test image and the detector as input to the detect function. The detect function returns the bounding boxes and the detection scores.

[bboxes,scores] = detect(detector,I);

Annotate the image with the bounding boxes and the detection scores. Display the detection results. The bounding boxes localize vehicles in the test image.

I = insertObjectAnnotation(I,'rectangle',bboxes,scores);
title('Detected vehicles and detection scores');

Output Arguments

collapse all

Trained YOLO v2 network for vehicle detection, returned as an yolov2ObjectDetector object. To detect vehicles in a test image, pass the YOLO v2 vehicle detector as input to the detect function.

Introduced in R2020a