繁体   English   中英

在Windows中的Qt中配置OpenCv

[英]Configuration OpenCv in Qt in windows

我在一个人工视觉项目中工作,该项目需要用于用户交互的GUI。

寻找一些可行的解决方案后,我决定使用Qt进行编程。

我遵循找到的一些教程,但是最后我总是遇到同样的问题:如果键入一些opencv代码,程序启动后会崩溃。

我正在使用带有Visual Studio编译器(适用于32位的MSCV 2010)的opencv 2.4.10和Qt 5.3.2。

出于学习目的,我正在尝试部署以下项目:

  • 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:

     #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:

     #include "mainwindow.h" #include <QApplication> int main(int argc, char *argv[]) { QApplication app(argc, argv); MainWindow mainWindow; mainWindow.showMaximized(); return app.exec(); } 
  • 最后,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(); } } 

该项目只有一个按钮,单击时,程序应在imaloc路径中显示图像。

我得到的应用程序输出是:

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

该程序意外完成。

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

而这甚至没有开始。

如果我在mainwindow.cpp中注释与opencv相关的代码,该程序将完美运行。

现在,如果我仅声明(未定义) Mat实例,则该应用程序退出运行,并再次显示相同的输出。

我认为这一定是配置问题,但找不到。

有人可以提供任何线索吗?

感谢您的帮助和时间。

我认为您忘记将必要的dll放在要尝试运行的可执行文件旁边,放在您的情况下的debug文件夹中。

要找出丢失的dll,请尝试直接运行该程序,而不要通过Qt Creator的界面进行操作。

暂无
暂无

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

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