【OpenCV学习】step的应用

时间:2022-06-11 16:34:58

作者:gnuhpc
出处:http://www.cnblogs.com/gnuhpc/

#pragma comment(lib,"cxcore.lib")#include"cv.h"
#include<stdio.h>
int main()
{
//矩阵元素为三通道8位浮点数
CvMat *mat=cvCreateMat(3,3,CV_32FC3 );
float *p;
int row,col;
for(row=0; row< mat->rows; row++)
{
p = mat->data.fl + row * (mat->step/4);
/* 除以4是因为一个float占4个字节,若为double则除以8,uchar不除*/
for(col = 0; col < mat->cols; col++)
{
*p = (float) row+col;
*(p+1) = (float) row+col+1;
*(p+2) =(float) row+col+2;
p+=3;
}
}

for(row = 0; row < mat->rows; row++)
{
p = mat->data.fl + row * (mat->step/4);
for(col = 0; col < mat->cols; col++)
{
printf("%f,%f,%f/t",*p,*(p+1),*(p+2));
p+=3;
}
printf("/n");
}

printf("rows=%d,cols=%d,height=%d,width=%d,step=%d/n",mat->rows,mat->cols,mat->height,mat->width,mat->step);

return 0;
}

 

作者:gnuhpc
出处:http://www.cnblogs.com/gnuhpc/