Skip to content

mrsp/superpoint_trt

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

SuperPoint TensorRT

TensorRT inference for SuperPoint feature detection, with an C++/Eigen3 API.

Dependencies

  • CUDA + TensorRT (libnvinfer-dev)
  • Eigen3
  • Python 3 + PyTorch (for export only)

SuperPoint architecture and weights are vendored in this repo (python/, weights/). No network fetch required for export.

Export ONNX and build engine

./scripts/export_and_build.sh

# Optional overrides:
WIDTH=640 HEIGHT=480 MAX_KP=1024 ./scripts/export_and_build.sh

Manual export:

python/.venv/bin/python python/export_superpoint_to_onnx.py \
  --width 640 --height 480 --max-keypoints 1024 \
  -o weights/superpoint_640x480_k1024.onnx

Build the TensorRT engine with trtexec (required before running inference):

trtexec \
  --onnx=weights/superpoint_640x480_k1024.onnx \
  --saveEngine=weights/superpoint_640x480_k1024.onnx.engine \
  --skipInference

SuperPointTrt::loadEngine() loads this pre-built engine file at runtime.

C++ usage

#include "superpoint_trt/SuperPointTrt.hpp"

sptrt::SuperPointTrtConfig cfg;
cfg.engine = "weights/superpoint_640x480_k1024.onnx.engine";
cfg.image_width = 640;
cfg.image_height = 480;
cfg.max_keypoints = 1024;

sptrt::SuperPointTrt detector(cfg);
detector.loadEngine();

std::vector<std::uint8_t> gray(detector.imagePixels());
sptrt::MonoImage image{0.0, detector.imageWidth(), detector.imageHeight(),
                       gray.data()};
auto frame = detector.detect(image);

Set image_width and image_height to match the exported ONNX/engine. MonoImage::data must point to a contiguous buffer of width * height bytes.

Build library

mkdir build && cd build
cmake .. -DCMAKE_BUILD_TYPE=Release
make -j8

Link against superpoint_trt and ensure CUDA/TensorRT libraries are on LD_LIBRARY_PATH.

Optional OpenCV visualization test

Requires OpenCV (core, imgcodecs, imgproc, features2d) and test images at test/data/img0.png, test/data/img1.png.

mkdir -p build && cd build
cmake .. -DCMAKE_BUILD_TYPE=Release -DSPTRT_BUILD_OPENCV_TESTS=ON
make -j8
./sptrt_opencv_tests --gtest_filter=SuperPointTrt.DetectMatchAndVisualizeOpenCvImages

Writes match visualizations to build/test/superpoint_bruteforce_matches.png (SuperPoint descriptor L2 + ratio test) and build/test/orb_bruteforce_matches.png (ORB Hamming + ratio test, up to 1024 features), plus per-image keypoint overlays at build/test/img0_keypoints.png and build/test/img1_keypoints.png.

Results

Example output from the OpenCV visualization test on test/data/img0.png and test/data/img1.png (640×480 inference, up to 1024 keypoints). SuperPoint detect() average: ~6.1 ms per frame on an NVIDIA GeForce RTX 4090 Laptop GPU (after warmup).

img0 keypoints img1 keypoints
SuperPoint keypoints on img0 SuperPoint keypoints on img1

Brute-force matches (SuperPoint descriptor L2 + Lowe ratio test; 132 accepted):

SuperPoint brute-force matches

Brute-force matches (ORB descriptor Hamming distance + Lowe ratio test; 111 accepted) ORB brute-force matches

Notes

  • SuperPoint ONNX uses a fixed input resolution and max_keypoints (top-k on the score map). Re-export when changing resolution or keypoint budget.
  • SuperPoint weights follow the rpautrat PyTorch port (weights/superpoint_v6_from_tf.pth).

License

SuperPoint rpautrat PyTorch port: MIT.