namedWindow() causes crashing
I am trying to run this program to display a image in qtcreator with openCV2 but it is crashing with out any compile error. And when I see the debug output it says that it is a segmentation fault. I am new in openCV . Please any one help. Here is the program
> #include "opencv2/core/core.hpp" > #include "opencv2/highgui/highgui.hpp" > #include <iostream> > > using namespace std; using namespace > cv; > > int main() { > // read image > Mat image = imread("/home/avishek/Pictures/kcs_11903b52.png"); > if(image.data == NULL){ > cout<< "Can not load image" << endl; > return -1; > } > namedWindow("Image", CV_WINDOW_NORMAL); > imshow("Image", image); > waitKey(5000); > destroyAllWindows(); > return 0; }
my qtcreator version is 3.4.1 qt version is 5.4.2 and OpenCv is 3.0.0
EDIT : Here is the error screen
Okay start by removing the namedWindow line, since it is not necessary to do this explicitly. Secondly, change the line
image.data == NULL
toimage.empty()
which does exactly the same but I am not sure if the NULL comparing is working. In that case if your image is not loaded correctly, it will not work since the if loop is being ignored.It is still crashing even after I remove namedWindow line and changing the
image.data == NULL
toimage.empty()
. No good so far.Please help if you can @StevenPuttemansHmm can you indicate where it crashes now? Because simply said, that runs on my machine ... just tested this code snippet
I have edited the question with the error screen take a look @StevenPuttemans . And another thing, when I run the program with a a non qt c++ project with qt creator then it runs flawlessly . Have no idea what is happening.
Did you built OpenCV with QT support? A version mismatch might cause this.
How should I do that? @StevenPuttemans
How did you install OpenCV? Build the source code yourself or not?
Built it from source @StevenPuttemans
Well then you have run CMAKE and there we want to know which options you selected.
I have ran this command
cmake -D WITH_TBB=ON -D BUILD_NEW_PYTHON_SUPPORT=ON -D WITH_V4L=ON -D INSTALL_C_EXAMPLES=ON -D INSTALL_PYTHON_EXAMPLES=ON -D BUILD_EXAMPLES=ON -D WITH_QT=ON -D WITH_OPENGL=ON -D WITH_VTK=ON ..
can you point to any tutorial on installing opencv with qt support. @StevenPuttemans