0

Now I'm trying to use ImagemagicK and convert it to Intel IPL format. But I have exception error like this.

Unhandled exception at 0x59596706 in mfc_test5.exe: 0xC0000005: Access violation writing location 0x02c30000.

the used code like this .

m_image.read("abc.jpg");
IplImage* gray;

Magick2Ipl(m_image,gray);



void Cmfc_test5Dlg::Magick2Ipl(Image magicImage, IplImage* cvImage)
{
   int width= magicImage.size().width();
   int height = magicImage.size().height();

   byte* blob= new byte[cvImage->imageSize];
   magicImage.write(0,0, width, height, "BGRA", MagickCore::CharPixel, blob);
   memcpy(cvImage->imageData, blob, cvImage->imageSize);
   delete [] blob;
}

What am I do for solving this memory exception error?

Update 1

Hi. I use initialize it as following.

        m_image.read("abc.jpg");
    

   IplImage* IPL_image = iplCreateImageHeader( 
      3,                            // number of channels
      0,                            // alpha channel
      IPL_DEPTH_8U,                 // data of byte type 
      "RGB", "BGR",                 // color model and channel seq
      IPL_DATA_ORDER_PIXEL,         // channel arrangement
      IPL_ORIGIN_BL,                // bottom left orientation
      IPL_ALIGN_DWORD,              // 4 bytes align
      m_image.columns(),
      m_image.rows(),                   // image width and height
      NULL,                         // ROI
      NULL, NULL, NULL              // no mask ROI, image ID, not tiled
   );

   iplAllocateImage(IPL_image,0,0);

    
    Magick2Ipl(m_image,IPL_image);


void Cmfc_test5Dlg::Magick2Ipl(Image magicImage, IplImage* cvImage)
{
   int width= magicImage.size().width();
   int height = magicImage.size().height();

   byte* blob= new byte[cvImage->imageSize];
   magicImage.write(0,0, width, height, "BGRA", MagickCore::CharPixel, blob);
   memcpy(cvImage->imageData, blob, cvImage->imageSize);
   delete [] blob;
}

But it still makes an error like this.

Unhandled exception at 0x595a6706 in mfc_test5.exe: 0xC0000005: Access violation writing location 0x038c1000.

Does anyone know hot to solve this problem? What am I missing?

Community
  • 1
  • 1
cabot
  • 73
  • 1
  • 7
  • 2
    Where is the code that initializes `gray` (or `cvImage`)? – Sga Dec 01 '15 at 15:20
  • @Sga : Would you please let me how to initialize a gray ? In IPL2.5 source code, I can't find how to initialize the IplImage. Ipl2.5 reference example code use only 'iplCreateImageJaehne' for initialize. Did you mean this? – cabot Dec 02 '15 at 00:18
  • I don't know IPL. In your code it seems you are using `cvImage->imageSize` without properly initializing `cvImage` (just a guess). When you debug it, do `cvImage` members hold the expected values? – Sga Dec 02 '15 at 08:12

0 Answers0