欢迎来到尧图网

客户服务 关于我们

您的位置:首页 > 财经 > 创投人物 > OpenCV 图形API(67)图像与通道拼接函数-----水平拼接(横向连接)两个输入矩阵(GMat 类型)函数concatHor()

OpenCV 图形API(67)图像与通道拼接函数-----水平拼接(横向连接)两个输入矩阵(GMat 类型)函数concatHor()

2025/4/29 16:59:14 来源:https://blog.csdn.net/jndingxin/article/details/147574833  浏览:    关键词:OpenCV 图形API(67)图像与通道拼接函数-----水平拼接(横向连接)两个输入矩阵(GMat 类型)函数concatHor()
  • 操作系统:ubuntu22.04
  • OpenCV版本:OpenCV4.9
  • IDE:Visual Studio Code
  • 编程语言:C++11

算法描述

该函数用于水平拼接两个 GMat 矩阵,要求输入矩阵的行数必须一致:

GMat A = { 1, 4,2, 5,3, 6 };
GMat B = { 7, 10,8, 11,9, 12 };
GMat C = gapi::concatHor(A, B);
//C:
//[1, 4, 7, 10;
// 2, 5, 8, 11;
// 3, 6, 9, 12]

输出矩阵的行数和数据类型必须与 src1 和 src2 相同,其列数为 src1 和 src2 列数之和。支持的矩阵数据类型包括:CV_8UC1、CV_8UC3、CV_16UC1、CV_16SC1、CV_32FC1。

注意

该函数的文本标识符为 “org.opencv.imgproc.transform.concatHor”。

参数

  • 参数 src1:第一个输入矩阵(参与水平拼接)。

  • 参数 src2:第二个输入矩阵(参与水平拼接)。

返回值

返回一个新的 GMat,表示水平拼接后的结果。

代码示例

#include <iostream>
#include <opencv2/gapi.hpp>
#include <opencv2/gapi/core.hpp>
#include <opencv2/opencv.hpp>int main()
{// 读取图像(确保尺寸和类型匹配)cv::Mat mat1 = cv::imread( "/media/dingxin/data/study/OpenCV/sources/images/stich1.png", cv::IMREAD_COLOR );cv::Mat mat2 = cv::imread( "/media/dingxin/data/study/OpenCV/sources/images/stich2.png", cv::IMREAD_COLOR );if ( mat1.empty() || mat2.empty() ){std::cerr << "无法加载图像!" << std::endl;return -1;}// 强制统一尺寸和类型(G-API不会自动调整)if ( mat1.rows != mat2.rows ){cv::resize( mat2, mat2, cv::Size( mat2.cols, mat1.rows ) );}if ( mat1.type() != mat2.type() ){mat2.convertTo( mat2, mat1.type() );}// 构建G-API计算图cv::GMat in1, in2;cv::GMat out = cv::gapi::concatHor( in1, in2 );cv::GComputation comp( cv::GIn( in1, in2 ), cv::GOut( out ) );// 执行计算图cv::Mat result;comp.apply( cv::gin( mat1, mat2 ), cv::gout( result ) );cv::imshow( "G-API拼接结果", result );cv::waitKey( 0 );return 0;
}

运行结果

在这里插入图片描述

版权声明:

本网仅为发布的内容提供存储空间,不对发表、转载的内容提供任何形式的保证。凡本网注明“来源:XXX网络”的作品,均转载自其它媒体,著作权归作者所有,商业转载请联系作者获得授权,非商业转载请注明出处。

我们尊重并感谢每一位作者,均已注明文章来源和作者。如因作品内容、版权或其它问题,请及时与我们联系,联系邮箱:809451989@qq.com,投稿邮箱:809451989@qq.com

热搜词