OpenCV and Qt 5.3 weird message - c++

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''

Related

Trying to build a test with Opencv and QT

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...

OpenCV simple code compiles successfully but crashes on runtime

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.

libjpegTurbo: libjpeg-62 File not recognized

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

C++: Media Player using Qt

I want to develop a media player using Qt. On the basis of the documentation I have done the following things:
pro file
QT += core gui multimedia
QT += multimediawidgets
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
TARGET = Player
TEMPLATE = app
SOURCES += main.cpp\
mainwindow.cpp
HEADERS += mainwindow.h
FORMS += mainwindow.ui
main.cpp file
#include <QApplication>
#include <QtMultimediaWidgets/QVideoWidget>
#include <QtMultimedia/QMediaPlayer>
#include <QtMultimedia/QMediaPlaylist>
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
QMediaPlayer *player=new QMediaPlayer;
QVideoWidget *videowidget=new QVideoWidget;
QMediaPlaylist *playlist=new QMediaPlaylist;
playlist->addMedia(QUrl("C:/Users/Administrator/Desktop/VideoLAN/VLC/stram.mp4"));
player->setVideoOutput(videowidget);
playlist->setCurrentIndex(1);
player->setPlaylist(playlist);
player->play();
videowidget->show();
return a.exec();
}
As for the header file I have included mainwindow.h
EDIT
All the erorrs are gone but now the output which is coming is:
Where am I going wrong?
Try add this string to .pro file:
QT += multimediawidgets
for additional info: http://qt-project.org/doc/qt-5/qvideowidget.html

Error when compiling simple Qwt program on Mac OSX 10.7.4

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.