PDA

View Full Version : Cannot call OpenCV 2.0 functions inside Qt slots



Asfer
19th February 2010, 09:18
Hi all,

I have a Qt (4.6 mingw) application that uses OpenCV (2.0) for image processing.

Everything was working fine with OpenCV 1.0 but when I upgraded to
OpenCV 2.0 it started crashing.
I noticed that it only crashes whenever OpenCV functions are called
inside Qt slots.

For instance, the following slot:



void TestClass::on_testButton_clicked() {
IplImage* src = cvLoadImage("test.jpg");
IplImage* dst = cvCreateImage(cvGetSize(src), src->depth, src->nChannels);
cvThreshold(src, dst, 100, 255, CV_THRESH_BINARY);
}


crashes when testButton is clicked.

However:
If I call the same cvThreshold function in any other place such as main or the Widget's constructor, it works.
If f I put the same code in a separate function and call that function with QtConcurrent::run() inside the same slot, it works.
If I use OpenCV 1.0, it works.

Why this behaviour? Are there any restrictions about the operations that can be done inside Qt slots?

Thanks in advance.

high_flyer
19th February 2010, 09:24
In such cases it is good to run this in a debugger, and step through until the crashing line.
Then you know exactly which line is crashing.
Next, you have to examine all the parameters in the call that is crashing.
If you have a debug build of your OpenCV you can drill with the debugger in to it, if the crash is in the lib, and not your code.
Knowing exactly which line crashed helps a lot to solve the problem.

Asfer
19th February 2010, 11:48
Hi, thanks for your reply.

Problem solved, I was using OpenCV's precompiled libraries, which were created with a different version of mingw.
I compiled the library with cmake+mingw and using the generated libraries solved the problem.