OpenCV 行列值与坐标的对应关系

来源:互联网 发布:剑网3秀萝捏脸数据图片 编辑:程序博客网 时间:2024/06/08 18:07
注:OpenCV 版本3.2.0
  • OpenCV像素坐标系如下图所示:

这里写图片描述

  • 行列与坐标系对应关系
    行:Y
    列: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;}
  • 执行结果

这里写图片描述

0 0