简体   繁体   中英

OpenCV Unhandled exception when writing a file

After trying different things, my program always crashes while saving an image. It reads well the image and I'm able to visualize it but I can't save files (it occurs in all programs that I make with OpenCV while using imwrite). It occurs while debugging in Visual Studio 10.0 with OpenCV 2.1:

Unhandled exception at 0x67570fcd in SR.exe: 0xC0000005: Access violation reading location 0x00000000.

Here the code:

Mat imLow;

imLow=imread("Cameraman256.png",0);
if(!imLow.data)                             
{
    std::cout<<  "Could not open or find the image" << std::endl ;
    return -1;
}
imwrite( "image.png", imLow);

Can anyone tell me how can I fix this? Thank you

UPDATE : It seems to be a problem with PNG and JPEG format, because the line works while saving in BMP format.

BMP file saving is built-in, as is IIRC .PGM, the others are provided by 3rd party libs depending on your OS.

Did you build openCV yourself? What OS?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM