qt5.14.2 MSVC opencv(不结合vs)路径添加问题 测试通过

 

不换行写法

1 win32:CONFIG(release, debug|release): LIBS += -LG:/opencv4.4.0/opencv4.4_vs_msvc19_qt6.5/x64/vc17/lib/ -lopencv_aruco440 -lopencv_bgsegm440 -lopencv_bioinspired440 -lopencv_calib3d440 -lopencv_ccalib440 -lopencv_core440 -lopencv_cvv440 -lopencv_datasets440 -lopencv_dnn440 -lopencv_dnn_objdetect440 -lopencv_dnn_superres440 -lopencv_dpm440 -lopencv_face440 -lopencv_features2d440 -lopencv_flann440 -lopencv_fuzzy440 -lopencv_gapi440 -lopencv_hfs440 -lopencv_highgui440 -lopencv_imgcodecs440 -lopencv_imgproc440 -lopencv_img_hash440 -lopencv_intensity_transform440 -lopencv_line_descriptor440 -lopencv_ml440 -lopencv_objdetect440 -lopencv_optflow440 -lopencv_phase_unwrapping440 -lopencv_photo440 -lopencv_plot440 -lopencv_quality440 -lopencv_rapid440 -lopencv_reg440 -lopencv_saliency440 -lopencv_shape440 -lopencv_stereo440 -lopencv_stitching440 -lopencv_structured_light440 -lopencv_superres440 -lopencv_surface_matching440 -lopencv_text440 -lopencv_tracking440 -lopencv_video440 -lopencv_videoio440 -lopencv_videostab440 -lopencv_xfeatures2d440 -lopencv_ximgproc440 -lopencv_xobjdetect440 -lopencv_xphoto440
2 else:win32:CONFIG(debug, debug|release): LIBS += -LG:/opencv4.4.0/opencv4.4_vs_msvc19_qt6.5/x64/vc17/lib/ -lopencv_aruco440d -lopencv_bgsegm440d -lopencv_bioinspired440d -lopencv_calib3d440d -lopencv_ccalib440d -lopencv_core440d -lopencv_cvv440d -lopencv_datasets440d -lopencv_dnn440d -lopencv_dnn_objdetect440d -lopencv_dnn_superres440d -lopencv_dpm440d -lopencv_face440d -lopencv_features2d440d -lopencv_flann440d -lopencv_fuzzy440d -lopencv_gapi440d -lopencv_hfs440d -lopencv_highgui440d -lopencv_imgcodecs440d -lopencv_imgproc440d -lopencv_img_hash440d -lopencv_intensity_transform440d -lopencv_line_descriptor440d -lopencv_ml440d -lopencv_objdetect440d -lopencv_optflow440d -lopencv_phase_unwrapping440d -lopencv_photo440d -lopencv_plot440d -lopencv_quality440d -lopencv_rapid440d -lopencv_reg440d -lopencv_saliency440d -lopencv_shape440d -lopencv_stereo440d -lopencv_stitching440d -lopencv_structured_light440d -lopencv_superres440d -lopencv_surface_matching440d -lopencv_text440d -lopencv_tracking440d -lopencv_video440d -lopencv_videoio440d -lopencv_videostab440d -lopencv_xfeatures2d440d -lopencv_ximgproc440d -lopencv_xobjdetect440d -lopencv_xphoto440d
3 
4 
5 INCLUDEPATH += G:/opencv4.4.0/opencv4.4_vs_msvc19_qt6.5/include
6 DEPENDPATH += G:/opencv4.4.0/opencv4.4_vs_msvc19_qt6.5/include

 

换行写法

  1 win32:CONFIG(release, debug|release): LIBS += -LG:/opencv4.4.0/opencv4.4_vs_msvc19_qt6.5/x64/vc17/lib/ \
  2     -lopencv_aruco440 \
  3     -lopencv_bgsegm440 \
  4     -lopencv_bioinspired440 \
  5     -lopencv_calib3d440 \
  6     -lopencv_ccalib440 \
  7     -lopencv_core440 \
  8     -lopencv_cvv440 \
  9     -lopencv_datasets440 \
 10     -lopencv_dnn440 \
 11     -lopencv_dnn_objdetect440 \
 12     -lopencv_dnn_superres440 \
 13     -lopencv_dpm440 \
 14     -lopencv_face440 \
 15     -lopencv_features2d440 \
 16     -lopencv_flann440 \
 17     -lopencv_fuzzy440 \
 18     -lopencv_gapi440 \
 19     -lopencv_hfs440 \
 20     -lopencv_highgui440 \
 21     -lopencv_imgcodecs440 \
 22     -lopencv_imgproc440 \
 23     -lopencv_img_hash440 \
 24     -lopencv_intensity_transform440 \
 25     -lopencv_line_descriptor440 \
 26     -lopencv_ml440 \
 27     -lopencv_objdetect440 \
 28     -lopencv_optflow440 \
 29     -lopencv_phase_unwrapping440 \
 30     -lopencv_photo440 \
 31     -lopencv_plot440 \
 32     -lopencv_quality440 \
 33     -lopencv_rapid440 \
 34     -lopencv_reg440 \
 35     -lopencv_saliency440 \
 36     -lopencv_shape440 \
 37     -lopencv_stereo440 \
 38     -lopencv_stitching440 \
 39     -lopencv_structured_light440 \
 40     -lopencv_superres440 \
 41     -lopencv_surface_matching440 \
 42     -lopencv_text440 \
 43     -lopencv_tracking440 \
 44     -lopencv_video440 \
 45     -lopencv_videoio440 \
 46     -lopencv_videostab440 \
 47     -lopencv_xfeatures2d440 \
 48     -lopencv_ximgproc440 \
 49     -lopencv_xobjdetect440 \
 50     -lopencv_xphoto440
 51 
 52 else:win32:CONFIG(debug, debug|release): LIBS += -LG:/opencv4.4.0/opencv4.4_vs_msvc19_qt6.5/x64/vc17/lib/ \
 53     -lopencv_aruco440d \
 54     -lopencv_bgsegm440d \
 55     -lopencv_bioinspired440d \
 56     -lopencv_calib3d440d \
 57     -lopencv_ccalib440d \
 58     -lopencv_core440d \
 59     -lopencv_cvv440d \
 60     -lopencv_datasets440d \
 61     -lopencv_dnn440d \
 62     -lopencv_dnn_objdetect440d \
 63     -lopencv_dnn_superres440d \
 64     -lopencv_dpm440d \
 65     -lopencv_face440d \
 66     -lopencv_features2d440d \
 67     -lopencv_flann440d \
 68     -lopencv_fuzzy440d \
 69     -lopencv_gapi440d \
 70     -lopencv_hfs440d \
 71     -lopencv_highgui440d \
 72     -lopencv_imgcodecs440d \
 73     -lopencv_imgproc440d \
 74     -lopencv_img_hash440d \
 75     -lopencv_intensity_transform440d \
 76     -lopencv_line_descriptor440d \
 77     -lopencv_ml440d \
 78     -lopencv_objdetect440d \
 79     -lopencv_optflow440d \
 80     -lopencv_phase_unwrapping440d \
 81     -lopencv_photo440d \
 82     -lopencv_plot440d \
 83     -lopencv_quality440d \
 84     -lopencv_rapid440d \
 85     -lopencv_reg440d \
 86     -lopencv_saliency440d \
 87     -lopencv_shape440d \
 88     -lopencv_stereo440d \
 89     -lopencv_stitching440d \
 90     -lopencv_structured_light440d \
 91     -lopencv_superres440d \
 92     -lopencv_surface_matching440d \
 93     -lopencv_text440d \
 94     -lopencv_tracking440d \
 95     -lopencv_video440d \
 96     -lopencv_videoio440d \
 97     -lopencv_videostab440d \
 98     -lopencv_xfeatures2d440d \
 99     -lopencv_ximgproc440d \
100     -lopencv_xobjdetect440d \
101     -lopencv_xphoto440d

 

最简单测试代码,不加按钮,启动后直接读取硬盘上一张图片

 1 #include "mainwindow.h"
 2 #include "ui_mainwindow.h"
 3 
 4 #include <opencv2/core/core.hpp>
 5 #include <opencv2/highgui/highgui.hpp>
 6 #include <opencv2/imgproc/imgproc.hpp>
 7 
 8 using namespace cv;
 9 
10 MainWindow::MainWindow(QWidget *parent)
11     : QMainWindow(parent)
12     , ui(new Ui::MainWindow)
13 {
14     ui->setupUi(this);
15 
16     cv::Mat image = imread("D:\\2.jpg");
17     namedWindow("Display window",WINDOW_AUTOSIZE);
18     imshow("Display window",image);
19     waitKey(0);
20 }
21 
22 MainWindow::~MainWindow()
23 {
24     delete ui;
25 }

 

添加按钮后代码,可点击按钮打开图片

 1 #include "mainwindow.h"
 2 #include "ui_mainwindow.h"
 3 
 4 #include <QFileDialog>
 5 #include <QMessageBox>
 6 #include <QPixmap>
 7 
 8 #include <opencv2/opencv.hpp>
 9 #include <opencv2/imgproc.hpp>
10 
11 using namespace cv;  // 引入opencv的命名空间
12 using namespace std;
13 
14 MainWindow::MainWindow(QWidget *parent)
15     : QMainWindow(parent)
16     , ui(new Ui::MainWindow)
17 {
18     ui->setupUi(this);
19 }
20 
21 MainWindow::~MainWindow()
22 {
23     delete ui;
24 }
25 
26 void MainWindow::on_pushButton_clicked()
27 {
28     QString filename = QFileDialog::getOpenFileName(this, "打开图像文件", "C:/Users", "Image Files (*.bmp;*.png;*.jpg)");
29 
30     if (filename.isEmpty()) {
31         QMessageBox::information(this, "提示", "文件打开失败1!");
32         return;
33     }
34     Mat img_input;
35     img_input = imread(filename.toLocal8Bit().toStdString());
36 
37     if (img_input.empty()) {
38 
39         QMessageBox::information(this, "提示", "文件打开失败2!");
40         return;
41     }
42     cv::Mat temp;
43     cv::cvtColor(img_input, temp, cv::COLOR_BGR2RGB);
44 
45     namedWindow("Display window",WINDOW_AUTOSIZE);
46     imshow("Display window",img_input);
47     waitKey(0);
48 
49     MainWindow w;
50     w.show();
51 }

 相对来说qt+mingw+opencv的路径就比较简单

1 #包含路径
2 INCLUDEPATH += E:\opencv\opencv4.5.4_mingw730_64_qt5.14.2\include
3 
4 #库文件
5 LIBS += E:\opencv\opencv4.5.4_mingw730_64_qt5.14.2\x64\mingw\lib\libopencv*.a

 

posted @ 2024-08-23 09:00  莫莫大人  阅读(7)  评论(0编辑  收藏  举报