1 | initial version |
If you are using IplImage * you need to use myIplImage->height, myIplImage->widht etc. You can use image data using below code
int width = img->width;
int height = img->height;
int nchannels = img->nChannels;
int step = img->widthStep;
uchar *data = ( uchar* )img->imageData;
for(int i = 0 ; i < height ; i++ ) {
for(int j = 0 ; j < width ; j++ ) {
int r = data[i*step + j*nchannels + 0];
int g = data[i*step + j*nchannels + 1];
int b = data[i*step + j*nchannels + 2];
}
}
Or using another method
for(int i=pix; i<img->height; i++)
{
for(int j=0; j<img->width; j++)
{
CvScalar ele;
ele=cvGet2D(img,i,j);
int B= ele.val[0]; //Blue channel
int G=ele.val[1]; //Green channel
int R=ele.val[2]; //Red channel
}
}
And if you are using Mat, See OpenCV documentation and this discussion for more details.