Configure object detector for using calibrated monocular camera
ACF (aggregate channel features)
Faster R-CNN (regions with convolutional neural networks)
YOLO v2 (you only look once v2)
YOLO v4 (you only look once v4)
SSD (single shot detector),
to detect objects of a known size on a ground plane. Specify your
trained object detector,
detector, a camera configuration for
transforming image coordinates to world coordinates,
and the range of the object widths and lengths,
Detect Vehicles Using Monocular Camera and ACF
Configure an ACF object detector for use with a monocular camera mounted on an ego vehicle. Use this detector to detect vehicles within video frames captured by the camera.
acfObjectDetector object pretrained to detect vehicles.
detector = vehicleDetectorACF;
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); monCam = monoCamera(intrinsics,height,'Pitch',pitch);
Configure the detector for use with the camera. Limit the width of detected objects to a typical range for vehicle widths: 1.5–2.5 meters. The configured detector is an
vehicleWidth = [1.5 2.5]; detectorMonoCam = configureDetectorMonoCamera(detector,monCam,vehicleWidth);
Load a video captured from the camera, and create a video reader and player.
videoFile = fullfile(toolboxdir('driving'),'drivingdata','caltech_washington1.avi'); reader = VideoReader(videoFile); videoPlayer = vision.VideoPlayer('Position',[29 597 643 386]);
Run the detector in a loop over the video. Annotate the video with the bounding boxes for the detections and the detection confidence scores.
cont = hasFrame(reader); while cont I = readFrame(reader); % Run the detector. [bboxes,scores] = detect(detectorMonoCam,I); if ~isempty(bboxes) I = insertObjectAnnotation(I, ... 'rectangle',bboxes, ... scores, ... 'Color','g'); end videoPlayer(I) % Exit the loop if the video player figure is closed. cont = hasFrame(reader) && isOpen(videoPlayer); end release(videoPlayer);
detector — Object detector to configure
acfObjectDetector object |
fastRCNNObjectDetector object |
fasterRCNNObjectDetector object |
yolov2ObjectDetector object |
yolov4ObjectDetector object |
Object detector to configure, specified as one of these object detector objects:
Train the object detector before configuring them by using:
sensor — Camera configuration
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
WorldObjectSize property for
objectSize — Range of object widths and lengths
[minWidth maxWidth] vector | [minWidth maxWidth; minLength maxLength]
Range of object widths and lengths in world units, specified as a [minWidth maxWidth] vector or [minWidth maxWidth; minLength maxLength] vector. Specifying the range of object lengths is optional.