OpenCV2.3 imwrite saves a black image

I am trying to save a JPEG image to disk using imwrite, it seems that I am missing something. I always get a black image of about 4k. What am I doing wrong here? The image that I see seems beautiful, but once per disk, its completely black.

std::vector<int> qualityType(1);
qualityType.push_back(CV_IMWRITE_JPEG_QUALITY);
cv::imwrite("Final.jpg",image,qualityType);

enter image description here

+1
source share
3 answers

The following code works for me on 8-bit (1 and 3 channel) images:

std::vector<int> qualityType;
qualityType.push_back(CV_IMWRITE_JPEG_QUALITY);
qualityType.push_back(90);
cv::imwrite("Final.jpg",image,qualityType);

Your code qualityTypedoes not initialize properly. Your vector contains 2 values

{<some unknown number>, CV_IMWRITE_JPEG_QUALITY}

but should be

{CV_IMWRITE_JPEG_QUALITY, <desired quality value>}
+3
source

I needed to convert it to a 16 bit image

image.convertTo(image,CV_16UC3,255,255);

according to the document, you can save 8 or 16-bit images.

0
source

imwrite prints on a scale from 0 to 255, but your image is on a scale from 0 to 1. To zoom in, use this line:

image.convertTo (image, CV_8UC3, 255.0);

0
source

All Articles