Cannot display image loaded from disk in release build
Hi everyone,
I have been unable to find a solution for my problem, where
cv::Mat image = cv::imread("path/to/file.jpg");
works in debug, but not in release build.
I am using Visual C++ on Windows and OpenCV 2.4.2.
My code just finds a file on disk and reads it using cv::imread
. When in Debug mode, I can use cv::imshow
to show the loaded image and it will. When in a release build, it won't. I have discovered that for some reason the loaded image in the release build has 1 channel, while the same image in a debug build has three.
The exception is:
OpenCV Error: Bad flag (parameter or structure field) (Unrecognized or unsupported array type) in unknown function, file ......\src\opencv\modules\core\src\array.cpp, line 2482
The include, and lib folders are the same for my release build as my debug build. I don't understand what's going wrong, but I would like to be able to create a release build of my program for the production environment.
Can you post some more code, and the exact line of code where it crashes? It does not seem to crash in
imread
No, imread works, but returns an invalid image. Like I said, it gives a 1 channel image. But when I call imshow with the loaded image, it gives this error. A part of my code:
int _tmain(int argc, _TCHAR *argv[])
{
// put the input_path parameter in a string variable.
string in_path = argv[1];
printf("Reading image from file: %s", in_path.c_str());
cv::Mat img = cv::imread(in_path);
printf("%i channels in image %s.", img.channels(), in_path.c_str()); // in debug, it has 3, in release it has 1 ???
cv::imshow("image", img); // this is where the exception is thrown!
}
argv[1] is a valid path to an image.
BTW: How do I get my code to show up right on this site?
How do I get my code to show up right on this site?
put < pre > tags around it
Indent with four spaces or use ` around it
Copy and paste text in the window. Then, highlight it and click on the code button (fifth button on top of input window).