Qt + OpenCV 4.2.0 环境搭建

下载OpenCV安装包

在官网下载opencv-4.2.0-vc14_vc15.exe包安装

Qt用的是MSVC2015_64bit构建套件

安装包里已经有VS的编译好的bin,就省略编译。如果用的是MinGW,自己得用CMake编译下,剩余的问下度娘。

新建一个Qt Widgets Application

工程类型

修改pro文件配置

  • 包含OpenCV头文件目录
INCLUDEPATH += D:\XQ\opencv\build\include
  • 引入静态库
LIBS += D:\XQ\opencv\build\x64\vc15\lib\opencv_world420d.lib

完整pro文件如下:

#-------------------------------------------------
#
# Project created by QtCreator 2020-04-06T22:55:20
#
#-------------------------------------------------

QT       += core gui

greaterThan(QT_MAJOR_VERSION, 4): QT += widgets

TARGET = RecognitionID
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 += D:\XQ\opencv\build\include

LIBS += D:\XQ\opencv\build\x64\vc15\lib\opencv_world420d.lib

注意、注意、注意:
修改pro文件后,请记住qmake下,要不然你会哭!

main.cpp 中加入OpenCV 代码

代码如下:

#include "mainwindow.h"
#include <QApplication>

#include <opencv2/opencv.hpp>

using namespace cv;

int main(int argc, char *argv[])
{
//    QApplication a(argc, argv);
//    MainWindow w;
//    w.show();

//    return a.exec();

      VideoCapture capture(0);
      while(1)
      {
          Mat frame;
          capture>>frame;
          imshow("video",frame);
          waitKey(30);
      }

      return 0;
}

拷入opencv_world420d.dll到Debug目录

opencv_world420d.dll在安装目录的位置:opencv\build\x64\vc15\bin

编译后出效果

效果图

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值