May I know what does x represent? Does the content inside of () represent a pointer? then the [] is the element of the array?
我可以知道x代表什么? ()内的内容是否代表指针?那么[]是数组的元素?
x = (df_dx->imageData+i*df_dx->widthStep)[j];
why doesnt it work if i put it this way?
如果我这样说,为什么它不起作用?
x=df_dx[2][j];
Does the
是吗?
->imageData
give the pixel value of the image? The full code is below. THanks
给出图像的像素值?完整代码如下。谢谢
float x;
IplImage*df_dx = cvCreateImage(cvGetSize(grayimg),IPL_DEPTH_16S,1);
for(int i=0;i=grayimg->height;i++)
{
for(int j=0;grayimg->width;j++)
{
x = (df_dx->imageData+i*df_dx->widthStep)[j];
}
}
1 个解决方案
#1
1
Short answers:
简短的答案:
-
x
is the element on row j, column i of the matrixdf_dx
- x是矩阵df_dx的第j行第i列的元素
-
df_dx->imageData
returns a pointer to the first element of the array (top-left) - df_dx-> imageData返回指向数组第一个元素的指针(左上角)
Accessing matrix elements in such a way is actually quite common for 2d matrices stored in memory as flat one-dimensional arrays (see e.g. GSL matrix accesses for a similar example with another library; see also this post for a similar question).
以这种方式访问矩阵元素实际上对于存储在存储器中的2d矩阵作为平坦的一维阵列是很常见的(参见例如对于具有另一个库的类似示例的GSL矩阵访问;也参见该帖子以获得类似的问题)。
Storing a matrix as an array of arrays (i.e. using [][]
for access) is definitely manageable, and many people chose to use this representation, but there are reasons why one would prefer a flat layout in memory.
将矩阵存储为数组数组(即使用[] []进行访问)绝对是可管理的,并且许多人选择使用此表示,但有理由为什么人们更喜欢内存中的平面布局。
#1
1
Short answers:
简短的答案:
-
x
is the element on row j, column i of the matrixdf_dx
- x是矩阵df_dx的第j行第i列的元素
-
df_dx->imageData
returns a pointer to the first element of the array (top-left) - df_dx-> imageData返回指向数组第一个元素的指针(左上角)
Accessing matrix elements in such a way is actually quite common for 2d matrices stored in memory as flat one-dimensional arrays (see e.g. GSL matrix accesses for a similar example with another library; see also this post for a similar question).
以这种方式访问矩阵元素实际上对于存储在存储器中的2d矩阵作为平坦的一维阵列是很常见的(参见例如对于具有另一个库的类似示例的GSL矩阵访问;也参见该帖子以获得类似的问题)。
Storing a matrix as an array of arrays (i.e. using [][]
for access) is definitely manageable, and many people chose to use this representation, but there are reasons why one would prefer a flat layout in memory.
将矩阵存储为数组数组(即使用[] []进行访问)绝对是可管理的,并且许多人选择使用此表示,但有理由为什么人们更喜欢内存中的平面布局。