I know the problem is related to the pointer used. Please help me in locating the error.
IplImage* ExtractBlue(IplImage* in)
{
int width = in->width;
int height = in->height;
IplImage *out = cvCreateImage( cvSize( width, height ), IPL_DEPTH_8U, 3 );
uchar *datain;
datain = (uchar *)in->imageData;
uchar *dataout;
dataout = (uchar *)out->imageData;
int i,j,k;
for(i=0;i<out->height;i++)
for(j=0;j<out->width;j++)
for(k=0;k<1;k++)
{
dataout[i*out->widthStep+j*out->nChannels+k]=datain[i*in->widthStep+j*in->nChannels+k];
dataout[i*out->widthStep+j*out->nChannels+(k+1)]=0;
dataout[i*out->widthStep+j*out->nChannels+(k+2)]=0;
}
return out;
}
"I know the problem is related to the pointer used" - yes. that's why you should avoid those horrible operations you're doing.
please do away with all IplImages, and use the c++ api !
if you want to retain the blue channel of an image, and set anything else to 0, it's so easy:
Mat in = imread(...);
Mat out = in.mul(Scalar(1,0,0));
User contributions licensed under CC BY-SA 3.0