你是否正在寻找关于widthstep的内容?让我把最有价值的东西奉献给你:
怎么访问图像元素
(坐标起点相对于图像原点imageorigin从0开始,或者是左上角(img->origin=IPL_ORIGIN_TL)或者是左下角(img->origin=IPL_ORIGIN_BL)
假设有8-bit1-通道的图像I(IplImage*img):
I(x,y)~((uchar*)(img->imageDataimg->widthstep*y))[x]
假设有8-bit3-通道的图像I(IplImage*img):
I(x,y)blue~((uchar*)(img->imageDataimg->widthstep*y))[x*3]
I(x,y)green~((uchar*)(img->imageDataimg->widthstep*y))[x*31]
I(x,y)red~((uchar*)(img->imageDataimg->widthstep*y))[x*32]
如果增加点(100,100)的亮度30,那么可以:
CvPointpt={100,100};
((uchar*)(img->imageDataimg->widthstep*pt.y))[pt.x*3]=30;
((uchar*)(img->imageDataimg->widthstep*pt.y))[pt.x*31]=30;
((uchar*)(img->imageDataimg->widthstep*pt.y))[pt.x*32]=30;
或者更有效的
CvPointpt={100,100};
uchar*temp_ptr=&((uchar*)(img->imageDataimg->widthstep*pt.y))[x*3];
temp_ptr[0]=30;
temp_ptr[1]=30;
temp_ptr[2]=30;
假设有32-bit浮点数,1-通道图像I(IplImage*img):
I(x,y)~((float*)(img->imageDataimg->widthstep*y))[x]
现在,通用方法:假设有N-通道,类型为T的图像:
I(x,y)c~((T*)(img->imageDataimg->widthstep*y))[x*Nc]
或者你可使用宏CV_IMAGE_ELEM(image_header,elemtype,y,x_Nc)
I(x,y)c~CV_IMAGE_ELEM(img,T,y,x*Nc)
也有针对各种图像(包括4-通道)和矩阵的函数(cvGet2D,cvSet2D),但是它们都很慢.
--------------------------------------------------------------------------------
如何访问矩阵元素?
方法是类的(都是针对0起点的列和行)
设有32-bit浮点数的实数矩阵M(CvMat*mat):
M(i,j)~((float*)(mat->data.ptrmat->step*i))[j]
设有64-bit浮点数的复数矩阵M(CvMat*mat):
ReM(i,j)~((double*)(mat->data.ptrmat->step*i))[j*2]
ImM(i,j)~((double*)(mat->data.ptrmat->step*i))[j*21]
设有单通道矩阵,有宏CV_MAT_ELEM(matrix,elemtype,row,col),例如对32-bit浮点数的实数矩阵
M(i,j)~CV_MAT_ELEM(mat,float,i,j),
假如初始化3x3单位阵:
CV_MAT_ELEM(mat,float,0,0)=1.f;
CV_MAT_ELEM(mat,float,0,1)=0.f;
CV_MAT_ELEM(mat,float,0,2)=0.f;
CV_MAT_ELEM(mat,float,1,0)=0.f;
CV_MAT_ELEM(mat,float,1,1)=1.f;
CV_MAT_ELEM(mat,float,1,2)=0.f;
CV_MAT_ELEM(mat,float,2,0)=0.f;
CV_MAT_ELEM(mat,float,2,1)=0.f;
CV_MAT_ELEM(mat,float,2,2)=1.f;
--------------------------------------------------------------------------------
如何在OpenCV中处理我自己的数据
设你有300x20032-bit浮点数image/array,也就是对一个有60000个元素的数组.
intcols=300,rows=200;
float*myarr=newfloat[rows*cols];
//step1)initializingCvMatheader
CvMatmat=cvMat(rows,cols,
CV_32FC1,//32-bitfloating-point,singlechanneltype
myarr//userdatapointer(nodataiscopied)
);
//step2)usingcvfunctions,e.g.calculatingl2(Frobenius)norm
doublenorm=cvNorm(&mat,0,CV_L2);
...
deletemyarr;
其它情况在参考手册中有描述.见cvCreateMatHeader,cvInitMatHeader,cvCreateImageHeader,cvSetDataetc.
--------------------------------------------------------------------------------
如何加载和显示图像
/*usage:prog
以上就是关于widthstep的全部内容,相信你一定会非常满意,。
本文来自电脑杂谈,转载请注明本文网址:
http://www.pc-fly.com/a/shenmilingyu/article-11244-1.html
真爱国绝不是动不动就喊打喊杀
你看康师傅在天津和政府有多亲密