Main Content

detect

Detect objects using ACF object detector configured for monocular camera

Description

bboxes = detect(detector,I) detects objects within image I using an aggregate channel features (ACF) object detector configured for a monocular camera. The locations of objects detected are returned as a set of bounding boxes.

[bboxes,scores] = detect(detector,I) also returns the detection confidence scores for each bounding box.

example

[___]= detect(detector,I,roi) detects objects within the rectangular search region specified by roi, using any of the preceding syntaxes.

[___] = detect(___,Name,Value) specifies options using one or more Name,Value pair arguments. For example, detect(detector,I,'WindowStride',2) sets the stride of the sliding window used to detect objects to 2.

Examples

collapse all

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.

Load an 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 acfObjectDetectorMonoCamera object.

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, ...
                           'AnnotationColor','g');
   end
   videoPlayer(I)
   % Exit the loop if the video player figure is closed.
   cont = hasFrame(reader) && isOpen(videoPlayer);
end

release(videoPlayer);

Input Arguments

collapse all

ACF object detector configured for a monocular camera, specified as an acfObjectDetectorMonoCamera object. To create this object, use the configureDetectorMonoCamera function with a monoCamera object and trained acfObjectDetector object as inputs.

Input image, specified as a real, nonsparse, grayscale or RGB image.

Data Types: uint8 | uint16 | int16 | double | single

Datastore, specified as a datastore object containing a collection of images. Each image must be a grayscale or RGB. The function processes only the first column of the datastore, which must contain images and must be cell arrays or tables with multiple columns. Therefore, datastore read function must return image data in the first column.

Search region of interest, specified as an [x y width height] vector. The vector specifies the upper left corner and size of a region in pixels.

Name-Value Arguments

Specify optional pairs of arguments as Name1=Value1,...,NameN=ValueN, where Name is the argument name and Value is the corresponding value. Name-value arguments must appear after other arguments, but the order of the pairs does not matter.

Before R2021a, use commas to separate each name and value, and enclose Name in quotes.

Example: WindowStride=2 sets the stride of the sliding window used to detects objects to 2.

Number of scale levels per octave, specified a positive integer. Each octave is a power-of-two downscaling of the image. To detect people at finer scale increments, increase this number. Recommended values are in the range [4, 8].

Stride for the sliding window, specified as a positive integer. This value indicates the distance for the function to move the window in both the x and y directions. The sliding window scans the images for object detection.

Select the strongest bounding box for each detected object, specified as true or false.

  • true — Return the strongest bounding box per object. To select these boxes, detect calls the selectStrongestBbox function, which uses nonmaximal suppression to eliminate overlapping bounding boxes based on their confidence scores.

  • false — Return all detected bounding boxes. You can then create your own custom operation to eliminate overlapping bounding boxes.

Minimum region size that contains a detected object, specified as a vector of the form [height width]. Units are in pixels.

By default, MinSize is the smallest object that the trained detector can detect.

Maximum region size that contains a detected object, specified as a vector of the form [height width]. Units are in pixels.

To reduce computation time, set this value to the known maximum region size for the objects being detected in the image. By default, 'MaxSize' is set to the height and width of the input image, I.

Classification accuracy threshold, specified as a numeric scalar. Recommended values are in the range [–1, 1]. During multiscale object detection, the threshold value controls the accuracy and speed for classifying image subregions as either objects or nonobjects. To speed up the performance at the risk of missing true detections, increase this threshold.

Output Arguments

collapse all

Location of objects detected within the input image, returned as an M-by-4 matrix, where M is the number of bounding boxes. Each row of bboxes contains a four-element vector of the form [x y width height]. This vector specifies the upper left corner and size of that corresponding bounding box in pixels.

Detection confidence scores, returned as an M-by-1 vector, where M is the number of bounding boxes. Scores are returned in the range [-inf inf]. A higher score indicates higher confidence in the detection.

Detection results, returned as a 3-column table with variable names, Boxes, Scores, and Labels. The Boxes column contains M-by-4 matrices, of M bounding boxes for the objects found in the image. Each row contains a bounding box as a 4-element vector in the format [x,y,width,height]. The format specifies the upper-left corner location and size in pixels of the bounding box in the corresponding image.

Version History

Introduced in R2017a