C++ CvGet2D的转换

C++ CvGet2D的转换,c++,visual-studio-2010,opencv,C++,Visual Studio 2010,Opencv,我有以下几点:img是一个高度x宽度的IplImage。有三个通道的 我想使用另一种解决方案(而不是我使用的以下解决方案)访问一幅图像中像素的三个值: IplImage* img=cvCreateImage(...); ... CvScalar scalar= cvGet2D(img, i, j); //where i and j are the coordinates of the considered pixel double v0=scalar.val[0]; double v1=sca

我有以下几点:img是一个高度x宽度的IplImage。有三个通道的 我想使用另一种解决方案(而不是我使用的以下解决方案)访问一幅图像中像素的三个值:

IplImage* img=cvCreateImage(...);
...
CvScalar scalar= cvGet2D(img, i, j); //where i and j are the coordinates of the considered pixel

double v0=scalar.val[0];
double v1=scalar.val[1];
double  v2=scalar.val[2];
我的想法是摆脱OpenCV依赖,并以另一种方式进行更改

有什么建议吗?

您可以使用x、y坐标访问像素,如

CV_IMAGE_ELEM( image_header, elementtype, y, x*N+C ) 
例如,如果您想使用i,j访问IplImage*img(3通道)的第二个通道,您可以

CV_IMAGE_ELEM(img, uchar, y, (x * 3) + 1))
或者使用下面的方法访问r、g、b像素值

int col, row, z;
     uchar b, g, r;
     for( y = 0; row < img->height; y++ )
     {
       for ( col = 0; col < img->width; col++ )
       {
         //for( z = 0; z < img->nChannels; z++ )
         //{
         //   c = img->imageData[img->widthStep * row + col * img->nChannels + z];
         //}
         b = img->imageData[img->widthStep * row + col * 3]
         g = img->imageData[img->widthStep * row + col * 3 + 1];
         r = img->imageData[img->widthStep * row + col * 3 + 2];
       }
     }
int列,行,z;
乌查尔b,g,r;
对于(y=0;行height;y++)
{
用于(col=0;col宽度;col++)
{
//对于(z=0;znChannels;z++)
//{
//c=img->imageData[img->widthStep*行+列*img->nChannels+z];
//}
b=img->imageData[img->widthStep*行+列*3]
g=img->imageData[img->widthStep*行+列*3+1];
r=img->imageData[img->widthStep*行+列*3+2];
}
}

有关更多详细信息,请参阅此堆栈溢出

,您的要求不太清楚。你到底想把它转换成什么?@Paddy我已经对我的问题进行了更多的编辑和解释。这与OpenCV有关,我不想介绍我的程序OpenCV。你能给我另一个想法吗?如果你不想包含OpenCV,你怎么能把图像加载到内存中呢?。你有没有其他方法,比如文件读取。