简体   繁体   English

在Windows中的Qt中配置OpenCv

[英]Configuration OpenCv in Qt in windows

I'm working in a artificial vision project, that requires a GUI for user interaction. 我在一个人工视觉项目中工作,该项目需要用于用户交互的GUI。

After looking for some posibles solutions, I decided to program with Qt. 寻找一些可行的解决方案后,我决定使用Qt进行编程。

I follow some tutorials I found, but at the end I have always the same issue: if I type some opencv code, the program crashed after it starts. 我遵循找到的一些教程,但是最后我总是遇到同样的问题:如果键入一些opencv代码,程序启动后会崩溃。

I'm working with opencv 2.4.10 and Qt 5.3.2 with Visual Studio compiler (MSCV 2010 for 32bit). 我正在使用带有Visual Studio编译器(适用于32位的MSCV 2010)的opencv 2.4.10和Qt 5.3.2。

For learning purpose I'm trying to deploy the following project: 出于学习目的,我正在尝试部署以下项目:

  • opencvButton.pro: opencvButton.pro:

     QT += core gui greaterThan(QT_MAJOR_VERSION, 4): QT += widgets TARGET = opencvButton TEMPLATE = app INCLUDEPATH += C:\\\\opencv\\\\build\\\\include LIBS += -LC:\\\\opencv\\\\build\\\\x86\\\\vc10\\\\lib \\ -lopencv_calib3d2410d \\ -lopencv_contrib2410d \\ -lopencv_core2410d \\ -lopencv_features2d2410d \\ -lopencv_flann2410d \\ -lopencv_gpu2410d \\ -lopencv_highgui2410d \\ -lopencv_imgproc2410d \\ -lopencv_legacy2410d \\ -lopencv_ml2410d \\ -lopencv_nonfree2410d \\ -lopencv_objdetect2410d \\ -lopencv_ocl2410d \\ -lopencv_photo2410d \\ -lopencv_stitching2410d \\ -lopencv_superres2410d \\ -lopencv_ts2410d \\ -lopencv_video2410d \\ -lopencv_videostab2410d SOURCES += main.cpp\\ mainwindow.cpp HEADERS += mainwindow.h FORMS += mainwindow.ui 
  • mainwindow.h: mainwindow.h:

     #ifndef MAINWINDOW_H #define MAINWINDOW_H #include <QMainWindow> #include <QPushButton> #include <QMessageBox> #include <opencv2/opencv.hpp> #include <opencv2/core/core.hpp> #include <opencv2/highgui/highgui.hpp> #include <opencv2/imgproc/imgproc.hpp> namespace Ui { class MainWindow; } class MainWindow : public QMainWindow { Q_OBJECT public: explicit MainWindow(QWidget *parent = 0); private slots: void handleButton(); private: QPushButton *m_button; }; #endif // MAINWINDOW_H 
  • main.cpp: main.cpp:

     #include "mainwindow.h" #include <QApplication> int main(int argc, char *argv[]) { QApplication app(argc, argv); MainWindow mainWindow; mainWindow.showMaximized(); return app.exec(); } 
  • And finally, mainwindow.cpp: #include "mainwindow.h" 最后,mainwindow.cpp:#include“ mainwindow.h”

      #include <QCoreApplication> using namespace cv; MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent) { // Create the button, make "this" the parent m_button = new QPushButton("Display image", this); // set size and location of the button m_button->setGeometry(QRect(QPoint(100, 100), QSize(200, 50))); // Connect button signal to appropriate slot connect(m_button, SIGNAL (released()), this, SLOT (handleButton())); } void MainWindow::handleButton() { // Define image path String imaloc = "C:\\\\Users\\\\Virtualmech\\\\Desktop\\\\ipRedCable.png"; // Mat instance declaration image. Mat image; // Load imaloc image in Mat instance. image = imread(imaloc); if(image.empty()){ QMessageBox::about(this, "Error", "Cannot load image"); }else{ // Declare name of window namedWindow("Display image"); // Show image imshow("Display image", image); // Wait for user interaction waitKey(0); // Close and destroy window destroyAllWindows(); } } 

This project consists in a single button, and when you click it, the program should show an image in the path imaloc. 该项目只有一个按钮,单击时,程序应在imaloc路径中显示图像。

The application output I get is: 我得到的应用程序输出是:

Starting C:\\Users\\Virtualmech\\Documents\\opencvButton\\debug\\opencvButton.exe... 正在启动C:\\ Users \\ Virtualmech \\ Documents \\ opencvButton \\ debug \\ opencvButton.exe ...

The program has unexpectedly finished. 该程序意外完成。

C:\\Users\\Virtualmech\\Documents\\opencvButton\\debug\\opencvButton.exe crashed C:\\ Users \\ Virtualmech \\ Documents \\ opencvButton \\ debug \\ opencvButton.exe崩溃

And this without even starts. 而这甚至没有开始。

If I comment opencv related code in mainwindow.cpp, the program runs perfectly. 如果我在mainwindow.cpp中注释与opencv相关的代码,该程序将完美运行。

Now, if I just only declare (without defining) a Mat instance, the application quits off running, and shows again the same output. 现在,如果我仅声明(未定义) Mat实例,则该应用程序退出运行,并再次显示相同的输出。

I think it must be a configuration issue, but I can't find it. 我认为这一定是配置问题,但找不到。

Could anyone give any clue? 有人可以提供任何线索吗?

Thanks for your help and time. 感谢您的帮助和时间。

I think you forgot to put the necessary dlls next to the executable you are trying to run, in the debug folder in your case. 我认为您忘记将必要的dll放在要尝试运行的可执行文件旁边,放在您的情况下的debug文件夹中。

To find out which dlls you are missing, try to run the program directly instead of doing it through Qt Creator's interface. 要找出丢失的dll,请尝试直接运行该程序,而不要通过Qt Creator的界面进行操作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM