Masthan
Masthan

Reputation: 685

Opencv is not working in Qt5.13. App is always crashing in windows

I have installed Qt5.13 and linked opencv version 4.0 . But application is crashing when I am trying to use opencv library; otherwise it will work

.pro file

 INCLUDEPATH += C:\opencv\build\include
 LIBS += -L"C:\\opencv\\build\\x64\\vc15\\lib" \
         -lopencv_world410

Mainwindow.cpp

   #include "mainwindow.h"
   #include "ui_mainwindow.h"
   #include "opencv2/opencv.hpp"

   MainWindow::MainWindow(QWidget *parent)
              : QMainWindow(parent)
              , ui(new Ui::MainWindow)
   {
        ui->setupUi(this);

        cv::Mat img = cv::imread("qq.jpg");
        cv::imshow("ee",img);
        cv::waitKey(0);
   }

   MainWindow::~MainWindow()
   {
       delete ui;
   }

Every solution is appreciated.

Upvotes: 0

Views: 183

Answers (3)

Masthan
Masthan

Reputation: 685

opencv path was missing in "path" environment variable

Upvotes: 0

TerribleDog
TerribleDog

Reputation: 1247

This is how I included my OpenCV DLL in my .pro file. Yes, DLL, I prefer just using the functions I need instead of including the whole OpenCV Library in my project.

LIBS += -L$$PWD/Libs/OpenCV \
-lopencv_core320 \
-lopencv_imgproc320 \

Upvotes: 1

Bahramdun Adil
Bahramdun Adil

Reputation: 6079

The problem should be with the project configuration. You can try the following configuration and run again:

INCLUDEPATH += C:\opencv\build\include
LIBS += -LC:\opencv\build\x64\vc15\lib \
    lopencv_world410.lib

So what changed?

  • Original: "C:\\opencv\\build\\x64\\vc15\\lib"
  • Suggested: C:\opencv\build\x64\vc15\lib
  • Original: -lopencv_world410
  • Suggested: lopencv_world410.lib

Hope it works!

Edit: As Scheff mentioned, add the OpenCV DLL files path to the system path variable or add thoese to the application root folder.

Upvotes: 0

Related Questions