My goal is to run a simple OpenCV contribute (extra) module in Qt 5.5.1.
Steps:
1) created a Qt Application app;
2) changed the main.cpp file to :
#include <QApplication>
#include <opencv2/core/utility.hpp>
#include <opencv2/tracking.hpp>
#include <opencv2/videoio.hpp>
#include <opencv2/highgui.hpp>
#include <iostream>
#include <cstring>
#include <QDebug>
using namespace std;
using namespace cv;
int main(int argc, char*argv[])
{
qDebug() <<"start!" << endl;
QApplication a(argc, argv);
string trackingAlg = "KCF";
MultiTracker trackers(trackingAlg);
qDebug() <<"success!" << endl;
return a.exec();
}
and here is my .pro file:
QT += core gui
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
TARGET = tracker4
CONFIG += c++11
TEMPLATE = app
SOURCES += main.cpp
INCLUDEPATH += /usr/local/include/opencv
LIBS += `pkg-config opencv --libs`
LIBS += -L/usr/local/lib -lopencv_core -lopencv_imgcodecs -lopencv_highgui -lopencv_videoio -lopencv_tracking
The program compiles successfully, but in the runtime, it crashes without even running the main() function. I don't get such an error when I run this in Code::Blocks but in Qt I still have this issue.
I am using Qt 5.5.1 and Ubuntu 14.04.
Can anyone generate this "seg fault" error in his/her machine?
For QT 5, build the OpenCV with QT=OFF.
For QT 4, build the OpenCV with QT=ON.
Related
I have installed the last QT Creator, running a gived example code, but i get
error: 'QGLFormat' file not found and
error: 'QGLWidget' file not found
My pro file looks like
GLEW_PATH = ../ext/glew-1.9.0
GLM_PATH = ../ext/glm-0.9.4.1
TEMPLATE = app
TARGET = myfilename
LIBS += -Wl,-rpath $${GLEW_PATH}/lib -L$${GLEW_PATH}/lib
LIBS += -lGLEW -lGL -lGLU -lm
INCLUDEPATH += $${GLEW_PATH}/include $${GLM_PATH}
SOURCES = main.cpp viewer.cpp
HEADERS = viewer.h
CONFIG += qt opengl warn_on thread uic4 release
QT += core gui opengl xml widgets
The errors happen here in my only header viewer.h, but others includes look fine
// GLEW lib: needs to be included first!!
#include <GL/glew.h>
// OpenGL library
#include <GL/gl.h>
// OpenGL Utility library
#include <GL/glu.h>
// OpenGL Mathematics
#include <glm/glm.hpp>
#include <QGLFormat> //Error here
#include <QGLWidget> //and here
#include <QMouseEvent>
#include <QKeyEvent>
...
with a main quite simple
#include <qapplication.h>
#include <QString>
#include "viewer.h"
int main(int argc,char** argv) {
QApplication application(argc,argv);
Viewer viewer;
viewer.show();
return application.exec();
}
Recently build OPENCV 3.4.3 with CMAKE 3.12.4 and MINGW64(32bit) 8.1.0 in Windows 7. Have QT 5.6 and i trying to test this build as QT Console App, but when i compiling with QT only get the message "Press "RETURN" to close this window...".
.PRO file:
CONFIG += c++11
TARGET = test
CONFIG += console
CONFIG -= app_bundle
TEMPLATE = app
SOURCES += main.cpp
OTHER_FILES += test.png
INCLUDEPATH += C:\Users\Test\Desktop\opencv\build\include
LIBS += C:\Users\Test\Desktop\mingw\bin\libopencv_*.dll
main.cpp:
#include <QCoreApplication>
#include <iostream>
#include "opencv2/core/core.hpp"
#include "opencv2/highgui/highgui.hpp"
#include "opencv/cv.h"
using namespace std;
int main(int argc, char *argv[]) {
QCoreApplication a(argc, argv);
cout << "Hello World!" << endl;
cv::Mat mat;
mat = cv::imread("test.png");
cvNamedWindow("hello");
cv::imshow("hello",mat);
return a.exec();
}
What im doing wrong?
Imo the problem is not in your code, I just run it (using Qt5.5, Win10, openCV 4 and mingw64), even if I had to change cvNamedWindow to cv::namedWindow.
I have two hints:
did you build openCV with mingw64? If not, do so.
are the openCV dlls in the path when you run the application? You can also copy all opencv dlls in the program folder to check that quickly...
I'm trying to run (in Qt, C++) the following code that uses OpenCV:
.pro file:
QT += core
QT -= gui
TARGET = testOpenCV2
CONFIG += console
CONFIG -= app_bundle
TEMPLATE = app
SOURCES += main.cpp
INCLUDEPATH += C:\opencv\build\include
LIBS += C:\opencv\release\bin\libopencv_core300.dll
LIBS += C:\opencv\release\bin\libopencv_highgui300.dll
LIBS += C:\opencv\release\bin\libopencv_imgcodecs300.dll
LIBS += C:\opencv\release\bin\libopencv_imgproc300.dll
main.cpp file:
#include <opencv2/opencv.hpp>
#include <opencv2/highgui/highgui.hpp>
using namespace cv;
int main(int argc, char *argv[])
{
cv::Mat image = cv::imread("pic.jpg", CV_LOAD_IMAGE_COLOR);
cv::namedWindow("My Image", WINDOW_AUTOSIZE);
cv::imshow("My Image", image);
cv::waitKey(0);
return 0;
}
But I'm getting the following message:
exited with code -1073741515
And sometimes I get the following message:
Cannot obtain a handle to the inferior: The parameter is incorrect.
and nothing is happening.
Can anyone help me please?
I'm new in Qt and I don't know what's going on.
You are not using Qt at all (except you try link QtCore). For running a QtApplication you would at least need to call QCoreApplication.
#include <QCoreApplication>
int main(int argc, char *argv[])
{
QCoreApplication a(argc, argv);
// Some code here
// QMainWindow w;
// w.show();
return a.exec();
}
Creating a non Qt application you would change your pro-file to (omit the QT at all):
TEMPLATE = app
CONFIG += console c++11
CONFIG -= app_bundle
CONFIG -= qt
SOURCES += main.cpp
INCLUDEPATH += C:\opencv\build\include
LIBS += C:\opencv\release\bin\libopencv_core300.dll
LIBS += C:\opencv\release\bin\libopencv_highgui300.dll
LIBS += C:\opencv\release\bin\libopencv_imgcodecs300.dll
LIBS += C:\opencv\release\bin\libopencv_imgproc300.dll
This way you also won't need ''QCoreApplication''
I tried to use libjpeg-turbo with qt.
I downloaded libjpeg-turbo and installed. I wanted to use it within a project but I got the following fault:
C:\libjpeg-turbo-gcc64\bin\libjpeg-62.dll:-1: Error: file not
recognized: File format not recognized
As soon as I removed the libjpeg-62.dll I received the following fault:
C:\test\main.cpp:8: Error: undefined reference to
`tjInitCompress'
Why is the libjpeg-62 not recognizing the file format?
Thanks for help,
Willy
PS. Here is the code:
test.pro
QT += core
QT -= gui
TARGET = test
CONFIG += console
CONFIG -= app_bundle
TEMPLATE = app
SOURCES += main.cpp
INCLUDEPATH += C:\libjpeg-turbo-gcc64\include
LIBS += -LC:\libjpeg-turbo-gcc64\bin -llibjpeg-62
main.cpp
#include <QCoreApplication>
#include <turbojpeg.h>
int main(int argc, char *argv[])
{
QCoreApplication a(argc, argv);
tjhandle _jpegCompressor = tjInitCompress();
return a.exec();
}
Ok now it works,
it was the wrong version of libjpeg-turbo. Now I use the libjpeg-turbo-gcc and not the libjpeg-turbo-gcc64. Also i change the Libs-Path to
LIBS += "C://libjpeg-turbo-gcc64//bin//libjpeg-62.dll"
MfG Willy
I'm trying to get the following c++ program using Qwt v. 6.0.1 to work:
#include <cmath>
#include <QApplication>
#include <qwt_plot.h>
#include <qwt_plot_curve.h>
int main(int argc, char **argv)
{
QApplication a(argc, argv);
QwtPlot plot(QwtText("CppQwtExample1"));
plot.setGeometry(0,0,640,400);
plot.setAxisScale(QwtPlot::xBottom, 0.0, 2.0*M_PI);
plot.setAxisScale(QwtPlot::yLeft, -1.0, 1.0);
QwtPlotCurve sine("Sine");
std::vector<double> xs;
std::vector<double> ys;
for (double x=0; x<2.0*M_PI; x+=(M_PI/10.0)) {
xs.push_back(x);
ys.push_back(std::sin(x));
}
sine.setData(&xs[0], &ys[0], xs.size());
sine.attach(&plot);
plot.show();
return a.exec();
}
and the .pro file looks like:
TEMPLATE = app
TARGET = CppQwtExample1
QMAKEFEATURES += /usr/local/qwt-6.0.1/features
CONFIG += qwt
INCLUDEPATH += /usr/local/qwt-6.0.1/lib/qwt.framework/Headers
LIBS += -L/usr/local/qwt-6.0.1/lib/qwt.framework/Versions/6/ \
-lqwt
SOURCES += qwtTest.cpp
However, when I now try to do
qmake
make
I get the error:
ld: library not found for -lqwt
collect2: ld returned 1 exit status
make: * [qwtTest.app/Contents/MacOS/qwtTest] Error 1
I surely miss something here. Any help is greatly appreciated.
LIBS += -L/usr/local/qwt-6.0.1/lib/qwt.framework/Versions/6/ -lqwt
This is wrong. Due to the naming conventions of Mac OS X frameworks, the dynamic library inside qwt.framework isn't named "libqwt.dylib" (which the linker requires), but simply "qwt".
Use
LIBS += -F/usr/local/qwt-6.0.1/lib -framework qwt
instead.