Giter Club home page Giter Club logo

superpoint-lightglue-image-stiching's Introduction

简体中文 | English

DeepLearning-based-Feature-extraction-and-matching

将深度学习预训练模型 SuperPoint 和 LightGlue 集成到OpenCV拼接算法中。

OpenCV拼接流水线

图像特征提取与匹配是许多高级计算机视觉任务的基础,例如图像配准,图像拼接,相机矫正,SLAM,深度估计等等。 今天我们就以图像拼接为切入点,来看一下特征提取与匹配的重要性。

OpenCV中提供了封装程度非常高的Stitcher类,通过下面几行代码就能实现图像拼接。
Mat pano;
Ptr stitcher = Stitcher::create(mode);
Stitcher::Status status = stitcher->stitch(imgs, pano);

但图像拼接整个过程非常复杂。
用文字总结一下拼接算法的主要流程:
特征提取->特征匹配->评估相机参数->生成融合图像

其中特征提取最为重要,特征点和特征描述符的质量好坏决定了最终的拼接效果。

目前OpenCV中提供了SIFT,SURF,ORB等特征提取器。
目前OpenCV中提供了Brute-Force,FLANN,KNN等特征匹配器。

然后,通过下面代码将选择的特征提取和匹配算法设置到拼接流水线中。

if (feature_type == FeatureType::SURF)
stitcher->setFeaturesFinder(xfeatures2d::SURF::create());
else if (feature_type == FeatureType::SIFT)
stitcher->setFeaturesFinder(SIFT::create());
else
stitcher->setFeaturesFinder(ORB::create());

stitcher->setFeaturesMatcher(makePtrdetail::BestOf2NearestMatcher( false));
stitcher->setFeaturesMatcher(makePtrdetail::BestOf2NearestRangeMatcher( false));
stitcher->setFeaturesMatcher(makePtrdetail::AffineBestOf2NearestMatcher(true, false));

这要感谢C++面向对象编程的**,通过继承与多态来实现不同特征提取和匹配算法的扩展。

深度学习特征检测匹配算法

说到这里该我们的主角出场了,我们要为OpenCV追加一种深度学习特征提取算法:SuperPoint,以及深度学习特征匹配算法:LightGlue。
SuperPoint:​
[Paper] [源码]

​ LightGlue:
[Paper] [源码]

根据OpenCV中类继承体系,特征提取类的基类为Feature2D,特征匹配的基类为FeaturesMatcher,我们以此为基类新增两个类:SuperPoint和LightGlue,并重新实现基类的虚方法。
superpoint
lightglue

如何编译

目前仅在Windows 11,Visualstudio2019,Cmake3.26.4中测试成功
1.微信公众号回复【sl】获取预训练模型 ,模型路径通过参数传递给程序
微信公众号:人工智能大讲堂

后台回复【sl】获取上面的预训练模型和第三方依赖库。
2.微信公众号回复【sl】获取第三方库:OpenCV和ONNXRuntime,然后将其解压到源码目录,OPenCV是我用Visual Studio2019编译的。ONNXRuntime不需要自己编译,下载官网编译好的即可
最终的项目结构如下:
project_root/
|- common.h
|- superpoint.h
|- superpoint.cpp
|- lightglue.h
|- lightglue.cpp
|- cppDemo.cpp
|- opencv/
|- onnxruntime-win-x64-1.15.1/
|- CMakeLists.txt

3.打开Cmake,输入源码路径和编译输出路径,然后以此点积Config->Generate->Open Project

集成到OpenCV中

然后将新增加的类设置到拼接流水线中。
CPPDemo
std::wstring_convert<std::codecvt_utf8<wchar_t>> converter;
std::wstring sp = converter.from_bytes(superPointPath);
std::wstring lh = converter.from_bytes(lightGluePath);

Mat pano;
Ptr stitcher = Stitcher::create(mode);
Ptr superpointp = makePtr<SuperPoint>(sp);
Ptr lightglue = makePtr<LightGlue>(lh, mode);
stitcher->setPanoConfidenceThresh(0.1f);
stitcher->setFeaturesFinder(superpointp);//SpuerPoint feature extraction
stitcher->setFeaturesMatcher(lightglue);//LightGlue feature matching
Stitcher::Status status = stitcher->stitch(imgs, pano);

1.将onnxruntime.dll和opencv_world455.dll(opencv_world455d.dll debug模式)hdf5.dll,zlib.dll放到exe路径下
2.运行cppDemo.exe,并设置参数,例如--mode panorama --lg D:\superpoint_lightglue.onnx --sp --mthresh 0.25 D:\superpoint.onnx D:\1.jpg D:\2.jpg

拼接支持两种变换模型,仿射变换和透视变换,由--mode (panorama|scans)指定,panorama表示透视变换模型,scans代表仿射变换模型
--sp 指定superpoint onnx格式模型路径
--lg 指定lightflue onnx格式模型路径
--mthresh 指定匹配阈值
D:\1.jpg D:\2.jpg为拼接输入图像

拼接结果

特征匹配

拼接结果

特征匹配

拼接结果

特征匹配

对于不熟悉C++的,我还提供了C#Demo
CSharpDemo

GPU推理

对于推理性能有要求的,同时具备GPU硬件环境的,可以切换到GPU推理模式,方法如下:
1.根据GPU型号安装驱动。
2.下载onnxruntime GPU连接库
https://github.com/microsoft/onnxruntime/releases/download/v1.15.1/onnxruntime-win-x64-gpu-1.15.1.zip
2.按照CPU推理目录结构解压链接库压缩包。
3.重新编译源代码。
4.由于onnxruntime依赖cuda,可以安装cuda tookit,也可以只将cuda运行时dll拷贝到exe所在目录。
5.由于onnxruntime依赖cudnn,将cudnn dll拷贝到exe所在目录。 根据onnxruntime和cuda,cudnn版本对照表。
https://onnxruntime.ai/docs/execution-providers/CUDA-ExecutionProvider.html
cunda运行时dll,cudnn dll我已经为大家准备好了,关注微信公众号:人工智能大讲堂,后台回复og获取。

superpoint-lightglue-image-stiching's People

Contributors

aidajiangtang avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

superpoint-lightglue-image-stiching's Issues

LightGlue-ONNX End_to_End model

Hi,

It looks like it is worth to implement the end-to-end model:

FYI ... OroChippw/LightGlue-OnnxRunner#23
Recently LightGlue-ONNX released there fused model which improve the performance substantially(~2x faster in my test) and change the format of the output tensor, making the current code not functional
output_tensors[2] is now the shape of (matchnum, 2) and the pairs are already computed(so you don't need to compute them yourself)
output_tensors[3] is now the shape of (matchnum), which denotes the matching score of each match
The following simple hack should do the work:
code ...

Thanks,

-Scott

Question l meet about execution

Firstly ,thank you very much for your willingness to share your work.I got some problem when l attempt to run cppDemo.exe after i build the project.It turned out that it required “hdf5.dll“. I got it but it still told me something worng with that.So i add hdf5_hl.dll zlib.dll just now while it still doesn't work.

关于superpoint_lightglue.onnx模型是如何转化的问题

您好,
Q1:关于superpoint_lightglue.onnx模型,查看到他的模型输出matches,想问一下是如何转化的(如下图所示)?
image
Q2:与此同时为什么不将前部分的superpoint.onnx模型也集成在一起形成end to end模型,是出于什么考量吗?
Q3:当我使用lightglue官方提供的样例图,使用您的代码进行运行时,只出现了特征匹配的结果图,没出现拼接的结果图,是我的操作或脚本有什么问题吗
image

感谢您的回答与贡献

Cuda.

Hi, thanks for making this project available.
Does the onnx runtime use cuda? What is the inference time?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.