detect

Detect objects using Fast R-CNN object detector

Syntax

bboxes = detect(detector,I)
[bboxes,scores] = detect(detector,I)
[___,labels] = detect(detector,I)
[___] = detect(___,roi)
[___] = detect(___,Name,Value)

Description

bboxes = detect(detector,I) detects objects within image I using a Fast R-CNN (regions with convolutional neural networks) object detector. The locations of objects detected are returned as a set of bounding boxes.

When using this function, use of a CUDA® enabled NVIDIA® GPU with a compute capability of 3.0 or higher is highly recommended. The GPU reduces computation time significantly. Usage of the GPU requires Parallel Computing Toolbox™.

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

[___,labels] = detect(detector,I) also returns a categorical array of labels assigned to the bounding boxes, using either of the preceding syntaxes. The labels used for object classes are defined during training using the trainFastRCNNObjectDetector function.

[___] = detect(___,roi) detects objects within the rectangular search region specified by roi.

[___] = detect(___,Name,Value) specifies options using one or more Name,Value pair arguments. For example, detect(detector,I,'NumStongestRegions',1000) limits the number of strongest region proposals to 1000.

Input Arguments

collapse all

Fast R-CNN object detector, specified as a fastRCNNObjectDetector object. To create this object, call the trainFastRCNNObjectDetector function with training data as input.

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

The detector is sensitive to the range of the input image. Therefore, ensure that the input image range is similar to the range of the images used to train the detector. For example, if the detector was trained on uint8 images, rescale this input image to the range [0, 255] by using the im2uint8 or rescale function. The size of this input image should be comparable to the sizes of the images used in training. If these sizes are very different, the detector has difficulty detecting objects because the scale of the objects in the input image differs from the scale of the objects the detector was trained to identify. Consider whether you used the SmallestImageDimension property during training to modify the size of training images.

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

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 Pair Arguments

Specify optional comma-separated pairs of Name,Value arguments. Name is the argument name and Value is the corresponding value. Name must appear inside quotes. You can specify several name and value pair arguments in any order as Name1,Value1,...,NameN,ValueN.

Example: 'NumStongestRegions',1000

Detection threshold, specified as a scalar in the range [0, 1]. Detections that have scores less than this threshold value are removed. To reduce false positives, increase this value.

Maximum number of strongest region proposals, specified as the comma-separated pair consisting of 'NumStrongestRegions' and a positive integer. Reduce this value to speed up processing time at the cost of detection accuracy. To use all region proposals, specify this value as Inf.

Select the strongest bounding box for each detected object, specified as the comma-separated pair consisting of 'SelectStrongest' and either true or false.

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

    For example:

     selectStrongestBboxMulticlass(bbox,scores, ...
                'RatioType','Min', ...
                'OverlapThreshold',0.5);

  • 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 the comma-separated pair consisting of 'MinSize' and a [height width] vector. 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 the comma-separated pair consisting of 'MaxSize' and a [height width] vector. 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.

Hardware resource on which to run the detector, specified as the comma-separated pair consisting of 'ExecutionEnvironment' and 'auto', 'gpu', or 'cpu'.

  • 'auto' — Use a GPU if it is available. Otherwise, use the CPU.

  • 'gpu' — Use the GPU. To use a GPU, you must have Parallel Computing Toolbox and a CUDA enabled NVIDIA GPU with a compute capability of 3.0 or higher. If a suitable GPU is not available, the function returns an error.

  • 'cpu' — Use the CPU.

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. A higher score indicates higher confidence in the detection.

Labels for bounding boxes, returned as an M-by-1 categorical array of M labels. You define the class names used to label the objects when you train the input detector.

Introduced in R2017a