OpenCV 4.1.1 Imread() & Imwrite() Crashes Program Immediately [Qt] ?

asked 2019-08-19 04:33:21 -0600

RPH gravatar image

Hi,

I have built OPENCV v4.1.1 from source for Qt. I have linked the necessary libraries and added the include path in the .pro file as follows:

INCLUDEPATH += "C:\opencv4-build-x64\install\include"

LIBS += -L"C:\opencv4-build-x64\install\x64\mingw\bin" -lopencv_core411 \
-lopencv_highgui411 \
-lopencv_imgproc411 \
-lopencv_imgcodecs411

The libraries are .dll files. Now in my source code, I have something like this:

#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <opencv2/imgproc/imgproc.hpp>
#include <opencv2/imgcodecs/imgcodecs.hpp>

int main(){

Mat img = imread("SamplePath.tiff", IMREAD_GRAYSCALE);

}

The program builds fine but when I try to run it, it crashes immediately. If I comment out all the imread() and imwrite() functions, then it runs perfectly.

Any ideas ? Thanks.

edit retag flag offensive close merge delete

Comments

Do you have the same issues with a .jpg or a .png image? It could be due to a faulty QT support implementation for .tiff images.

StevenPuttemans gravatar imageStevenPuttemans ( 2019-08-19 08:39:57 -0600 )edit

@StevenPuttemans Yes, it doesn't even get that far. The program doesn't even start. Just having the imread function causes the program to not start, EVEN if I don't actually call the function.

RPH gravatar imageRPH ( 2019-08-19 09:18:28 -0600 )edit

Can you output the exact error message that pops up?

StevenPuttemans gravatar imageStevenPuttemans ( 2019-08-19 09:28:02 -0600 )edit

@StevenPuttemans What is very strange is that running the program from inside Qt I get the error: "The program has unexpectedly finished. The process was ended forcefully". But running the executable directly on my PC, it starts up fine. When running the program on another machine (with the required .DLLs copied into the release folder) I get this error: Error Screen

RPH gravatar imageRPH ( 2019-08-21 11:49:44 -0600 )edit

You cannot just transfer dlls from one machine to another without having an exact copy. It is very tricky. I would urge to built OpenCV on every single pc, unless you are using package managers that did it for you ...

StevenPuttemans gravatar imageStevenPuttemans ( 2019-08-22 09:25:56 -0600 )edit

@StevenPuttemans I managed to get it working on the other machine by copying the correct DLLs over. However, it is still crashing when I run it from inside Qt.

So now the .exe runs fine directly on my PC and the other machine, HOWEVER it is still instantly crashing when running it from Qt directly AS LONG AS THE IMREAD() AND IMWRITE() FUNCTIONS ARE THERE. If I comment them out it runs fine from inside Qt.

It really doesn't make sense to me that the executable runs fine yet from inside Qt it crashes ? I've never had that happen before.

RPH gravatar imageRPH ( 2019-08-23 04:14:54 -0600 )edit

Then my guess is this issue is due to your Qt environment are wrongly configured and the issue is not within OpenCV itself.

StevenPuttemans gravatar imageStevenPuttemans ( 2019-08-23 07:53:50 -0600 )edit

@StevenPuttemans I don't know, all my other Qt projects run fine through Qt when using older versions of OpenCV.

RPH gravatar imageRPH ( 2019-08-26 04:15:12 -0600 )edit