• opencv图像水平/竖直拼接hconcat()/vconcat()


    图像水平拼接hconcat()

    hconcat函数在opencv中有如下三个重载函数:

    1. CV_EXPORTS void hconcat(const Mat src, size_t nsrc, OutputArray dst);*

    /** @brief Applies horizontal concatenation to given matrices.
    
    The function horizontally concatenates two or more cv::Mat matrices (with the same number of rows).
    @code{.cpp}
        cv::Mat matArray[] = { cv::Mat(4, 1, CV_8UC1, cv::Scalar(1)),
                               cv::Mat(4, 1, CV_8UC1, cv::Scalar(2)),
                               cv::Mat(4, 1, CV_8UC1, cv::Scalar(3)),};
    
        cv::Mat out;
        cv::hconcat( matArray, 3, out );
        //out:
        //[1, 2, 3;
        // 1, 2, 3;
        // 1, 2, 3;
        // 1, 2, 3]
    @endcode
    @param src input array or vector of matrices. all of the matrices must have the same number of rows and the same depth.
    @param nsrc number of matrices in src.
    @param dst output array. It has the same number of rows and depth as the src, and the sum of cols of the src.
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19

    2. CV_EXPORTS void hconcat(InputArray src1, InputArray src2, OutputArray dst);

     @code{.cpp}
        cv::Mat_ A = (cv::Mat_(3, 2) << 1, 4,
                                                      2, 5,
                                                      3, 6);
        cv::Mat_ B = (cv::Mat_(3, 2) << 7, 10,
                                                      8, 11,
                                                      9, 12);
    
        cv::Mat C;
        cv::hconcat(A, B, C);
        //C:
        //[1, 4, 7, 10;
        // 2, 5, 8, 11;
        // 3, 6, 9, 12]
     @endcode
     @param src1 first input array to be considered for horizontal concatenation.
     @param src2 second input array to be considered for horizontal concatenation.
     @param dst output array. It has the same number of rows and depth as the src1 and src2, and the sum of cols of the src1 and src2.
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18

    3.CV_EXPORTS_W void hconcat(InputArrayOfArrays src, OutputArray dst);

    /** @overload
     @code{.cpp}
        std::vector matrices = { cv::Mat(4, 1, CV_8UC1, cv::Scalar(1)),
                                          cv::Mat(4, 1, CV_8UC1, cv::Scalar(2)),
                                          cv::Mat(4, 1, CV_8UC1, cv::Scalar(3)),};
    
        cv::Mat out;
        cv::hconcat( matrices, out );
        //out:
        //[1, 2, 3;
        // 1, 2, 3;
        // 1, 2, 3;
        // 1, 2, 3]
     @endcode
     @param src input array or vector of matrices. all of the matrices must have the same number of rows and the same depth.
     @param dst output array. It has the same number of rows and depth as the src, and the sum of cols of the src.
    same depth.
     */
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18

    总结起来就一个要求,
    all of the matrices must have the same number of rows and the same depth.
    要进行图像的水平连接,各个源图像的行数(rows)必须相同(也就是图像的高必须相等),并且图像的通道数(depth)也需要相同。

    图像垂直拼接vconcat()

    有三个重载函数
    1. CV_EXPORTS void vconcat(const Mat src, size_t nsrc, OutputArray dst);*

    @code{.cpp}
        cv::Mat matArray[] = { cv::Mat(1, 4, CV_8UC1, cv::Scalar(1)),
                               cv::Mat(1, 4, CV_8UC1, cv::Scalar(2)),
                               cv::Mat(1, 4, CV_8UC1, cv::Scalar(3)),};
    
        cv::Mat out;
        cv::vconcat( matArray, 3, out );
        //out:
        //[1,   1,   1,   1;
        // 2,   2,   2,   2;
        // 3,   3,   3,   3]
    @endcode
    @param src input array or vector of matrices. all of the matrices must have the same number of cols and the same depth.
    @param nsrc number of matrices in src.
    @param dst output array. It has the same number of cols and depth as the src, and the sum of rows of the src.
    @sa cv::hconcat(const Mat*, size_t, OutputArray), @sa cv::hconcat(InputArrayOfArrays, OutputArray) and @sa cv::hconcat(InputArray, InputArray, OutputArray)
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16

    2. CV_EXPORTS void vconcat(InputArray src1, InputArray src2, OutputArray dst);

    /** @overload
     @code{.cpp}
        cv::Mat_ A = (cv::Mat_(3, 2) << 1, 7,
                                                      2, 8,
                                                      3, 9);
        cv::Mat_ B = (cv::Mat_(3, 2) << 4, 10,
                                                      5, 11,
                                                      6, 12);
    
        cv::Mat C;
        cv::vconcat(A, B, C);
        //C:
        //[1, 7;
        // 2, 8;
        // 3, 9;
        // 4, 10;
        // 5, 11;
        // 6, 12]
     @endcode
     @param src1 first input array to be considered for vertical concatenation.
     @param src2 second input array to be considered for vertical concatenation.
     @param dst output array. It has the same number of cols and depth as the src1 and src2, and the sum of rows of the src1 and src2.
     */
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23

    3. CV_EXPORTS_W void vconcat(InputArrayOfArrays src, OutputArray dst);

    /** @overload
     @code{.cpp}
        std::vector matrices = { cv::Mat(1, 4, CV_8UC1, cv::Scalar(1)),
                                          cv::Mat(1, 4, CV_8UC1, cv::Scalar(2)),
                                          cv::Mat(1, 4, CV_8UC1, cv::Scalar(3)),};
    
        cv::Mat out;
        cv::vconcat( matrices, out );
        //out:
        //[1,   1,   1,   1;
        // 2,   2,   2,   2;
        // 3,   3,   3,   3]
     @endcode
     @param src input array or vector of matrices. all of the matrices must have the same number of cols and the same depth
     @param dst output array. It has the same number of cols and depth as the src, and the sum of rows of the src.
    same depth.
     */
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17

    总结起来,要进行图像的竖向的拼接,也只有一个要求:
    all of the matrices must have the same number of cols and the same depth.
    需要图像的列数相等(即图像的宽度是相等的,cols),并且图像的通道数(depth)相等。

    参考链接:
    opencv hconcat和vconcat函数详解
    OpenCV双目相机的标定C++

  • 相关阅读:
    树链剖分与线段树
    【2024秋招】2023-9-16 贝壳后端开发一面
    OpenAI首席科学家:ChatGPT已经出现意识,人类未来将与AI融合
    js “2018/01-2018/12“转为“2018年01月-2018年12月“,字符串的替换和插入
    论文阅读 Fast Reinforcement Learning Via Slow Reinforcement Learning
    【网安小白成长之路】9.sql注入操作
    竞赛选题 基于设深度学习的人脸性别年龄识别系统
    java基于springboot实验室预约设备报修管理系统fu1ju
    API 与 SDK
    如何设计一条大型PLC生产线系统
  • 原文地址:https://blog.csdn.net/springslx/article/details/126712398