OPenCV中的Mat类中rowRange和colRange基本使用

    技术2026-08-29  9

    文章目录

    定义Mat::rowRange函数Mat::colRange函数

    定义

    rowRange为指定的行span创建一个新的矩阵头,可取指定行区间元素colRange为指定的列span创建一个新的矩阵头,可取指定列区间元素

    Mat::rowRange函数

    Mat::rowRange为矩阵的指定行区间创建一个矩阵头。

    C++: Mat Mat::rowRange(int startrow, int endrow) const C++: Mat Mat::rowRange(const Range& r) const

    Parameters:

    startrow – An inclusive 0-based start index of the row span.// 从0开始的行间距索引endrow – An exclusive 0-based ending index of the row span.//终止索引r – Range structure containing both the start and the end indices.

    The method makes a new header for the specified row span of the matrix. Similarly to Mat::row() and Mat::col() , this is an O(1) operation.

    Mat Test = (Mat_<double>(3,3) << 0,1,2, 3,4,5, 6,7,8); cout << "Total matrix:" << endl; cout << Test << endl; Mat testrow = Test.rowRange(0,1).clone(); cout << "Row range:" << endl; cout << testrow << endl; cout << "Test 1 row:" << endl; cout << Test.row(0) << endl; Mat testcol = Test.colRange(0,1).clone(); cout << "Col range:" << endl; cout << testcol << endl;

    Mat::colRange函数

    参考链接:https://blog.csdn.net/sinat_29089097/article/details/75533538

    Processed: 0.013, SQL: 9