質問

At first, I'm using OpenCV 2.4.2 with Visual 2008 on WinXp. Here is the problem:

I'm using the imwrite function to write gray leveled image which has the following prototype:

bool imwrite( const string& filename, InputArray img, const vector<int>& params=vector<int>());

The image type is previously checked and set (8bits, 1channel). However, I've got an exception in the Release mode only (error -2, could not find a writer for the specified extension) to write a bmp image, in my case .\Images\Debug\calibration_ref.bmp. I didn't understand what were wrong with this file name.

Clue

After looking deep into dll source file (opencv_highgui242d.dll, loadsave.cpp, l.298), I realised that the parameter const std::string & filename (at least this one...) was corrupted (or freed?) due to the <Bad Ptr>. To get this result, I used the highgui debug version dll in the Release mode, else, with the highgui release version, I get trash string instead. I suspect all the arguments to be corrupted.

Clue2

I've absolutely no idea where this corruption come from! I searched here and there but all I could find is related to optimisation disabling in release mode then bug fixing and this article on string class about thread safe but i'm not sure that's the issue.

I'd add that the OpenCV version I use is not a package. I built it particularly with TBB (ver 4.0 6005). Feel free to ask more questions.

役に立ちましたか?

解決 2

The issue comes from the static initialization order.

Because the file name is declared as static which depends of other statics (I have a lot of static variable int this project), I have got uninitialized variable as parameter. This is the reason why it raised the exception with bad argument.

I could track this phenomenon thanks to breakpoints at the variable initialization and the execution of the function. The execution happened first... However, it could be a good idea to make a trace of the parameter (rather an OutputDebugString or something to force display since trace won't work in release mode) before entering in the function.

他のヒント

You are looking at a release build, so the debugger will not be able to display all values because the optimisations will remove some objects. I think you went down a rabbit hole with the "corruption".

You say the error is error -2, could not find a writer for the specified extension so have you looked to find out why this is? What writer is used in Debug mode, and why isn't is available in Release mode. It may just be a missing DLL in your working directory.

I recommend changing your output filename too, so you don't get confused with output from each build. .\Images\Debug\calibration_ref.bmp might be better as .\Images\Release\calibration_ref.bmp, for example.

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top