【opencv】获取图片某点像素值的两种方法

1. 通过指针访问像素值

		IplImage *Temp=*iterIplOri;

		uchar *dataaa=(uchar*)Temp->imageData;
		int step=Temp->widthStep/sizeof(uchar);
		int channals=Temp->nChannels;
		int r=0,g=0,b=0;


		for (int jj=Temp->height-1;jj>0;jj--)
		{
			for (int kk=0;kk<Temp->width;kk++)
			{
				r=dataaa[jj*step+kk*channals+0];
				// g and b are zeros for gray image 
				g=dataaa[jj*step+kk*channals+1]; 
				b=dataaa[jj*step+kk*channals+2];

				if (r>nTemp)
				{
					nTemp=r;
				}
			}
		}
	


2. 通过该像素的坐标获得像素值

		
		IplImage *Temp=*iterIplOri;		
		// nTesty is y cordinate,nTestx is x cordinate
		CvScalar pColor=cvGet2D(Temp,nTesty,nTestx);   
		int Pixl1=pColor.val[0];
		int Pixl2=pColor.val[1];
		int Pixl3=pColor.val[2];


你可能感兴趣的:(【opencv】获取图片某点像素值的两种方法)