开发者

OpenCV2.3 imwrite saves black image

开发者 https://www.devze.com 2023-04-05 12:45 出处:网络
I am trying to save a JPEG image onto the disk using imwrite, seems that I am missing something.开发者_开发技巧 I am always getting a black image of around 4KBs. What am I doing wrong here?

I am trying to save a JPEG image onto the disk using imwrite, seems that I am missing something.开发者_开发技巧 I am always getting a black image of around 4KBs. What am I doing wrong here? Image I see seems fine but once onto the disk, its completely black.

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

OpenCV2.3 imwrite saves black image


The following code works for me on 8bit (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);

In your code qualityType is initialized incorrectly. Your vector contains 2 values

{<some unknown number>, CV_IMWRITE_JPEG_QUALITY}

but should be

{CV_IMWRITE_JPEG_QUALITY, <desired quality value>}


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

image.convertTo(image, CV_8UC3, 255.0);


I only had to convert it to 16bit image

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

as per document, 8 or 16 bit images can be saved.

0

精彩评论

暂无评论...
验证码 换一张
取 消