OpenCV Point(x,y) 表示 (column,row) 或 (row,column)
我在矩阵 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
使用 (i,j)
作为 (row,column) 但 Point(x,y)
使用 (x,y)
作为 (column,row)
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)
作为 (row,column) 但Point(x,y)
使用(x,y)
作为 (column,row)
So, this means that
src.at(i,j)
is using(i,j)
as (row,column) butPoint(x,y)
is using(x,y)
as (column,row)
没错!因为这似乎让很多人感到困惑,所以我将写下我的解释:
That is right! Since this seems to confuse many people I'll write my interpretation 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.对于矩阵,数学符号是按行主序排列,即
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#说明_and_example
在数学中,row:0, column: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.对于点,选择一个满足两件事的坐标系:1.它使用相同的单位大小和相同的起源"作为矩阵符号,所以左上角是 Point(0,0) 轴长度 1 表示 1 行或 1 列的长度.2. 它使用图像符号";对于轴排序,这意味着横坐标(水平轴)是指定 x 方向的第一个值,而纵坐标(垂直轴)是指定 y 方向的第二个值.
2. For Points, a coordinate system is chosen that fulfills 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 the bottom, it is instead:
0/0---X--->
|
|
Y
|
|
v
因此,对于图像处理来说,行优先表示法可能很奇怪,但对于数学家来说,x 轴优先访问矩阵会很奇怪.
So, for image processing people row-first notation might be weird, but for mathematicians x-axis-first would be strange to access a matrix.
因此,在 OpenCV 中,您可以使用:mat.at
或 mat.at
访问同一点,如果 x=column
和 y=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.
相关文章