OpenCVTest
OpenCV测试示例以及库
OpenCVTest
OpenCV测试示例以及库
语言组成
- QMake
- 53.5%
- C++
- 46.5%
文件结构
查看完整文件清单(6 个文件)
OpenCVTest.pro README.md main.cpp widget.cpp widget.h widget.ui
关键源码
widget.h
#ifndef WIDGET_H#define WIDGET_H#include <QWidget>#include <QImage>#include <QLabel>QT_BEGIN_NAMESPACEnamespace Ui {class Widget;}QT_END_NAMESPACEclass Widget : public QWidget{ Q_OBJECTpublic: Widget(QWidget *parent = nullptr); ~Widget();private: Ui::Widget *ui; QLabel *imageLabel; QImage image;};#endif // WIDGET_Hwidget.cpp
#include "widget.h"#include "ui_widget.h"#include <opencv2/opencv.hpp>#include <QVBoxLayout>Widget::Widget(QWidget *parent) : QWidget(parent) , ui(new Ui::Widget){ ui->setupUi(this); imageLabel = new QLabel(this); imageLabel->setAlignment(Qt::AlignCenter); QVBoxLayout *layout = new QVBoxLayout(this); layout->addWidget(imageLabel); setLayout(layout); cv::Mat mat(300, 500, CV_8UC3, cv::Scalar(50, 100, 200)); cv::putText(mat, "WildPointer", cv::Point(20, 160), cv::FONT_HERSHEY_SIMPLEX, 1.2, cv::Scalar(255, 255, 255), 2); cv::Mat rgb; cv::cvtColor(mat, rgb, cv::COLOR_BGR2RGB); image = QImage(rgb.data, rgb.cols, rgb.rows, rgb.step, QImage::Format_RGB888).copy(); imageLabel->setPixmap(QPixmap::fromImage(image));}Widget::~Widget(){ delete ui;}main.cpp
#include "widget.h"#include <QApplication>int main(int argc, char *argv[]){ QApplication a(argc, argv); Widget w; w.show(); return a.exec();}OpenCVTest.pro
QT += core guigreaterThan(QT_MAJOR_VERSION, 4): QT += widgetsCONFIG += c++17# You can make your code fail to compile if it uses deprecated APIs.# In order to do so, uncomment the following line.#DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0SOURCES += \ main.cpp \ widget.cppHEADERS += \ widget.hFORMS += \ widget.ui# Default rules for deployment.qnx: target.path = /tmp/$${TARGET}/binelse: unix:!android: target.path = /opt/$${TARGET}/bin!isEmpty(target.path): INSTALLS += targetOPENCV_INC = E:/SummaryLib/OpenCVBuild/install/includeOPENCV_BIN = E:/SummaryLib/OpenCVBuild/install/x64/vc17/binOPENCV_LIBDIR = E:/SummaryLib/OpenCVBuild/install/x64/vc17/lib!exists($$OPENCV_INC) { OPENCV_INC = E:/SummaryLib/OpenCV4.12.0_MSVC_Win/opencv/build/include OPENCV_BIN = E:/SummaryLib/OpenCV4.12.0_MSVC_Win/opencv/build/x64/vc16/bin OPENCV_LIBDIR = E:/SummaryLib/OpenCV4.12.0_MSVC_Win/opencv/build/x64/vc16/lib}INCLUDEPATH += $$OPENCV_INCwin32-msvc:LIBS += -L$$OPENCV_LIBDIRwin32-msvc:CONFIG(release, debug|release): LIBS += -lopencv_world4120win32-msvc:CONFIG(debug, debug|release): LIBS += -lopencv_world4120dwin32-msvc:CONFIG(release, debug|release): QMAKE_POST_LINK += $$quote(cmd /c if exist "$$OPENCV_BIN\opencv_world4120.dll" copy /Y "$$OPENCV_BIN\opencv_world4120.dll" "$$OUT_PWD\\")win32-msvc:CONFIG(debug, debug|release): QMAKE_POST_LINK += $$quote(cmd /c if exist "$$OPENCV_BIN\opencv_world4120d.dll" copy /Y "$$OPENCV_BIN\opencv_world4120d.dll" "$$OUT_PWD\\")