sashoalm
sashoalm

Reputation: 79685

cv::imread() causes memory corruption

I've created an OpenCV project in Qt Creator. This very simple code was causing a memory corruption:

std::string fileName = "c:\\Workspace\\ImageProcessing\\Tutorials\\src\\images\\test.jpg";
cv::Mat mat = cv::imread(fileName.c_str());

After executing the code, the cv::Mat was empty, and also the contents of fileName were filled with garbage. I read imread not working in Opencv and OpenCV imread(filename) fails in debug mode when using release libraries.

I checked in my own project, but I am not mixing Debug and Release libraries. Also there's the memory corruption.

Upvotes: 1

Views: 341

Answers (1)

sashoalm
sashoalm

Reputation: 79685

It turned out that I was using MSVC9 (VS2008) compiler for my Qt Creator project, but using OpenCV that was compiled using MSVC10 (VS2010).

Since the C++ interface is not stable across compiler versions, it caused a memory corruption. The problem is that this fails completely silently, with no warnings whatsoever, and it blows up via memory corruptions.

After downloading a Qt version built with VS2010, it's working now.

Upvotes: 1

Related Questions