問題描述
我在矩陣 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.
在數(shù)學(xué)中,我們有一些不同的東西:
In mathematics, we have some different things:
- 矩陣,具有多行多列.
- (函數(shù)的)圖形,具有多個軸并以圖像的形式以圖形方式表示圖形.
- 點,按坐標(biāo)系的軸排序,坐標(biāo)系通常是笛卡爾坐標(biāo).
1.對于矩陣,數(shù)學(xué)符號是按行主序排列,即
1. For matrices, the mathematical notation is to order in row-major-order which is
按照傳統(tǒng)的矩陣表示法,行按二維數(shù)組的第一個索引編號,列按第二個索引編號,即 a1,2 是第一行的第二個元素,向下和向右計數(shù).(請注意,這與笛卡爾約定相反.)
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
在數(shù)學(xué)中,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.對于點,選擇一個滿足兩件事的坐標(biāo)系:1.它使用相同的單位大小和相同的起源"作為矩陣符號,所以左上角是 Point(0,0) 軸長度 1 表示 1 行或 1 列的長度.2. 它使用圖像符號";對于軸排序,這意味著橫坐標(biāo)(水平軸)是指定 x 方向的第一個值,而縱坐標(biāo)(垂直軸)是指定 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.
軸線相交的點是兩條數(shù)軸的共同原點,簡稱原點.它通常標(biāo)記為 O,如果是,則軸稱為 Ox 和 Oy.定義了 x 軸和 y 軸的平面通常稱為笛卡爾平面或 xy 平面.x 的值稱為 x 坐標(biāo)或橫坐標(biāo),y 的值稱為 y 坐標(biāo)或縱坐標(biāo).
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
所以在一個完美的世界中,我們會選擇點/圖像的坐標(biāo)系:
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
因此,對于圖像處理來說,行優(yōu)先表示法可能很奇怪,但對于數(shù)學(xué)家來說,x 軸優(yōu)先訪問矩陣會很奇怪.
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 =)
希望這是正確的.我不太了解符號,但這是我在數(shù)學(xué)和成像方面的經(jīng)驗告訴我的.
Hope this correct. I don't know much about the notations, but that's what my experience in mathematics and imaging tells me.
這篇關(guān)于OpenCV Point(x,y) 表示 (column,row) 或 (row,column)的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網(wǎng)!