Ask Your Question
0

namedWindow() causes crashing

asked 2015-06-29 22:46:06 -0600

Barshan gravatar image

updated 2015-07-01 23:14:07 -0600

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

Error Screen

edit retag flag offensive close merge delete

Comments

1

Okay start by removing the namedWindow line, since it is not necessary to do this explicitly. Secondly, change the line image.data == NULL to image.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.

StevenPuttemans gravatar imageStevenPuttemans ( 2015-06-30 06:27:17 -0600 )edit

It is still crashing even after I remove namedWindow line and changing the image.data == NULL to image.empty() . No good so far.Please help if you can @StevenPuttemans

Barshan gravatar imageBarshan ( 2015-06-30 10:29:02 -0600 )edit

Hmm can you indicate where it crashes now? Because simply said, that runs on my machine ... just tested this code snippet

#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/spu/Pictures/spu.jpg");
    if(image.empty()){
        cout<< "Can not load image" << endl;
        return -1;
    }
    imshow("Image", image);
    waitKey(0);

    return 0;
}
StevenPuttemans gravatar imageStevenPuttemans ( 2015-07-01 06:49:31 -0600 )edit

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.

Barshan gravatar imageBarshan ( 2015-07-01 23:12:03 -0600 )edit

Did you built OpenCV with QT support? A version mismatch might cause this.

StevenPuttemans gravatar imageStevenPuttemans ( 2015-07-02 02:09:55 -0600 )edit

How should I do that? @StevenPuttemans

Barshan gravatar imageBarshan ( 2015-07-02 05:40:13 -0600 )edit

How did you install OpenCV? Build the source code yourself or not?

StevenPuttemans gravatar imageStevenPuttemans ( 2015-07-02 06:21:11 -0600 )edit

Built it from source @StevenPuttemans

Barshan gravatar imageBarshan ( 2015-07-02 06:48:24 -0600 )edit

Well then you have run CMAKE and there we want to know which options you selected.

StevenPuttemans gravatar imageStevenPuttemans ( 2015-07-02 07:35:00 -0600 )edit

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

Barshan gravatar imageBarshan ( 2015-07-02 07:48:05 -0600 )edit

1 answer

Sort by ยป oldest newest most voted
-2

answered 2016-01-25 05:43:54 -0600

When you have opencv3.0.0 don't use Waitkey. I have learned it causes your Qt Creator apps to crash with GTK errors. You can try I sleep (

edit flag offensive delete link more

Comments

This is seriously crap, I have collegues working on Qt creator for every single project and the imshow and waitKey work perfectly fine for them ...

StevenPuttemans gravatar imageStevenPuttemans ( 2016-01-25 06:25:23 -0600 )edit

Question Tools

1 follower

Stats

Asked: 2015-06-29 22:46:06 -0600

Seen: 2,375 times

Last updated: Jul 01 '15