1. 程式人生 > >opencv 影象row、col座標對應關係

opencv 影象row、col座標對應關係

宣告:本內容轉載自https://blog.csdn.net/u010189457/article/details/71553436?utm_source=itdadao&utm_medium=referral,只為閱讀方便。

行列與座標系對應關係 
行rows:Y 
列cols:X 
注意!注意!注意! 
在Mat型別變數訪問時下標是反著寫的,即:按照(y, x)的關係形式訪問,下面通過程式碼展示來說明這一點

#include "opencv2/core.hpp"
#include "opencv2/imgproc.hpp"
#include "opencv2/highgui.hpp"

#include <iostream>

using namespace cv;
using namespace std;

int main()
{
    Mat mat_src = Mat::eye(3, 4, CV_8UC1);

    cout << "mat_src :" << endl;
    cout << mat_src    << endl;

    cout << endl;
    cout << "Rows : " << mat_src.rows << endl;
    cout << "Cols : " << mat_src.cols << endl;

    //注: mat_src.at<float>(y, x), 下標關係為: y-x
    mat_src.at<float>(0, 2) = 2; 
    mat_src.at<float>(2, 0) = 4;

    cout << endl;
    cout << "mat_src :" << endl;
    cout << mat_src    << endl;

    return 0;
}