-
-
Notifications
You must be signed in to change notification settings - Fork 56.5k
Strange side effect on imwrite/libpng #6070
Copy link
Copy link
Closed
Labels
category: imgcodecsquestion (invalid tracker)ask questions and other "no action" items here: https://forum.opencv.orgask questions and other "no action" items here: https://forum.opencv.org
Description
This has to be the strangest bug I've ever seen. When I run this code snippet:
#include <string>
#include <opencv2/opencv.hpp>
int main()
{
int i; std::cin >> i; // <---------------------
std::string s1 = ""; // <---------------------
std::string s2 = ""; // <---------------------
std::string s3 = ""; // <---------------------
cv::Mat img(100, 100, CV_8UC3);
for (size_t i = 0; i < 100; i++)
for (size_t j = 0; j < 100; j++)
img.at<cv::Vec3b>(i, j) = cv::Vec3b(100,10,40);
cv::imwrite("x.png", img, { CV_IMWRITE_PNG_COMPRESSION, 2 });
return EXIT_SUCCESS;
}
Type in any number for cin.
Then the 'x.png' file is created but stays empty and I get this error:
libpng warning: Invalid color type/bit depth combination in IHDR
libpng error: Invalid IHDR data
But if I remove any one of the four lines marked with an arrow, the error disappears and the 'x.png' is written properly.
I don't know how to begin to understand this bug. How can a variable declaration or use of cin here affect libpng?
My environment:
Windows 7 SP1
Visual Studio 2015, compiling for x64
OpenCV 3.1.0 pre-built binaries
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
category: imgcodecsquestion (invalid tracker)ask questions and other "no action" items here: https://forum.opencv.orgask questions and other "no action" items here: https://forum.opencv.org