This has been covered numerous times in this forum
Thanks for reply. I already did and tried those solutions but still negative. Maybe I didn't correctly. Here is my environment:
openSUSE 12.3 64 bits with Gnome Desktop 3.6.2
I have installed openCV using install/remove software tool comes with gnome. I have installed qtcreator 2.8.0 manually. Qt 4.8.4 is already installed in openSUSE.
In usr/include/ there are two opencv folders
opencv
opencv2
all opencv libraries and links files are in usr/libs64
e.g. libopencv_core.so.2.4.6
libopencv_core.so.2.4
libopencv_core.so
Here is my .pro contents:
#-------------------------------------------------
#
# Project created by QtCreator 2013-09-05T12:37:35
#
#-------------------------------------------------
QT += core gui
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
TARGET = QTopenCV03
TEMPLATE = app
INCLUDEPATH += /usr/include/opencv2
LIBS += -L/usr/lib64
LIBS += -lopencv_core
LIBS += -lopencv_imgproc
LIBS += -lopencv_highgui
LIBS += -lopencv_features2d
LIBS += -lopencv_calib3d
SOURCES += main.cpp\
mainwindow.cpp
HEADERS += mainwindow.h
FORMS += mainwindow.ui
#-------------------------------------------------
#
# Project created by QtCreator 2013-09-05T12:37:35
#
#-------------------------------------------------
QT += core gui
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
TARGET = QTopenCV03
TEMPLATE = app
INCLUDEPATH += /usr/include/opencv2
LIBS += -L/usr/lib64
LIBS += -lopencv_core
LIBS += -lopencv_imgproc
LIBS += -lopencv_highgui
LIBS += -lopencv_features2d
LIBS += -lopencv_calib3d
SOURCES += main.cpp\
mainwindow.cpp
HEADERS += mainwindow.h
FORMS += mainwindow.ui
To copy to clipboard, switch view to plain text mode
The contents of main.cpp
#include "mainwindow.h"
#include <QApplication>
int main(int argc, char *argv[])
{
MainWindow w;
w.show();
return a.exec();
}
#include "mainwindow.h"
#include <QApplication>
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
MainWindow w;
w.show();
return a.exec();
}
To copy to clipboard, switch view to plain text mode
The contents of mainwindow.h
#ifndef MAINWINDOW_H
#define MAINWINDOW_H
#include <QMainWindow>
#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>
using namespace cv;
namespace Ui {
class MainWindow;
}
{
Q_OBJECT
public:
explicit MainWindow
(QWidget *parent
= 0);
~MainWindow();
private slots:
void on_pushButton_clicked( );
private:
Ui::MainWindow *ui;
};
#endif // MAINWINDOW_H
#ifndef MAINWINDOW_H
#define MAINWINDOW_H
#include <QMainWindow>
#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>
using namespace cv;
namespace Ui {
class MainWindow;
}
class MainWindow : public QMainWindow
{
Q_OBJECT
public:
explicit MainWindow(QWidget *parent = 0);
~MainWindow();
private slots:
void on_pushButton_clicked( );
private:
Ui::MainWindow *ui;
};
#endif // MAINWINDOW_H
To copy to clipboard, switch view to plain text mode
The contents of mainwindow.cpp
#include "mainwindow.h"
#include "ui_mainwindow.h"
#include "opencv2/highgui/highgui.hpp"
#include <iostream>
using namespace cv;
MainWindow
::MainWindow(QWidget *parent
) : ui(new Ui::MainWindow)
{
ui->setupUi(this);
}
MainWindow::~MainWindow()
{
delete ui;
}
void MainWindow::on_pushButton_clicked()
{
IplImage* pImg = cvLoadImage("./HappyFish.jpg");
if(pImg == NULL)
std::cout<< "Error loading image"<<std::endl;
cvShowImage("Image", pImg);
cvReleaseImage(&pImg);
std::cout<< "start **********"<<std::endl;
Mat image;
image = imread("./HappyFish.jpg"); // Read the file
if( !image.data ) { std::cout<< "Error loading src again"<<std::endl; }
namedWindow( "Display window", 1 );// Create a window for display.
imshow( "Display window", image ); // Show our image inside it.
waitKey(5000); // Wait for a keystroke in the window
}
#include "mainwindow.h"
#include "ui_mainwindow.h"
#include "opencv2/highgui/highgui.hpp"
#include <iostream>
using namespace cv;
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
}
MainWindow::~MainWindow()
{
delete ui;
}
void MainWindow::on_pushButton_clicked()
{
IplImage* pImg = cvLoadImage("./HappyFish.jpg");
if(pImg == NULL)
std::cout<< "Error loading image"<<std::endl;
cvShowImage("Image", pImg);
cvReleaseImage(&pImg);
std::cout<< "start **********"<<std::endl;
Mat image;
image = imread("./HappyFish.jpg"); // Read the file
if( !image.data ) { std::cout<< "Error loading src again"<<std::endl; }
namedWindow( "Display window", 1 );// Create a window for display.
imshow( "Display window", image ); // Show our image inside it.
waitKey(5000); // Wait for a keystroke in the window
}
To copy to clipboard, switch view to plain text mode
The compiler output:
Starting /home/ibr/projects/build-QTopenCV03-Desktop-Release/QTopenCV03...
Error loading image
start **********
Error loading src again
OpenCV Error: Assertion failed (size.width>0 && size.height>0) in imshow, file /home/abuild/rpmbuild/BUILD/opencv-2.4.6.1/modules/highgui/src/window.cpp, line 269
Qt has caught an exception thrown from an event handler. Throwing
exceptions from an event handler is not supported in Qt. You must
reimplement
QApplication::notify() and
catch all exceptions there.
terminate called after throwing an instance of 'cv::Exception'
what(): /home/abuild/rpmbuild/BUILD/opencv-2.4.6.1/modules/highgui/src/window.cpp:269: error: (-215) size.width>0 && size.height>0 in function imshow
The program has unexpectedly finished.
/home/ibr/projects/build-QTopenCV03-Desktop-Release/QTopenCV03 exited with code 0
Starting /home/ibr/projects/build-QTopenCV03-Desktop-Release/QTopenCV03...
Error loading image
start **********
Error loading src again
OpenCV Error: Assertion failed (size.width>0 && size.height>0) in imshow, file /home/abuild/rpmbuild/BUILD/opencv-2.4.6.1/modules/highgui/src/window.cpp, line 269
Qt has caught an exception thrown from an event handler. Throwing
exceptions from an event handler is not supported in Qt. You must
reimplement QApplication::notify() and catch all exceptions there.
terminate called after throwing an instance of 'cv::Exception'
what(): /home/abuild/rpmbuild/BUILD/opencv-2.4.6.1/modules/highgui/src/window.cpp:269: error: (-215) size.width>0 && size.height>0 in function imshow
The program has unexpectedly finished.
/home/ibr/projects/build-QTopenCV03-Desktop-Release/QTopenCV03 exited with code 0
To copy to clipboard, switch view to plain text mode
Is there something I did wrong? The same code works with out problem outside qtcreator.
any suggestions?
Bookmarks