OpenCV2.3 imwrite saves black image

杀马特。学长 韩版系。学妹 提交于 2019-12-01 23:44:17

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.

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!