Ask Your Question
0

opencv imwrite unable to save images >40MP [closed]

asked 2019-08-08 02:06:15 -0600

enxdtw gravatar image

Hi,

I have a camera capable of 41.5MP. When I try to save an image from the camera it gets created, only that the image is 0KB in size, there is no error caught. If I save a region from the image then the image is saved correctly (as in the code below). Is there some limit to image size above which the image cannot be saved? (I am using version 4.0.1 opencv on Windows 10 and VC++ 17)

cv::Mat im = grabCVImage();


int s = 1200;
roi.x = s;
roi.y = s;
roi.width = s;
roi.height = s;


try {
    imwrite("C:\\Users\\Watts\\Pictures\\alpha.png", im(roi));
}
catch (std::runtime_error& ex) {
    fprintf(stderr, "Exception converting image to PNG format: %s\n", ex.what());
    return 1;
}
edit retag flag offensive reopen merge delete

Closed for the following reason the question is answered, right answer was accepted by LBerger
close date 2019-08-08 12:40:14.300400

Comments

default size limit is 2^30 (CV_IO_MAX_IMAGE_PIXELS system variable)

LBerger gravatar imageLBerger ( 2019-08-08 03:02:24 -0600 )edit

But 2^30 or 1 Gigapixel is much larger than 41.5MP. It doesn't explain why the image does not save

enxdtw gravatar imageenxdtw ( 2019-08-08 04:21:17 -0600 )edit

Problem is not imwritte try :

Mat img=Mat::zeros(1400,1400,CV_8UC4);
imwrite("C:\\Users\\Watts\\Pictures\\alpha.png", img);

It will works.

Check im size, im depth, and im type. Change path, try im(oi).clone() ...

LBerger gravatar imageLBerger ( 2019-08-08 04:42:26 -0600 )edit

Yes, strange, I can save a newly created image of the same dimensions OK.

And when I call

imshow("im", im);

it shows the image perfectly. Then the imwrite() afterwards gives an image of 0KB. Also when an roi of the image was saved it worked ok.

enxdtw gravatar imageenxdtw ( 2019-08-08 06:14:21 -0600 )edit

1 answer

Sort by ยป oldest newest most voted
1

answered 2019-08-08 11:27:36 -0600

enxdtw gravatar image

The problem was windows MFC's parent document class overwriting the file!

edit flag offensive delete link more

Question Tools

1 follower

Stats

Asked: 2019-08-08 02:06:15 -0600

Seen: 857 times

Last updated: Aug 08 '19