当前位置: 首页 > news >正文

OpenCV旋转估计(4)生成一个字符串表示的匹配图函数 matchesGraphAsString()

  • 操作系统:ubuntu22.04
  • OpenCV版本:OpenCV4.9
  • IDE:Visual Studio Code
  • 编程语言:C++11

算法描述

matchesGraphAsString 函数是OpenCV库中的一部分,位于 cv::detail 命名空间下。这个函数的主要作用是生成一个字符串表示的匹配图(matches graph),其中包含了一系列图像路径和它们之间的匹配信息。这对于调试或者可视化图像拼接过程中的匹配关系非常有用。

函数原型

String cv::detail::matchesGraphAsString 	
(
	 	std::vector< String > &  	paths,
		std::vector< MatchesInfo > &  	pairwise_matches,
		float  	conf_threshold 
) 	

参数

  • paths: 一个字符串向量,包含了参与匹配的所有图像的路径。
  • pairwise_matches: 包含了每对图像之间匹配信息的向量。每个MatchesInfo结构体通常包含关键点匹配、匹配的质量等信息。
  • conf_threshold: 置信度阈值,用于过滤掉那些被认为不够可靠的匹配。

返回值

返回一个字符串,表示图像匹配图。该字符串格式化为易于阅读的形式,可以用来展示哪些图像与哪些图像相匹配及其置信度等信息。

代码示例

#include <iostream>
#include <opencv2/opencv.hpp>
#include <opencv2/stitching/detail/matchers.hpp>
#include <vector>

using namespace cv;
using namespace cv::detail;

int main()
{
    // 示例图像路径
    std::vector< String > paths = { "/media/dingxin/data/study/OpenCV/sources/images/stich1.png", "/media/dingxin/data/study/OpenCV/sources/images/stich2.png" };

    // 加载图像
    std::vector< Mat > images;
    for ( const auto& path : paths )
    {
        Mat img = imread( path );
        if ( img.empty() )
        {
            std::cerr << "无法加载图像: " << path << std::endl;
            return -1;
        }
        images.push_back( img );
    }

    // 初始化特征检测器和描述符提取器
    Ptr< Feature2D > detector = ORB::create();
    std::vector< std::vector< KeyPoint > > keypoints( images.size() );
    std::vector< Mat > descriptors( images.size() );

    // 检测关键点并计算描述符
    for ( size_t i = 0; i < images.size(); ++i )
    {
        detector->detectAndCompute( images[ i ], noArray(), keypoints[ i ], descriptors[ i ] );
    }

    // 匹配描述符
    std::vector< MatchesInfo > pairwise_matches;
    BFMatcher matcher( NORM_HAMMING );
    for ( size_t i = 0; i < images.size(); ++i )
    {
        for ( size_t j = i + 1; j < images.size(); ++j )
        {
            std::vector< DMatch > matches;
            matcher.match( descriptors[ i ], descriptors[ j ], matches );

            MatchesInfo mi;
            mi.src_img_idx = static_cast< int >( i );
            mi.dst_img_idx = static_cast< int >( j );
            mi.matches     = matches;
            // 假设这里我们简单地设置了置信度为1.0f,实际应用中应根据实际情况设置
            mi.confidence = 1.0f;
            pairwise_matches.push_back( mi );
        }
    }

    // 设置置信度阈值
    float conf_threshold = 1.0f;

    try
    {
        // 调用matchesGraphAsString函数
        String matches_graph_string = matchesGraphAsString( paths, pairwise_matches, conf_threshold );
        std::cout << "Matches Graph:\n" << matches_graph_string << std::endl;
    }
    catch ( const std::exception& e )
    {
        std::cerr << "运行时错误: " << e.what() << std::endl;
        return -1;
    }

    return 0;
}

运行结果

Matches Graph:
graph matches_graph{
"stich1.png";
"stich2.png";
}

相关文章:

  • 区块链学习总结
  • DDT数据驱动
  • 说一下yolo的一些概念 和 自己对 置信度阈值 和图像处理模板匹配的理解
  • java设计模式之建造者模式《装修启示录》​
  • 基于DrissionPage的DY无水印视频采集
  • C++与OO思想的联系
  • React 18 如何定义变量,及赋值 与渲染
  • python网络爬虫开发实战之网页数据的解析提取
  • docker常见的命令详细介绍
  • java小白日记38(集合-List)
  • 来源于胡椒的亚甲二氧桥CYP450-文献精读119
  • Android Window浮窗UI组件使用JetPack
  • 剑指 Offer II 111. 计算除法
  • 如何在 Linux 系统中部署 FTP 服务器:从基础配置到安全优化
  • Softmax温度调节与注意力缩放:深度神经网络中的平滑艺术
  • iStoreOS软路由对硬盘格式化分区(转化ext4)
  • Redisson分布式锁(超时释放及锁续期)
  • 已安装MFC,仍然提示“error MSB8041: 此项目需要 MFC 库”
  • 14:00面试,15:00就出来了,问的问题过于变态了。。。
  • golang errgroup用法介绍结合
  • 著名蒙古族音乐学者马•斯尔古愣逝世,享年86岁
  • 航行警告:渤海海峡黄海北部执行军事任务,禁止驶入
  • 普京提议于15日在土耳其恢复俄乌直接谈判
  • 这座古村,藏着多少赣韵风华
  • 巴西总统卢拉将访华
  • 白宫启动“返乡计划” ,鼓励非法移民自愿离开美国