Qt+Halcon/Qt+OpenCV的pro工程文件和预编译头文件的书写(支持Windows和macOS)

简介: Qt+Halcon/Qt+OpenCV的pro工程文件和预编译头文件的书写(支持Windows和macOS)

Qt+Halcon

QT       += core gui
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
CONFIG += c++11
# The following define makes your compiler emit warnings if you use
# any Qt feature that has been marked 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 it uses 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 += \
    HalconImageWnd.cpp \
    ROI.cpp \
    ROIArc.cpp \
    ROICircle.cpp \
    ROIController.cpp \
    ROILine.cpp \
    ROIPolygon.cpp \
    ROIPolyline.cpp \
    ROIRectangle.cpp \
    ROIRectangle2.cpp \
    main.cpp \
    mainwindow.cpp
HEADERS += \
    HalconImageWnd.h \
    ROI.h \
    ROIArc.h \
    ROICircle.h \
    ROIController.h \
    ROILine.h \
    ROIPolygon.h \
    ROIPolyline.h \
    ROIRectangle.h \
    ROIRectangle2.h \
    mainwindow.h \
    stable.h
#调试输出
#DEFINES += QT_MESSAGELOGCONTEXT
DEFINES += QT_MESSAGELOGCONTEXT
CONFIG(release, debug|release){
DEFINES += QT_NO_WARNING_OUTPUT
DEFINES += QT_NO_DEBUG_OUTPUT
}
#指定生成的临时文件放置的目录
MOC_DIR = temp/moc
RCC_DIR = temp/rcc
UI_DIR = temp/ui
OBJECTS_DIR = temp/obj
#指定编译器选项和项目配置
CONFIG += c++11
CONFIG += warn_on           #告诉qmake要把编译器设置为输出警告信息的
#CONFIG += warn_off          #不要警告输出
CONFIG += precompile_header #可以在项目中使用预编译头文件的支持
#预编译头文件路径
PRECOMPILED_HEADER = $$PWD/stable.h
#disable C4819 warning
win32:QMAKE_CXXFLAGS_WARN_ON += -wd4819
win32:QMAKE_CXXFLAGS += /FS
#QMAKE_CXXFLAGS += /utf-8
#避免VC编译器关于fopen等应使用fopen_s的安全警告
win32:DEFINES += _CRT_SECURE_NO_WARNINGS
#指定生成的应用程序放置的目录
CONFIG(debug, debug|release){
    contains(DEFINES, WIN64) {
    DESTDIR = ../_debug64
    } else {
    DESTDIR = ../_debug32
    }
} else {
    contains(DEFINES, WIN64) {
    DESTDIR = ../_release64
    } else {
    DESTDIR = ../_release32
    }
}
macx:CONFIG(debug, debug|release){
    DESTDIR = ../bind
} else:macx:CONFIG(release, debug|release){
    DESTDIR = ../bin
}
message($$PWD)
message($$DESTDIR)
#Halcon Configuration
isEmpty(MY_HALCON_PATH) {
    win32:MY_HALCON_PATH = "D:/My Resources/ImageProcessingLibrary/halcon/" #注意斜杆的方向;引号;
    macx:MY_HALCON_PATH = none
    message($$MY_HALCON_PATH)
}
#头文件包含路径
win32 {
    INCLUDEPATH += $${MY_HALCON_PATH}/include/
    INCLUDEPATH += $${MY_HALCON_PATH}/include/halconcpp
    DEPENDPATH += $${MY_HALCON_PATH}/include/
}
#库文件包含路径
win32 {
contains(QT_ARCH, i386) {
        message("32-bit")
        #Windows x86 (32bit) specific build here
        MY_HALCON_LIBS_PATH = $${MY_HALCON_PATH}/lib/x86sse2-win32
    } else {
        message("64-bit")
        #Windows x64 (64bit) specific build here
        MY_HALCON_LIBS_PATH = $${MY_HALCON_PATH}/lib/x64-win64
    }
    message($$MY_HALCON_LIBS_PATH)
}
#依赖库的名称
win32:CONFIG(debug, debug|release): {
    LIBS += -L$${MY_HALCON_LIBS_PATH} -lhalcon
    LIBS += -L$${MY_HALCON_LIBS_PATH} -lhalconcpp
}
else:win32:CONFIG(release, debug|release):{
    LIBS += -L$${MY_HALCON_LIBS_PATH} -lhalcon
    LIBS += -L$${MY_HALCON_LIBS_PATH} -lhalconcpp
}
else:unix:{
}
# MacOS specific settings. Note that while dyld will search under
# /Library/Frameworks by default, the preprocessor/compiler/linker will not
# and need to be told explicitly.
macx {
  QMAKE_CXXFLAGS += -F/Library/Frameworks
  QMAKE_LFLAGS   += -F/Library/Frameworks
  LIBS           += -framework HALCONCpp
}
# Default rules for deployment.
qnx: target.path = /tmp/$${TARGET}/bin
else: unix:!android: target.path = /opt/$${TARGET}/bin
!isEmpty(target.path): INSTALLS += target
#pro文件的参考文档
#https://doc.qt.io/qt-5/qmake-variable-reference.html

Qt+OpenCV

#-------------------------------------------------
#
# Project created by QtCreator 2019-08-29T10:43:54
#
#-------------------------------------------------
QT       += core gui
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
TARGET = qt_opencv_demo
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\
    Widget_op.cpp \
    mylabel.cpp
HEADERS  += \
    mylabel.h \
    Widget_op.h \
    stable.h
FORMS += Widget_op.ui
#指定生成的临时文件放置的目录
MOC_DIR = temp/moc
RCC_DIR = temp/rcc
UI_DIR = temp/ui
OBJECTS_DIR = temp/obj
#指定编译器选项和项目配置
CONFIG += c++11
CONFIG += warn_on           #告诉qmake要把编译器设置为输出警告信息的
#CONFIG += warn_off          #不要警告输出
CONFIG += precompile_header #可以在项目中使用预编译头文件的支持
#预编译头文件路径
PRECOMPILED_HEADER = $$PWD/stable.h
#disable C4819 warning
win32:QMAKE_CXXFLAGS_WARN_ON += -wd4819
win32:QMAKE_CXXFLAGS += /FS
#避免VC编译器关于fopen等应使用fopen_s的安全警告
win32:DEFINES += _CRT_SECURE_NO_WARNINGS
#指定生成的应用程序放置的目录
win32:CONFIG(debug, debug|release){
    contains(DEFINES, WIN64) {
    DESTDIR = ../_debug64
    } else {
    DESTDIR = ../_debug32
    }
} else:win32:CONFIG(release, debug|release){
    contains(DEFINES, WIN64) {
    DESTDIR = ../_release64
    } else {
    DESTDIR = ../_release32
    }
}
macx:CONFIG(debug, debug|release){
    DESTDIR = ../bind
} else:macx:CONFIG(release, debug|release){
    DESTDIR = ../bin
}
message($$PWD)
message($$DESTDIR)
#Opencv Configuration
isEmpty(MY_OPENCV_PATH) {
    win32:MY_OPENCV_PATH = "D:/My Resources/ImageProcessingLibrary/opencv/" #注意斜杆的方向;引号;
    macx:MY_OPENCV_PATH = "/Users/firecat/opencv4.2.0"
    message($$MY_OPENCV_PATH)
}
#头文件包含路径
win32 {
    INCLUDEPATH += $${MY_OPENCV_PATH}/include/
    DEPENDPATH += $${MY_OPENCV_PATH}/include/
}
macx {
    INCLUDEPATH += $${MY_OPENCV_PATH}/include/opencv4
    DEPENDPATH += $${MY_OPENCV_PATH}/include/opencv4
}
#库文件包含路径
win32 {
contains(QT_ARCH, i386) {
        message("32-bit")
        #Windows x86 (32bit) specific build here
        MY_OPENCV_LIBS_PATH = $${MY_OPENCV_PATH}/Win32/vc15/lib
    } else {
        message("64-bit")
        #Windows x64 (64bit) specific build here
        MY_OPENCV_LIBS_PATH = $${MY_OPENCV_PATH}/x64/vc15/lib
    }
    message($$MY_OPENCV_LIBS_PATH)
}
macx {
    MY_OPENCV_LIBS_PATH = $${MY_OPENCV_PATH}/lib
    message($$MY_OPENCV_LIBS_PATH)
}
#依赖库的名称
win32:CONFIG(debug, debug|release): {#动态库
    LIBS += -L$${MY_OPENCV_LIBS_PATH} -lopencv_calib3d420d
    LIBS += -L$${MY_OPENCV_LIBS_PATH} -lopencv_core420d
    LIBS += -L$${MY_OPENCV_LIBS_PATH} -lopencv_features2d420d
    LIBS += -L$${MY_OPENCV_LIBS_PATH} -lopencv_flann420d
    LIBS += -L$${MY_OPENCV_LIBS_PATH} -lopencv_highgui420d
    LIBS += -L$${MY_OPENCV_LIBS_PATH} -lopencv_imgcodecs420d
    LIBS += -L$${MY_OPENCV_LIBS_PATH} -lopencv_imgproc420d
    LIBS += -L$${MY_OPENCV_LIBS_PATH} -lopencv_videoio420d
}
else:win32:CONFIG(release, debug|release):{
    LIBS += -L$${MY_OPENCV_LIBS_PATH} -lopencv_calib3d420
    LIBS += -L$${MY_OPENCV_LIBS_PATH} -lopencv_core420
    LIBS += -L$${MY_OPENCV_LIBS_PATH} -lopencv_features2d420
    LIBS += -L$${MY_OPENCV_LIBS_PATH} -lopencv_flann420
    LIBS += -L$${MY_OPENCV_LIBS_PATH} -lopencv_highgui420
    LIBS += -L$${MY_OPENCV_LIBS_PATH} -lopencv_imgcodecs420
    LIBS += -L$${MY_OPENCV_LIBS_PATH} -lopencv_imgproc420
    LIBS += -L$${MY_OPENCV_LIBS_PATH} -lopencv_videoio420
}
else:macx:{
    LIBS += -L$${MY_OPENCV_LIBS_PATH} -lopencv_calib3d.4.2.0
    LIBS += -L$${MY_OPENCV_LIBS_PATH} -lopencv_core.4.2.0
    LIBS += -L$${MY_OPENCV_LIBS_PATH} -lopencv_features2d.4.2.0
    LIBS += -L$${MY_OPENCV_LIBS_PATH} -lopencv_flann.4.2.0
    LIBS += -L$${MY_OPENCV_LIBS_PATH} -lopencv_highgui.4.2.0
    LIBS += -L$${MY_OPENCV_LIBS_PATH} -lopencv_imgcodecs.4.2.0
    LIBS += -L$${MY_OPENCV_LIBS_PATH} -lopencv_imgproc.4.2.0
    LIBS += -L$${MY_OPENCV_LIBS_PATH} -lopencv_videoio.4.2.0
}
#pro文件的参考文档
#https://doc.qt.io/qt-5/qmake-variable-reference.html

预编译头文件stable.h

//#ifndef STABLE_H
//#define STABLE_H
// Add C includes here
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <iomanip>
#include <iostream>
#include <math.h>
#if defined __cplusplus
// Add C++ includes here
#include <algorithm>
#include <string.h>
#include <vector>
using namespace std;
// Qt includes
#include <QApplication>
#include <QDateTime>
#include <QDebug>
#include <QFileDialog>
#include <QGraphicsEllipseItem>
#include <QGraphicsRectItem>
#include <QGraphicsScene>
#include <QGroupBox>
#include <QHBoxLayout>
#include <QImage>
#include <QLabel>
#include <QList>
#include <QMainWindow>
#include <QMenu>
#include <QMessageBox>
#include <QMouseEvent>
#include <QPainter>
#include <QPixmap>
#include <QPointF>
#include <QPushButton>
#include <QScopedPointer>
#include <QSettings>
#include <QSlider>
#include <QStandardItem>
#include <QStandardItemModel>
#include <QStyledItemDelegate>
#include <QTextCodec>
#include <QThread>
#include <QUndoGroup>
#include <QUndoStack>
#include <QVBoxLayout>
#include <QVector>
#include <QWheelEvent>
#include <QWidget>
#include <qdebug.h>
#include <qfiledialog.h>
#include <qmath.h>
//如果可以的话,请尽量不要#include <QtCore>和#include <QtGui>,因为这两个头文件涵盖了Qt所有的类,处理他们需要的时间相当长。
//#include <QtCore> //请谨慎包含
//#include <QtGui>  //请谨慎包含
#include <opencv2/opencv.hpp>
//using namespace cv;
#ifndef max
#define max(x, y) ((x) < (y) ? (y) : (x))
#define min(x, y) ((x) < (y) ? (x) : (y))
#endif
//解决UTF-8编码中文乱码的问题
#ifdef _MSC_VER
#if _MSC_VER >= 1600
#pragma execution_character_set("utf-8")
#pragma warning(disable : 4819)
#endif // _MSC_VER >= 1600
#endif // _MSC_VER
//扩展qDebug以文件行列记录信息
#define QLOG_DEBUG(msg) qDebug() << QString("[%1][%2][%3][%4]%5")                                               \
                                        .arg(QDateTime::currentDateTime().toString("yyyy-MM-dd hh:mm:ss:zzz"))  \
                                        .arg(QString("%1:%2:%3").arg(__FILE__).arg(__LINE__).arg(__FUNCTION__)) \
                                        .arg(QThread::currentThread()->objectName())                            \
                                        .arg("DEBUG")                                                           \
                                        .arg(msg);
#define LWLGD //LWLG::日志开关,注释关闭打印日志
#ifdef LWLGD
#define lwlgout qDebug() << "[lwlg]File" << __FILE__ << ",Line:" << __LINE__ << ">>"
#else
#define lwlgout
#endif
#endif //__cplusplus
//#endif // STABLE_H
建议不要在项目中使用using namespace cv;否则会报错:error C2872: “ACCESS_MASK”: 不明确的符号
因为winnt.h里边定义了cv,它的cv空间里有一个符号叫ACCESS_MASK;
opencv函数里边也定义了命名空间cv,它的cv空间里也有一个符号叫ACCESS_MASK。
那么我的项目如果同时包含这两个头文件,计算机是否知道我要调用哪个ACCESS_MASK吗?
main.cpp
————————————————
版权声明:本文为CSDN博主「libaineu2004」的原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接及本声明。
原文链接:https://blog.csdn.net/libaineu2004/article/details/105309196
相关文章
|
2月前
|
算法 计算机视觉
基于qt的opencv实时图像处理框架FastCvLearn实战
本文介绍了一个基于Qt的OpenCV实时图像处理框架FastCvLearn,通过手撕代码的方式详细讲解了如何实现实时人脸马赛克等功能,并提供了结果展示和基础知识回顾。
106 7
基于qt的opencv实时图像处理框架FastCvLearn实战
|
2月前
|
文字识别 计算机视觉 开发者
基于QT的OCR和opencv融合框架FastOCRLearn实战
本文介绍了在Qt环境下结合OpenCV库构建OCR识别系统的实战方法,通过FastOCRLearn项目,读者可以学习Tesseract OCR的编译配置和在Windows平台下的实践步骤,文章提供了技术资源链接,帮助开发者理解并实现OCR技术。
133 9
基于QT的OCR和opencv融合框架FastOCRLearn实战
|
2月前
|
计算机视觉
基于QT的opencv插件框架qtCvFrameLearn实战
这篇文章详细介绍了如何基于Qt框架开发一个名为qtCvFrameLearn的OpenCV插件,包括项目配置、插件加载、Qt与OpenCV图像转换,以及通过各个插件学习OpenCV函数的使用,如仿射变换、卡通效果、腐蚀、旋转和锐化等。
45 10
|
2月前
|
机器学习/深度学习 Java 计算机视觉
opencv4.5.5+qt5.15.2+vtk9.1+mingw81_64编译记录
本文记录了使用mingw81_64编译OpenCV 4.5.5、Qt 5.15.2、VTK 9.1的详细过程,包括编译结果截图、编译步骤、遇到的问题及其解决方案,以及相关参考链接。文中还提到了如何编译boost源码为静态库,并提供了测试代码示例。
opencv4.5.5+qt5.15.2+vtk9.1+mingw81_64编译记录
|
3月前
|
Linux iOS开发 开发者
跨平台开发不再难:.NET Core如何让你的应用在Windows、Linux、macOS上自如游走?
【8月更文挑战第28天】本文提供了一份详尽的.NET跨平台开发指南,涵盖.NET Core简介、环境配置、项目结构、代码编写、依赖管理、构建与测试、部署及容器化等多个方面,帮助开发者掌握关键技术与最佳实践,充分利用.NET Core实现高效、便捷的跨平台应用开发与部署。
193 3
|
3月前
|
计算机视觉
使用QT显示OpenCV读取的图片
使用QT显示OpenCV读取的图片
74 1
|
3月前
|
iOS开发 Android开发 MacOS
从零到全能开发者:解锁Uno Platform,一键跨越多平台应用开发的神奇之旅,让你的代码飞遍Windows、iOS、Android、macOS及Web,技术小白也能秒变跨平台大神!
【8月更文挑战第31天】从零开始,踏上使用Uno Platform开发跨平台应用的旅程。只需编写一次代码,即可轻松部署到Windows、iOS、macOS、Android及Web(通过WASM)等多个平台。Uno Platform为.NET生态带来前所未有的灵活性和效率,简化跨平台开发。首先确保安装了Visual Studio或VS Code及.NET SDK,然后选择合适的项目模板创建新项目。项目结构类似传统.NET MAUI或WPF项目,包含核心NuGet包。通过简单的按钮示例,你可以快速上手并构建应用。Uno Platform让你的技术探索之旅充满无限可能。
69 0
|
5月前
|
算法 计算机视觉
【Qt&OpenCV 图像的感兴趣区域ROI】
【Qt&OpenCV 图像的感兴趣区域ROI】
174 1
|
5月前
|
运维 算法 计算机视觉
【Qt&OpenCV 图像的模板匹配 matchTemplate/minMaxLoc】
【Qt&OpenCV 图像的模板匹配 matchTemplate/minMaxLoc】
81 1
|
5月前
|
存储 编解码 算法
【Qt&OpenCV 检测图像中的线/圆/轮廓 HoughLinesP/HoughCircles/findContours&drawContours】
【Qt&OpenCV 检测图像中的线/圆/轮廓 HoughLinesP/HoughCircles/findContours&drawContours】
91 0
下一篇
无影云桌面