I have a CV_32F
image that I want to save as file with different extensions. I use cv::imencode
With a tiff format, everything is fine. With some other formats (png, jpg, bmp), the output image is black.
I can solve the problem by manually converting the image to CV_8U
beforehand:
<code>m_mat.convertTo(matTmp, CV_8U, 255.0);
cv::imencode(sExt, matTmp, buffer);
</code>
<code>m_mat.convertTo(matTmp, CV_8U, 255.0);
cv::imencode(sExt, matTmp, buffer);
</code>
m_mat.convertTo(matTmp, CV_8U, 255.0);
cv::imencode(sExt, matTmp, buffer);
But the documentation of imencode
(which points to imwrite
) states that “If the image format is not supported, the image will be converted to 8-bit unsigned (CV_8U) and saved that way.” So It should not be required to manually do the conversion.
What am I missing?