%% Detect Vehicles Using YOLO v2 Detector
% 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);
figure
imshow(I)
title('Detected vehicles and detection scores');

% Copyright 2019 The MathWorks, Inc.