First-chance exception at 0x013e1e61 in mith test.exe: 0xC0000005: Access violation reading location 0x00000028

-1

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;


    }
opencv
visual-c++
asked on Stack Overflow Dec 23, 2014 by user3327290 • edited Dec 23, 2014 by (unknown user)

1 Answer

0

"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));

enter image description here

enter image description here

answered on Stack Overflow Dec 23, 2014 by berak • edited Dec 23, 2014 by berak

User contributions licensed under CC BY-SA 3.0