VPI - Vision Programming Interface

0.2.0 Release

Harris Keypoint 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} &= 250 \\ \mathit{sensitivity} &= 0.24 \\ \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 VPIHarrisKeypointDetectorParams::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 <= VPIHarrisKeypointDetectorParams::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.
    2. Define the stream on which the algorithm will be executed and the input image.
      VPIStream stream = /*...*/;
      VPIImage input = /*...*/;
    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);
    4. Since this algorithm needs temporary memory buffers, create the payload for it.
      uint32_t w, h;
      vpiImageGetSize(input, &w, &h);
      VPIPayload harris;
      vpiCreateHarrisKeypointDetector(stream, w, h, &harris);
  2. Processing phase
    1. Fill the configuration structure with parameters for the current algorithm invocation.
      params.gradientSize = 5;
      params.blockSize = 5;
      params.strengthThresh = 250;
      params.sensitivity = 0.24;
      params.minNMSDistance = 8;
    2. Submit the algorithm and its parameters to the stream.
      vpiSubmitHarrisKeypointDetector(harris, input, keypoints, scores, &params);
    3. Optionally, wait until the processing is done.
      vpiStreamSync(stream);
  3. Cleanup phase
    1. Free resources held by the payload.

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 supports VPI_IMAGE_TYPE_S16.
  • Output keypoints and scores array capacity must be 8192.
  • Only accepts \(\mathit{minNMSDistance} = 8\).

Performance

For further information on how performance was benchmarked, see Performance Measurement.

Jetson AGX Xavier
sizetypegrad.
size
block
size
CPUCUDAPVA
1920x1080u833 5.7 ms1.0003 msn/a
1920x1080u855 8.2 ms0.9735 msn/a
1920x1080u877 10.2 ms1.2313 msn/a
1920x1080s1633 6.0 ms1.0437 ms8.346 ms
1920x1080s1655 8.57 ms1.0011 ms8.680 ms
1920x1080s1677 10.2 ms1.2646 ms9.054 ms
Jetson TX2
sizetypegrad.
size
block
size
CPUCUDAPVA
1920x1080u833 15.7 ms5.226 msn/a
1920x1080u855 18.4 ms4.61 msn/a
1920x1080u877 24.3 ms5.246 msn/a
1920x1080s1633 15.3 ms5.229 msn/a
1920x1080s1655 19.2 ms4.70 msn/a
1920x1080s1677 25.0 ms5.25 msn/a
Jetson Nano
sizetypegrad.
size
block
size
CPUCUDAPVA
1920x1080u833 29.69 ms10.7 msn/a
1920x1080u855 39.2 ms10.311 msn/a
1920x1080u877 50.89 ms12.041 msn/a
1920x1080s1633 30.29 ms11.99 msn/a
1920x1080s1655 39.8 ms10.309 msn/a
1920x1080s1677 51.77 ms12.052 msn/a

References

  1. C. Harris, M. Stephens (1988), "A Combined Corner and Edge Detector"
    Proceedings of Alvey Vision Conference, pp. 147-151.
vpiArrayCreate
VPIStatus vpiArrayCreate(uint32_t capacity, VPIArrayType fmt, uint32_t flags, VPIArray *array)
Create an empty array instance with the specified flags.
VPIHarrisKeypointDetectorParams::sensitivity
float sensitivity
Specifies sensitivity threshold from the Harris-Stephens equation.
Definition: HarrisKeypointDetector.h:92
vpiCreateHarrisKeypointDetector
VPIStatus vpiCreateHarrisKeypointDetector(VPIStream stream, uint32_t inputWidth, uint32_t inputHeight, VPIPayload *payload)
Creates a Harris Keypoint Detector payload.
VPIHarrisKeypointDetectorParams
Structure that defines the parameters for vpiSubmitHarrisKeypointDetector.
Definition: HarrisKeypointDetector.h:81
vpiStreamSync
VPIStatus vpiStreamSync(VPIStream stream)
Blocks the calling thread until all submitted commands in this stream queue are done (queue is empty)...
HarrisKeypointDetector.h
VPIHarrisKeypointDetectorParams::strengthThresh
float strengthThresh
Specifies the minimum threshold with which to eliminate Harris Corner scores.
Definition: HarrisKeypointDetector.h:89
VPIHarrisKeypointDetectorParams::gradientSize
uint32_t gradientSize
Gradient window size.
Definition: HarrisKeypointDetector.h:83
vpiSubmitHarrisKeypointDetector
VPIStatus vpiSubmitHarrisKeypointDetector(VPIPayload payload, VPIImage input, VPIArray outFeatures, VPIArray outScores, const VPIHarrisKeypointDetectorParams *params)
Submits Harris Keypoint Detector operation to the stream associated with the payload.
VPIHarrisKeypointDetectorParams::minNMSDistance
float minNMSDistance
Non-maximum suppression radius, set to 0 to disable it.
Definition: HarrisKeypointDetector.h:95
VPI_ARRAY_TYPE_KEYPOINT
@ VPI_ARRAY_TYPE_KEYPOINT
VPIKeypoint element.
Definition: Types.h:264
VPIImage
struct VPIImageImpl * VPIImage
Definition: Types.h:170
vpiImageGetSize
VPIStatus vpiImageGetSize(VPIImage img, uint32_t *width, uint32_t *height)
Get the image size in pixels.
VPIHarrisKeypointDetectorParams::blockSize
uint32_t blockSize
Block window size used to compute the Harris Corner score.
Definition: HarrisKeypointDetector.h:86
VPIPayload
struct VPIPayloadImpl * VPIPayload
A handle to an algorithm payload.
Definition: Types.h:181
VPIArray
struct VPIArrayImpl * VPIArray
Definition: Types.h:146
vpiPayloadDestroy
void vpiPayloadDestroy(VPIPayload payload)
Deallocates the payload object and all associated resources.
VPI_ARRAY_TYPE_U32
@ VPI_ARRAY_TYPE_U32
unsigned 32-bit.
Definition: Types.h:263
VPIStream
struct VPIStreamImpl * VPIStream
Definition: Types.h:164