opencv范围矩阵操作与矩阵运算

在opencv中使用Rect获取范围矩阵:

//Rect类使用
    Mat matrix = (Mat_(5,5)<<1,2,3,4,5,
        6,7,8,9,10,
        11,12,13,14,15,
        16,17,18,19,20,
        21,22,23,24,25);
    cout << matrix << endl;
    Mat rx1 = matrix(Rect(Point(2, 1), Point(3, 2)));
    cout << rx1 << endl;
    Mat rx2 = matrix(Rect(2,1,2,2));
    cout << rx2 << endl;
    Mat rx3 = matrix(Rect(Point(2, 1), Size(2, 2)));
    cout << rx3 << endl;
    //矩阵范围元素克隆
    Mat rx4 = matrix(Rect(Point(2, 1), Size(2, 2))).clone();
    cout << rx4 << endl;
    //矩阵范围元素克隆
    Mat rx5;
    matrix(Rect(Point(2, 1), Size(2, 2))).copyTo(rx5);
    cout << rx5 << endl;

    //矩阵运算,注:uchar最大值255,大于255截断
    Mat s1 = (Mat_(2, 3) << 23, 123, 90, 100, 250, 0);
    Mat s2 = (Mat_(2, 3) << 125

你可能感兴趣的:(OpenCV开发,Python,C++,opencv,c++,python)