CVPR2021配准算法LoFTR的配置(LoFTR: Detector-Free Local Feature Matching with Transformers)
2021/10/5 1:11:59
本文主要是介绍CVPR2021配准算法LoFTR的配置(LoFTR: Detector-Free Local Feature Matching with Transformers),对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!
1、论文下载地址:
https://arxiv.org/pdf/2104.00680.pdf
2、代码下载地址:
https://github.com/zju3dv/LoFTR
3、新建虚拟python环境并激活
conda create -n LoFTR python=3.7 source activate LoFTR
4、安装需要的库
pip install torch==1.6.0 einops yacs kornia opencv-python matplotlib
5、下载额外库
在如下网址https://raw.githubusercontent.com/magicleap/SuperGluePretrainedNetwork/master/models/superglue.py
下载superglue.py
然后放到路径src/loftr/utils
6、下载预训练模型
链接:https://pan.baidu.com/s/1dwUDx6A9lRMBkCSowLIz5Q
提取码:jlcl
放到路径:weights/outdoor_ds.ckpt
7、demo运行
1)加入工程路径环境变量:
export PYTHONPATH=$PYTHONPATH:/home1/users/XXX/Codes/LoFTR-master/
2)新建mydemo.py写入如下代码:
import os os.chdir("..") from copy import deepcopy # import os # os.environ["CUDA_VISIBLE_DEVICES"] = "0" import torch import cv2 import numpy as np import matplotlib.cm as cm from src.utils.plotting import make_matching_figure from src.loftr import LoFTR, default_cfg # The default config uses dual-softmax. # The outdoor and indoor models share the same config. # You can change the default values like thr and coarse_match_type. matcher = LoFTR(config=default_cfg) matcher.load_state_dict(torch.load("/home1/users/XXX/Codes/LoFTR-master/weights/outdoor_ds.ckpt")['state_dict']) matcher = matcher.eval().cuda() default_cfg['coarse'] # Load example images img0_pth = "/home1/users/XXX/Codes/LoFTR-master/assets/phototourism_sample_images/united_states_capitol_26757027_6717084061.jpg" img1_pth = "/home1/users/XXX/Codes/LoFTR-master/assets/phototourism_sample_images/united_states_capitol_98169888_3347710852.jpg" img0_raw = cv2.imread(img0_pth, cv2.IMREAD_GRAYSCALE) img1_raw = cv2.imread(img1_pth, cv2.IMREAD_GRAYSCALE) img0_raw = cv2.resize(img0_raw, (img0_raw.shape[1]//8*8, img0_raw.shape[0]//8*8)) # input size shuold be divisible by 8 img1_raw = cv2.resize(img1_raw, (img1_raw.shape[1]//8*8, img1_raw.shape[0]//8*8)) img0 = torch.from_numpy(img0_raw)[None][None].cuda() / 255. img1 = torch.from_numpy(img1_raw)[None][None].cuda() / 255. batch = {'image0': img0, 'image1': img1} # Inference with LoFTR and get prediction with torch.no_grad(): matcher(batch) mkpts0 = batch['mkpts0_f'].cpu().numpy() mkpts1 = batch['mkpts1_f'].cpu().numpy() mconf = batch['mconf'].cpu().numpy() # Draw color = cm.jet(mconf) text = [ 'LoFTR', 'Matches: {}'.format(len(mkpts0)), ] fig = make_matching_figure(img0_raw, img1_raw, mkpts0, mkpts1, color, text=text,path="LoFTR-master/LoFTR-colab-demo.pdf")
3)运行python mydemo.py得到结果:
这篇关于CVPR2021配准算法LoFTR的配置(LoFTR: Detector-Free Local Feature Matching with Transformers)的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!
- 2024-11-23增量更新怎么做?-icode9专业技术文章分享
- 2024-11-23压缩包加密方案有哪些?-icode9专业技术文章分享
- 2024-11-23用shell怎么写一个开机时自动同步远程仓库的代码?-icode9专业技术文章分享
- 2024-11-23webman可以同步自己的仓库吗?-icode9专业技术文章分享
- 2024-11-23在 Webman 中怎么判断是否有某命令进程正在运行?-icode9专业技术文章分享
- 2024-11-23如何重置new Swiper?-icode9专业技术文章分享
- 2024-11-23oss直传有什么好处?-icode9专业技术文章分享
- 2024-11-23如何将oss直传封装成一个组件在其他页面调用时都可以使用?-icode9专业技术文章分享
- 2024-11-23怎么使用laravel 11在代码里获取路由列表?-icode9专业技术文章分享
- 2024-11-22怎么实现ansible playbook 备份代码中命名包含时间戳功能?-icode9专业技术文章分享