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,通过手撕代码的方式详细讲解了如何实现实时人脸马赛克等功能,并提供了结果展示和基础知识回顾。
基于qt的opencv实时图像处理框架FastCvLearn实战
|
29天前
|
计算机视觉 Python
Opencv学习笔记(二):如何将整个文件下的彩色图片全部转换为灰度图
使用OpenCV库将一个文件夹内的所有彩色图片批量转换为灰度图,并提供了相应的Python代码示例。
31 0
Opencv学习笔记(二):如何将整个文件下的彩色图片全部转换为灰度图
|
2月前
|
文字识别 计算机视觉 开发者
基于QT的OCR和opencv融合框架FastOCRLearn实战
本文介绍了在Qt环境下结合OpenCV库构建OCR识别系统的实战方法,通过FastOCRLearn项目,读者可以学习Tesseract OCR的编译配置和在Windows平台下的实践步骤,文章提供了技术资源链接,帮助开发者理解并实现OCR技术。
116 9
基于QT的OCR和opencv融合框架FastOCRLearn实战
|
2月前
|
存储 UED Windows
Windows服务器上大量文件迁移方案
Windows服务器上大量文件迁移方案
113 1
|
2月前
|
iOS开发 MacOS Windows
Mac air使用Boot Camp安装win10 ,拷贝 Windows 文件时出错
Mac air使用Boot Camp安装win10 ,拷贝 Windows 文件时出错
|
3月前
|
计算机视觉 Windows Python
windows下使用python + opencv读取含有中文路径的图片 和 把图片数据保存到含有中文的路径下
在Windows系统中,直接使用`cv2.imread()`和`cv2.imwrite()`处理含中文路径的图像文件时会遇到问题。读取时会返回空数据,保存时则无法正确保存至目标目录。为解决这些问题,可以使用`cv2.imdecode()`结合`np.fromfile()`来读取图像,并使用`cv2.imencode()`结合`tofile()`方法来保存图像至含中文的路径。这种方法有效避免了路径编码问题,确保图像处理流程顺畅进行。
287 1
|
1月前
|
存储 开发框架 .NET
Windows IIS中asp的global.asa全局配置文件使用说明
Windows IIS中asp的global.asa全局配置文件使用说明
33 1
|
1月前
|
Java Windows
如何在windows上运行jar包/JAR文件 如何在cmd上运行 jar包 保姆级教程 超详细
本文提供了一个详细的教程,解释了如何在Windows操作系统的命令提示符(cmd)中运行JAR文件。
690 1
|
2月前
|
计算机视觉
基于QT的opencv插件框架qtCvFrameLearn实战
这篇文章详细介绍了如何基于Qt框架开发一个名为qtCvFrameLearn的OpenCV插件,包括项目配置、插件加载、Qt与OpenCV图像转换,以及通过各个插件学习OpenCV函数的使用,如仿射变换、卡通效果、腐蚀、旋转和锐化等。
41 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编译记录