VPI - Vision Programming Interface

0.1.0 Release

Harris Keypoint Detector

Overview

The algorithm implements the Harris keypoint detection operator that is commonly used into 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 prunning 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 prunning 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 superceed 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:

PVA

  • Not implemented

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::minNMSDistance
float minNMSDistance
Non-maximum suppression radius, set to 0 to disable it.
Definition: HarrisKeypointDetector.h:95
vpiCreateHarrisKeypointDetector
VPIStatus vpiCreateHarrisKeypointDetector(VPIStream stream, uint32_t inputWidth, uint32_t inputHeight, VPIPayload *payload)
Creates a Harris Keypoint Detector payload.
vpiStreamSync
VPIStatus vpiStreamSync(VPIStream stream)
Blocks the calling thread until all submitted commands in this stream queue are done (queue is empty)...
HarrisKeypointDetector.h
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::strengthThresh
float strengthThresh
Specifies the minimum threshold with which to eliminate Harris Corner scores.
Definition: HarrisKeypointDetector.h:89
VPI_ARRAY_TYPE_KEYPOINT
VPIKeypoint element.
Definition: Types.h:216
VPIHarrisKeypointDetectorParams::sensitivity
float sensitivity
Specifies sensitivity threshold from the Harris-Stephens equation.
Definition: HarrisKeypointDetector.h:92
VPIImage
struct VPIImageImpl * VPIImage
Definition: Types.h:153
vpiImageGetSize
VPIStatus vpiImageGetSize(VPIImage img, uint32_t *width, uint32_t *height)
Get the image size in pixels.
VPIHarrisKeypointDetectorParams
Structure that defines the parameters for vpiSubmitHarrisKeypointDetector.
Definition: HarrisKeypointDetector.h:80
VPIHarrisKeypointDetectorParams::gradientSize
uint32_t gradientSize
Gradient window size.
Definition: HarrisKeypointDetector.h:83
VPIPayload
struct VPIPayloadImpl * VPIPayload
A handle to an algorithm payload.
Definition: Types.h:164
VPIArray
struct VPIArrayImpl * VPIArray
Definition: Types.h:129
vpiPayloadDestroy
void vpiPayloadDestroy(VPIPayload payload)
Deallocates the payload object and all associated resources.
VPIHarrisKeypointDetectorParams::blockSize
uint32_t blockSize
Block window size used to compute the Harris Corner score.
Definition: HarrisKeypointDetector.h:86
VPI_ARRAY_TYPE_U32
unsigned 32-bit.
Definition: Types.h:215
VPIStream
struct VPIStreamImpl * VPIStream
Definition: Types.h:147