- 如果不是要改进SuperPoint的模型的话,并没有必要重新训练。
- SP在准确度上相比SIFT、SURF传统视觉方法有了提升,而且作者也提供了不错的预训练模型,如果仅需要提取特征点,或提取单应矩阵,可直接从demo的代码入手。
- 花了一整晚拜读了
match_features_demo.py
的代码,在关键处都加了中文注释。便于将SuperPoint强大的特征提取能力快速应用于新的 idea~ - 除了tensorflow,opencv和numpy再无其它依赖,并且tf也不需要gpu版,简单易用
(2020.4.17)
不过有一个问题,这个版本的superpoint强在可以用自己的数据训练,但是如果仅仅用于提取特征的话,还是应该用magicleap版。
对于一张240x320的图片,该版本在我的5500U上需要1.5s左右,而原版只需0.7s。速度差了一倍,而拼接质量相似
感觉sp论文里讲的实时性并没有那么实时,或者说只有在120x160这样的迷你图片才可以达到5fps左右的勉强实时,然而opencv里优化后的sift可以在0.05s内完成)
##Author: https://github.com/rpautrat/SuperPoint
import argparse
from pathlib import Path
import cv2
import numpy as np
import tensorflow as tf # noqa: E402
from settings import EXPER_PATH # noqa: E402
def extract_SIFT_keypoints_and_descriptors(img):
gray_img = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
sift = cv2.xfeatures2d.SIFT_create()
kp, desc = sift.detectAndCompute(np.squeeze(gray_img), None)
return kp, desc
def extract_superpoint_keypoints_and_descriptors(keypoint_map, descriptor_map,
keep_k_points=1000):
def select_k_best(points, k):
""" Select the k most probable points (and strip their proba).
points has shape (num_points, 3) where the last coordinate is the proba. """
sorted_prob = points[points[:, 2].argsort(), :2]
start = min(k, points.shape[0])
return sorted_prob[-start:, :]
# Extract keypoints
keypoints = np.where(keypoint_map > 0)
prob = keypoint_map[keypoints[0], keypoints[1]]
#分别是所有的横坐标和所有的纵坐标,取出来的是所有概率值
keypoints = np.stack([keypoints[0], keypoints[1], prob], axis=-1)
#此时的keypoints是(n,3),n是疑似特征点的个数,3是横坐标,纵坐标,概率值
keypoints = select_k_best(keypoints, keep_k_points)
keypoints = keypoints.astype(int)
# Get descriptors for keypoints
desc = descriptor_map[keypoints