opencv将两幅图像拼在一起

来源:互联网 发布:人类实验室 网络暴力 编辑:程序博客网 时间:2024/06/06 13:59

网上看到的,来源忘记了

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