OpenCV Point(x,y)表示(列,行)或(行,列) [英] OpenCV Point(x,y) represent (column,row) or (row,column)

查看:319
本文介绍了OpenCV Point(x,y)表示(列,行)或(行,列)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在矩阵src中有一个300x200的图片.我正在对图像执行以下操作.

I have a 300x200 image in a Matrix src. I am doing the following operation on the image.

for(int i=0;i<src.rows;i++){
  for(int j=0;j<src.cols;j++){
    line( src, Point(i,j),Point(i,j), Scalar( 255, 0, 0 ),  1,8 );
  }
}
imshow("A",src);
waitKey(0);

我希望它能以白色覆盖整个图像,但是图像的下部仍然是空白.如果我这样做

I was expecting it to cover the entire image in white, but lower portion of the image remain empty. While if I do this

  for(int i=0;i<src.rows;i++){
    for(int j=0;j<src.cols;j++){
      src.at<uchar>(i,j)=255;
    }
  }
  imshow("A",src);
  waitKey(0);

整个图像以白色覆盖.因此,这意味着src.at<uchar>(i,j)使用(i,j)作为(行,列),而Point(x,y)使用(x,y)作为(列,行)

Entire image is covered in white. So, this means that src.at<uchar>(i,j) is using (i,j) as (row,column) but Point(x,y) is using (x,y) as (column,row)

推荐答案

因此,这意味着src.at(i,j)使用(i,j)作为(行,列),而Point(x,y)使用(x,y)作为(列,行)

So, this means that src.at(i,j) is using (i,j) as (row,column) but Point(x,y) is using (x,y) as (column,row)

是的!因为这似乎使很多人感到困惑,所以我会写我的解释,原因是:

That is right! Since this seems to confuse many people I'll write my interpreation for the reason:

在OpenCV中,cv::Mat用于图像和矩阵,因为离散图像与矩阵基本相同.

In OpenCV, cv::Mat is used for both, images and matrices, since a discrete image is basically the same as a matrix.

在数学中,我们有一些不同的东西:

In mathematics, we have some different things:

  1. 具有多行和多列的矩阵.
  2. 具有多个轴的图形(具有功能),并以图像形式图形表示图形.
  3. 点,这些点由通常是笛卡尔坐标的坐标系的轴排序.


1..对于矩阵,数学符号按行主要顺序排序


1. For matrices the mathematical notation is to order in row-major-order which is

按照传统的矩阵表示法,行由二维数组的第一个索引编号,列由第二个索引编号,即a1,2是第一行的第二个元素,向下和向右计数. (请注意,这与笛卡尔惯例相反.)

Following conventional matrix notation, rows are numbered by the first index of a two-dimensional array and columns by the second index, i.e., a1,2 is the second element of the first row, counting downwards and rightwards. (Note this is the opposite of Cartesian conventions.)

来自 http://en.wikipedia.org/wiki/Row-major_order#说明_和_示例

与数学中一样,第0行,第0列是矩阵的左上角元素.行/列就像在表格中一样.

As in mathematics, row:0, column:0 is the top-left element of the matrix. Row/column are just like in tables...

0/0---column--->
 |
 |
row
 |
 |
 v


2..对于 Points ,选择了满足以下两个条件的坐标系:1.它使用与矩阵符号相同的单位尺寸和相同的原点" ,因此左上角是Point(0,0),轴长度1表示1行或1列的长度. 2.它使用图像符号"进行轴排序,这意味着横坐标(水平轴)是指定x方向的第一个值,而纵坐标(垂直轴)是指定y方向的第二个值.


2. For Points a coordinate system is chosen that fulfils two things: 1. it uses the same unit-sizes and the same "origin" as the matrix notation, so top-left is Point(0,0) and axis length 1 means the length of 1 row or 1 column. 2. it uses "image notation" for axis-ordering, which means that abscissa (horizontal axis) is the first value designating the x-direction and the ordinate (vertical axis) is the second value designating the y-direction.

轴相交的点是两条数字线的共同原点,简称为原点.通常将其标记为O,如果这样,则将轴称为Ox和Oy.定义了x轴和y轴的平面通常称为笛卡尔平面或xy平面. x的值称为x坐标或横坐标,y的值称为y坐标或纵坐标.

The point where the axes meet is the common origin of the two number lines and is simply called the origin. It is often labeled O and if so then the axes are called Ox and Oy. A plane with x- and y-axes defined is often referred to as the Cartesian plane or xy plane. The value of x is called the x-coordinate or abscissa and the value of y is called the y-coordinate or ordinate.

字母的选择来自原始约定,即使用字母的后半部分指示未知值.字母表的第一部分用于指定已知值.

The choices of letters come from the original convention, which is to use the latter part of the alphabet to indicate unknown values. The first part of the alphabet was used to designate known values.

http://en.wikipedia.org/wiki/Cartesian_coordinate_system#Two_dimensions

因此,在一个理想的世界中,我们将点/图像的坐标系选择为:

so in a perfect world we would choose the coordinate system of points/images to be:

 ^
 |
 |
 Y
 |
 |
0/0---X--->

但是由于我们希望该原点位于左上角,而正值要向下移动,因此它是:

but since we want to have that origin in top-left and positive values to go to bottom, it is instead:

0/0---X--->
 |
 |
 Y
 |
 |
 v


因此对于图像处理人员来说,行优先表示法可能很奇怪,但是对于数学家来说,x轴优先表示法访问矩阵很奇怪.


So for image processing people row-first notation might be weird, but for mathematicans x-axis-first would be strange to access a matrix.

因此在OpenCV中,您可以使用:mat.at<type>(row,column)mat.at<type>(cv::Point(x,y))来访问同一点,如果x=columny=row完全理解=)

So in OpenCV you can use: mat.at<type>(row,column) or mat.at<type>(cv::Point(x,y)) to access the same point if x=column and y=row which is perfectly comprehensible =)

希望这个正确.我对这些符号了解不多,但这就是我在数学和图像处理方面的经验告诉我的.

Hope this correct. I don't know much about the notations, but that's what my experience in mathematics and imaging tells me.

这篇关于OpenCV Point(x,y)表示(列,行)或(行,列)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆