我试图在qt中设置opencv,并按照步骤从这里https://wiki.qt.io/How_to_setup_Qt_and_openCV_on_Windows,但得到链接错误,如
对
cv::imread(cv::String const&, int)' debug/mainwindow.o: In function
MainWindow::MainWindow(QWidget*)的未定义引用':c: users hans desktop QT_projectsbuild-TEST_OPENCV-Desktop_Qt_5_15_2_MinGW_64_bit->Debug/../TEST_OPENCV/mainwindow.cpp:17:未定义引用' cv::imread(cv::String const&,>int)'">
这是我的opencv的路径:C: opencv-build x86 mingw lib 安装
我尝试过的事情:使用"添加库">
我的代码:.pro file
#-------------------------------------------------
#
# Project created by QtCreator 2017-03-05T12:30:06
#
#-------------------------------------------------
QT += core gui
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
TARGET = opencvtest
TEMPLATE = app
# The following define makes your compiler emit warnings if you use
# any feature of Qt which as been marked as deprecated (the exact warnings
# depend on your compiler). Please consult the documentation of the
# deprecated API in order to know how to port your code away from it.
DEFINES += QT_DEPRECATED_WARNINGS
# You can also make your code fail to compile if you use deprecated APIs.
# In order to do so, uncomment the following line.
# You can also select to disable deprecated APIs only up to a certain version of Qt.
#DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0
SOURCES += main.cpp
mainwindow.cpp
HEADERS += mainwindow.h
FORMS += mainwindow.ui
INCLUDEPATH += C:opencvbuildinclude
LIBS += C:opencv-buildbinlibopencv_core343.dll
LIBS += C:opencv-buildbinlibopencv_highgui343.dll
LIBS += C:opencv-buildbinlibopencv_imgcodecs343.dll
LIBS += C:opencv-buildbinlibopencv_imgproc343.dll
LIBS += C:opencv-buildbinlibopencv_features2d343.dll
LIBS += C:opencv-buildbinlibopencv_calib3d343.dll
# more correct variant, how set includepath and libs for mingw
# add system variable: OPENCV_SDK_DIR=D:/opencv/opencv-build/install
# read http://doc.qt.io/qt-5/qmake-variable-reference.html#libs
#INCLUDEPATH += $$(OPENCV_SDK_DIR)/include
#LIBS += -L$$(OPENCV_SDK_DIR)/x86/mingw/lib
# -lopencv_core320
# -lopencv_highgui320
# -lopencv_imgcodecs320
# -lopencv_imgproc320
# -lopencv_features2d320
# -lopencv_calib3d320
主要
#include "mainwindow.h"
#include "ui_mainwindow.h"
#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
// read an image
cv::Mat image = cv::imread("f://1.jpg", 1);
// create image window named "My Image"
cv::namedWindow("My Image");
// show the image on window
cv::imshow("My Image", image);
}
MainWindow::~MainWindow()
{
delete ui;
}
我很感激任何帮助。谢谢!尝试指定LIBS为LIBS += -Lpath/to/lib -llibname
qmake reference
LIBS += -LC:opencv-buildbin -lopencv_core343 -lopencv_highgui343 -lopencv_imgcodecs343 -lopencv_imgproc343 -lopencv_features2d343 -lopencv_calib3d343