[英]What does this code mean? OpenCV
May I know what does x represent? 我可以知道x代表什么吗? Does the content inside of () represent a pointer?
()内的内容是否表示一个指针? then the [] is the element of the array?
那么[]是数组的元素?
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];
}
}
Short answers: 简短的答案:
x
is the element on row j, column i of the matrix df_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 eg 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 (ie 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. 将矩阵存储为数组数组(即使用
[][]
进行访问)绝对是可以管理的,并且许多人选择使用此表示形式,但是出于某些原因 ,人们倾向于使用内存中的平面布局。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.