opencv将两幅图像拼在一起

网上看到的,来源忘记了

1.按列拼接

Mat mergeCols(Mat A, Mat B)
{
    CV_ASSERT(A.cols == B.cols&&A.type() == B.type());
    int totalCols = A.cols + B.cols;

    Mat mergedDescriptors(A.rows, totalCols, A.type());
    Mat submat = mergedDescriptors.colRange(0, A.cols);
    A.copyTo(submat);
    submat = mergedDescriptors.colRange(A.cols, totalCols);
    B.copyTo(submat);
    return mergedDescriptors;
 }

2.按行拼接

Mat mergeRows(Mat A, Mat B)
{
    CV_ASSERT(A.cols == B.cols&&A.type() == B.type());
    int totalRows = A.rows + B.rows;

    Mat mergedDescriptors(totalRows, A.cols, A.type());
    Mat submat = mergedDescriptors.rowRange(0, A.rows);
    A.copyTo(submat);
    submat = mergedDescriptors.rowRange(A.rows, totalRows);
    B.copyTo(submat);
    return mergedDescriptors;
 }


主要用到的函数 rowRange,colRange    copyTo 

你可能感兴趣的:(OPencv)