VPI - Vision Programming Interface

1.0 Release

Harris Corner Detector

Overview

This algorithm implements the Harris keypoint detection operator that is commonly used to detect keypoints and infer features of an image.

The standard Harris detector algorithm as described in [1] is applied first. After that, a non-max suppression pruning process is applied to the result to remove multiple or spurious keypoints.

Input Parameters Output keypoints

\begin{align*} \mathit{gradientSize} &= 5 \\ \mathit{blockSize} &= 5 \\ \mathit{strengthThresh} &= 20 \\ \mathit{sensitivity} &= 0.01 \\ \mathit{minNMSDistance} &= 8 \end{align*}

Implementation

  1. Compute the spatial gradient of the input using one of the following filters, depending on the value of VPIHarrisCornerDetectorParams::gradientSize :
    • For gradientSize = 3:

      \begin{align*} \mathit{sobel}_x &= \frac{1}{4} \cdot \begin{bmatrix} 1 \\ 2 \\ 1 \end{bmatrix} \cdot \begin{bmatrix} -1 & 0 & 1 \end{bmatrix} \\ \mathit{sobel}_y &= (\mathit{sobel}_x)^\intercal \end{align*}

    • For gradientSize = 5:

      \begin{align*} \mathit{sobel}_x &= \frac{1}{16} \cdot \begin{bmatrix} 1 \\ 4 \\ 6 \\ 4 \\ 1 \end{bmatrix} \cdot \begin{bmatrix} -1 & -2 & 0 & 2 & 1 \end{bmatrix} \\ \mathit{sobel}_y &= (\mathit{sobel}_x)^\intercal \end{align*}

    • For gradientSize = 7:

      \begin{align*} \mathit{sobel}_x &= \frac{1}{64} \cdot \begin{bmatrix} 1 \\ 6 \\ 15 \\ 20 \\ 15 \\ 6 \\ 1 \end{bmatrix} \cdot \begin{bmatrix} -1 & -4 & -5 & 0 & 5 & 4 & 1 \end{bmatrix} \\ \mathit{sobel}_y &= (\mathit{sobel}_x)^\intercal \end{align*}

  2. Compute a gradient covariance matrix (structure tensor) for each pixel within a block window, as described by:

    \[ M = \sum_{p \in B}\begin{bmatrix}I_x^2(p) & I_x(p) I_y(p) \\ I_x(p) I_y(p) & I_y^2(p) \end{bmatrix} \]

    where:

    • p is a pixel coordinate within B, a block window of size 3x3, 5x5 or 7x7.
    • \(I(p)\) is the input image
    • \( I_x(p) = I(p) * \mathit{sobel}_x \)
    • \( I_y(p) = I(p) * \mathit{sobel}_y \)
  3. Compute a Harris response score using a sensitivity factor

    \[ R = \mathit{det}(M) - k \cdot \mathit{trace}^2(M ) \]

    where k is the sensitivity factor

  4. Applies a threshold-strength criterion, pruning keypoints whose response <= VPIHarrisCornerDetectorParams::strengthThresh.
  5. Applies a non-max suppression pruning process.

    This process splits the input image into a 2D cell grid. It selects a single corner with the highest response score inside the cell. If several corners within the cell have the same response score, it selects the bottom-right corner.

Usage

  1. Initialization phase
    1. Include the header that defines the box filter function.
      Declares functions that implement the Harris Corner Detector algorithm.
    2. Define the input image object.
      VPIImage input = /*...*/;
      struct VPIImageImpl * VPIImage
      A handle to an image.
      Definition: Types.h:197
    3. Create the output arrays that will store the keypoints and their scores.
      VPIArray keypoints;
      vpiArrayCreate(8192, VPI_ARRAY_TYPE_KEYPOINT, 0, &keypoints);
      VPIArray scores;
      vpiArrayCreate(8192, VPI_ARRAY_TYPE_U32, 0, &scores);
      VPIStatus vpiArrayCreate(int32_t capacity, VPIArrayType type, uint32_t flags, VPIArray *array)
      Create an empty array instance.
      struct VPIArrayImpl * VPIArray
      A handle to an array.
      Definition: Types.h:173
      @ VPI_ARRAY_TYPE_U32
      unsigned 32-bit.
      Definition: ArrayType.h:73
      @ VPI_ARRAY_TYPE_KEYPOINT
      VPIKeypoint element.
      Definition: ArrayType.h:74
    4. Since this algorithm needs temporary memory buffers, create the payload for it on the CUDA backend.
      int32_t w, h;
      vpiImageGetSize(input, &w, &h);
      VPIPayload harris;
      VPIStatus vpiCreateHarrisCornerDetector(uint32_t backends, int32_t inputWidth, int32_t inputHeight, VPIPayload *payload)
      Creates a Harris Corner Detector payload.
      VPIStatus vpiImageGetSize(VPIImage img, int32_t *width, int32_t *height)
      Get the image size in pixels.
      struct VPIPayloadImpl * VPIPayload
      A handle to an algorithm payload.
      Definition: Types.h:209
      @ VPI_BACKEND_CUDA
      CUDA backend.
      Definition: Types.h:92
    5. Create the stream where the algorithm will be submitted for execution.
      VPIStream stream;
      vpiStreamCreate(0, &stream);
      struct VPIStreamImpl * VPIStream
      A handle to a stream.
      Definition: Types.h:191
      VPIStatus vpiStreamCreate(uint32_t flags, VPIStream *stream)
      Create a stream instance.
  2. Processing phase
    1. Fill the configuration structure with parameters for the current algorithm invocation.
      params.gradientSize = 5;
      params.blockSize = 5;
      params.strengthThresh = 20;
      params.sensitivity = 0.01;
      params.minNMSDistance = 8;
      int32_t gradientSize
      Gradient window size.
      Definition: HarrisCorners.h:82
      int32_t blockSize
      Block window size used to compute the Harris Corner score.
      Definition: HarrisCorners.h:85
      float strengthThresh
      Specifies the minimum threshold with which to eliminate Harris Corner scores.
      Definition: HarrisCorners.h:88
      float minNMSDistance
      Non-maximum suppression radius, set to 0 to disable it.
      Definition: HarrisCorners.h:94
      float sensitivity
      Specifies sensitivity threshold from the Harris-Stephens equation.
      Definition: HarrisCorners.h:91
      Structure that defines the parameters for vpiSubmitHarrisCornerDetector.
      Definition: HarrisCorners.h:80
    2. Submit the algorithm and its parameters to the stream. It'll be executed by the CUDA backend associated with the payload.
      VPI_CHECK_STATUS(
      vpiSubmitHarrisCornerDetector(stream, VPI_BACKEND_CUDA, harris, input, keypoints, scores, &params));
      VPIStatus vpiSubmitHarrisCornerDetector(VPIStream stream, uint32_t backend, VPIPayload payload, VPIImage input, VPIArray outFeatures, VPIArray outScores, const VPIHarrisCornerDetectorParams *params)
      Submits Harris Corner Detector operation to the stream associated with the payload.
    3. Optionally, wait until the processing is done.
      vpiStreamSync(stream);
      VPIStatus vpiStreamSync(VPIStream stream)
      Blocks the calling thread until all submitted commands in this stream queue are done (queue is empty)...
  3. Cleanup phase
    1. Free resources held by the stream, the payload, the input image and the output arrays.
      vpiArrayDestroy(keypoints);
      vpiArrayDestroy(scores);
      void vpiArrayDestroy(VPIArray array)
      Destroy an array instance.
      void vpiImageDestroy(VPIImage img)
      Destroy an image instance.
      void vpiPayloadDestroy(VPIPayload payload)
      Deallocates the payload object and all associated resources.
      void vpiStreamDestroy(VPIStream stream)
      Destroy a stream instance and deallocate all HW resources.

For more information, see Harris Corners in the "API Reference" section of VPI - Vision Programming Interface.

Limitations and Constraints

Constraints for specific backends supersede the ones specified for all backends.

All Backends

  • Input image must have same dimensions as the ones specified during payload creation.
  • Only supports Sobel gradient kernels of sizes 3x3, 5x5 and 7x7.
  • Output scores and keypoints arrays must have the same capacity.
  • Must satisfy \(\mathit{minNMSDistance} \geq 1\).
  • The following image types are accepted:
  • On 16-bit inputs, the pixel values must be restricted to 12-bit, or else overflows in score calculation will occur. In this case some keypoints might be invalid.

PVA

  • Only available on Jetson Xavier devices.
  • Only supports VPI_IMAGE_FORMAT_S16.
  • Output keypoints and scores array capacity must be 8192.
  • Only accepts \(\mathit{minNMSDistance} = 8\).

VIC

  • Not implemented.

Performance

For information on how to use the performance table below, see Algorithm Performance Tables.
Before comparing measurements, consult Comparing Algorithm Elapsed Times.
For further information on how performance was benchmarked, see Performance Benchmark.

 - 

References

  1. C. Harris, M. Stephens (1988), "A Combined Corner and Edge Detector"
    Proceedings of Alvey Vision Conference, pp. 147-151.