<img src="assets/magicleap.png" width="240">
### Research @ Magic Leap (CVPR 2020, Oral)
# SuperGlue Inference and Evaluation Demo Script
## Introduction
SuperGlue is a CVPR 2020 research project done at Magic Leap. The SuperGlue network is a Graph Neural Network combined with an Optimal Matching layer that is trained to perform matching on two sets of sparse image features. This repo includes PyTorch code and pretrained weights for running the SuperGlue matching network on top of [SuperPoint](https://arxiv.org/abs/1712.07629) keypoints and descriptors. Given a pair of images, you can use this repo to extract matching features across the image pair.
<p align="center">
<img src="assets/teaser.png" width="500">
</p>
SuperGlue operates as a "middle-end," performing context aggregation, matching, and filtering in a single end-to-end architecture. For more details, please see:
* Full paper PDF: [SuperGlue: Learning Feature Matching with Graph Neural Networks](https://arxiv.org/abs/1911.11763).
* Authors: *Paul-Edouard Sarlin, Daniel DeTone, Tomasz Malisiewicz, Andrew Rabinovich*
* Website: [psarlin.com/superglue](https://psarlin.com/superglue) for videos, slides, recent updates, and more visualizations.
* `hloc`: a new toolbox for visual localization and SfM with SuperGlue, available at [cvg/Hierarchical-Localization](https://github.com/cvg/Hierarchical-Localization/). Winner of 3 CVPR 2020 competitions on localization and image matching!
We provide two pre-trained weights files: an indoor model trained on ScanNet data, and an outdoor model trained on MegaDepth data. Both models are inside the [weights directory](./models/weights). By default, the demo will run the **indoor** model.
## Dependencies
* Python 3 >= 3.5
* PyTorch >= 1.1
* OpenCV >= 3.4 (4.1.2.30 recommended for best GUI keyboard interaction, see this [note](#additional-notes))
* Matplotlib >= 3.1
* NumPy >= 1.18
Simply run the following command: `pip3 install numpy opencv-python torch matplotlib`
## Contents
There are two main top-level scripts in this repo:
1. `demo_superglue.py` : runs a live demo on a webcam, IP camera, image directory or movie file
2. `match_pairs.py`: reads image pairs from files and dumps matches to disk (also runs evaluation if ground truth relative poses are provided)
## Live Matching Demo Script (`demo_superglue.py`)
This demo runs SuperPoint + SuperGlue feature matching on an anchor image and live image. You can update the anchor image by pressing the `n` key. The demo can read image streams from a USB or IP camera, a directory containing images, or a video file. You can pass all of these inputs using the `--input` flag.
### Run the demo on a live webcam
Run the demo on the default USB webcam (ID #0), running on a CUDA GPU if one is found:
```sh
./demo_superglue.py
```
Keyboard control:
* `n`: select the current frame as the anchor
* `e`/`r`: increase/decrease the keypoint confidence threshold
* `d`/`f`: increase/decrease the match filtering threshold
* `k`: toggle the visualization of keypoints
* `q`: quit
Run the demo on 320x240 images running on the CPU:
```sh
./demo_superglue.py --resize 320 240 --force_cpu
```
The `--resize` flag can be used to resize the input image in three ways:
1. `--resize` `width` `height` : will resize to exact `width` x `height` dimensions
2. `--resize` `max_dimension` : will resize largest input image dimension to `max_dimension`
3. `--resize` `-1` : will not resize (i.e. use original image dimensions)
The default will resize images to `640x480`.
### Run the demo on a directory of images
The `--input` flag also accepts a path to a directory. We provide a directory of sample images from a sequence. To run the demo on the directory of images in `freiburg_sequence/` on a headless server (will not display to the screen) and write the output visualization images to `dump_demo_sequence/`:
```sh
./demo_superglue.py --input assets/freiburg_sequence/ --output_dir dump_demo_sequence --resize 320 240 --no_display
```
You should see this output on the sample Freiburg-TUM RGBD sequence:
<img src="assets/freiburg_matches.gif" width="560">
The matches are colored by their predicted confidence in a jet colormap (Red: more confident, Blue: less confident).
### Additional useful command line parameters
* Use `--image_glob` to change the image file extension (default: `*.png`, `*.jpg`, `*.jpeg`).
* Use `--skip` to skip intermediate frames (default: `1`).
* Use `--max_length` to cap the total number of frames processed (default: `1000000`).
* Use `--show_keypoints` to visualize the detected keypoints (default: `False`).
## Run Matching+Evaluation (`match_pairs.py`)
This repo also contains a script `match_pairs.py` that runs the matching from a list of image pairs. With this script, you can:
* Run the matcher on a set of image pairs (no ground truth needed)
* Visualize the keypoints and matches, based on their confidence
* Evaluate and visualize the match correctness, if the ground truth relative poses and intrinsics are provided
* Save the keypoints, matches, and evaluation results for further processing
* Collate evaluation results over many pairs and generate result tables
### Matches only mode
The simplest usage of this script will process the image pairs listed in a given text file and dump the keypoints and matches to compressed numpy `npz` files. We provide the challenging ScanNet pairs from the main paper in `assets/example_indoor_pairs/`. Running the following will run SuperPoint + SuperGlue on each image pair, and dump the results to `dump_match_pairs/`:
```sh
./match_pairs.py
```
The resulting `.npz` files can be read from Python as follows:
```python
>>> import numpy as np
>>> path = 'dump_match_pairs/scene0711_00_frame-001680_scene0711_00_frame-001995_matches.npz'
>>> npz = np.load(path)
>>> npz.files
['keypoints0', 'keypoints1', 'matches', 'match_confidence']
>>> npz['keypoints0'].shape
(382, 2)
>>> npz['keypoints1'].shape
(391, 2)
>>> npz['matches'].shape
(382,)
>>> np.sum(npz['matches']>-1)
115
>>> npz['match_confidence'].shape
(382,)
```
For each keypoint in `keypoints0`, the `matches` array indicates the index of the matching keypoint in `keypoints1`, or `-1` if the keypoint is unmatched.
### Visualization mode
You can add the flag `--viz` to dump image outputs which visualize the matches:
```sh
./match_pairs.py --viz
```
You should see images like this inside of `dump_match_pairs/` (or something very close to it, see this [note](#a-note-on-reproducibility)):
<img src="assets/indoor_matches.png" width="560">
The matches are colored by their predicted confidence in a jet colormap (Red: more confident, Blue: less confident).
### Evaluation mode
You can also estimate the pose using RANSAC + Essential Matrix decomposition and evaluate it if the ground truth relative poses and intrinsics are provided in the input `.txt` files. Each `.txt` file contains three key ground truth matrices: a 3x3 intrinsics matrix of image0: `K0`, a 3x3 intrinsics matrix of image1: `K1` , and a 4x4 matrix of the relative pose extrinsics `T_0to1`.
To run the evaluation on the sample set of images (by default reading `assets/scannet_sample_pairs_with_gt.txt`), you can run:
```sh
./match_pairs.py --eval
```
Since you enabled `--eval`, you should see collated results printed to the terminal. For the example images provided, you should get the following numbers (or something very close to it, see this [note](#a-note-on-reproducibility)):
```txt
Evaluation Results (mean over 15 pairs):
AUC@5 AUC@10 AUC@20 Prec MScore
26.99 48.40 64.47 73.52 19.60
```
The resulting `.npz` files in `dump_match_pairs/` will now contain scalar values related to the evaluation, computed on the sample images provided. Here is what you should find in one of the generated evaluation files:
```python
>>> import numpy as np
>>> path = 'dump_match_pairs/scene0711_00_frame-001680_scene0711_00_frame-001995_evaluation.npz'
>>>
Just_a_Way_Plus
- 粉丝: 79
- 资源: 23
最新资源
- Matlab语音识别技术:利用GMM和MFCC实现说话内容与说话人的精准识别,含训练集与测试集说明 ,Matlab语音识别,识别说话内容、识别说话人等,使用GMM和MFCC,有训练集和测试集,带说明等
- 基于改进下垂控制的混合储能系统稳压与微电网控制研究,改进下垂控制、微电网控制方向 1、纯阻性负载和冲击负载对母线电压稳压(simulink) 对蓄电池和超级电容的功率分配问题 2、程序创新点是:采用新
- "基于Cruise与Matlab dll的纯电动汽车前后轴电机双驱模型联合仿真研究:控制策略详解与能量管理开发实践",Cruise与Matlab dll方式联合仿真 纯电动汽车前后轴电机双驱模型 有控
- 基于STM32H750的MPU9250姿态角解算程序:无迹卡尔曼滤波校准与数据保存显示,mpu9250姿态角解算程序 方法:无迹卡尔曼滤波UKF mcu:默认stm32h750 743 驱动:spi
- "非球面匀光技术:复眼透镜与微透镜阵列的完美融合,实现矩形光与圆形光的均匀分布",匀光合集 非球面匀光、复眼透镜匀光、匀光、微透镜阵列匀光 矩形光 圆形光 ,核心关键词:匀光合集; 非球面匀光; 复眼
- "COOMSOL超声仿真:基于复合材料空气耦合的超声单侧检测模型与声传播仿真研究",COOMSOL超声仿真-复合材料空气耦合超声单侧检测仿真研究(lunwen仿真) 模型介绍:本模型采用压力声学、固
- 自适应等效氢耗最小化策略下的燃料电池混合动力汽车能量管理优化方案,基于自适应等效氢耗最小化的燃料电池混合动力汽车能量管理策略 1.具有燃料电池-动力电池两个能量源; 2.利用等效氢耗最小化策略来实现燃
- 基于COMSOL的声表面波SAW传感器:行波驻波三维模型研究及电场、位移、深度方向的影响因素分析,COMSOL声表面波SAW行波驻波传感器铌酸锂128度Y切X传播三维模型 电场、位移、深度方向、叉指对
- 初学者必备的模拟IC设计课程:SMIC 0.18um锁相环电路,理想仿真,锁定频率达400MHz的VCO电路设计,模拟ic设计,smic0.18um的锁相环电路,较简单的结构,适合入门学习,可以直接仿
- 三相两电平整流器Simulink仿真:空间矢量调制与双闭环控制策略下的电压电流追踪性能表现与电阻调节指南(MATLAB版本兼容),三相两电平整流器simulink仿真 (可提供资料来源以及轻微) 空间
- 基于Comsol动网格技术的流固耦合仿真研究与应用,comsol动网格,流固耦合仿真 ,核心关键词:comsol动网格; 流固耦合仿真; 仿真技术; 动态网格; 流体与结构相互作用仿真 ,"COMSO
- 基于改进A*算法的AGV路径规划仿真:灵活地图切换与起点终点自定义,基于改进A*算法的AGV路径规划算法仿真代码 改进对比结果如下 可自行更改地图,起始点目标点 ,基于改进A*算法的AGV路径规划;
- 多智能体系统动态事件触发一致性研究:以航天器模型为例,文献支持下的高效效果探索,多智能体系统,一致性,事件触发,动态事件触发一致性,航天器模型为例,效果好 有对应参考文献 ,核心关键词:多智能体系
- 具有通信时变时延和扰动的事件触发多智能体领导跟随一致性仿真研究:策略效果卓越,多智能体系统,一致性,事件触发,具有通信时变时延和扰动的事件触发的多智能体领导跟随一致性问题的仿真,效果良好 ,核心关
- 基于双层优化的电动汽车充放电行为时空协同调度研究:输电层与配电层协同优化策略实现与仿真分析,MATLAB代码:基于双层优化的电动汽车优化调度研究 关键词:双层优化 选址定容 输配协同 时空优化
- 基于改进A*算法与人工势场融合技术的路径规划解决方案 融合全局规划,解决目标不可达及局部最优陷阱问题,附对比代码,代码销售不退 ,基于融合改进A*算法的改进人工势场算法的路径规划 融合改进A*算法,做
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈