OpenCV2.3 imwrite保存黑色图像
我正在尝试使用 imwrite 将 JPEG 图像保存到磁盘上,似乎我丢失了一些东西。我总是得到大约 4KB 的黑色图像。我在这里做错了什么? 我看到的图像看起来不错,但一旦进入磁盘,它就全黑了。
std::vector<int> qualityType(1);
qualityType.push_back(CV_IMWRITE_JPEG_QUALITY);
cv::imwrite("Final.jpg",image,qualityType);
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);
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
以下代码适用于 8 位(1 和 3 通道)图像:
在您的代码中,
qualityType
初始化不正确。你的向量包含 2 个值,但应该是
The following code works for me on 8bit (1 and 3 channel) images:
In your code
qualityType
is initialized incorrectly. Your vector contains 2 valuesbut should be
imwrite 按 0 到 255 的比例打印,但您的图像是 0 到 1 的比例。要放大,请使用以下行:
image.convertTo(image, CV_8UC3, 255.0);
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);
我只需
按照文档将其转换为 16 位图像,就可以保存 8 或 16 位图像。
I only had to convert it to 16bit image
as per document, 8 or 16 bit images can be saved.