添加项目文件。
This commit is contained in:
27
NodeEditorPro/examples/opcv/CvAlgorithmTools.cpp
Normal file
27
NodeEditorPro/examples/opcv/CvAlgorithmTools.cpp
Normal file
@ -0,0 +1,27 @@
|
||||
#include "opcv/CvAlgorithmTools.h"
|
||||
|
||||
CvAlgorithmTools::CvAlgorithmTools(QObject* parent)
|
||||
:QObject(parent)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
CvAlgorithmTools::~CvAlgorithmTools() {}
|
||||
|
||||
void CvAlgorithmTools::CvImageRgb2Gray(cv::Mat rgbImg)
|
||||
{
|
||||
if (rgbImg.empty())
|
||||
return;
|
||||
cv::Mat src, dst;
|
||||
rgbImg.copyTo(src);
|
||||
if (src.channels() == 3)
|
||||
cv::cvtColor(src, dst, CV_BGR2GRAY);
|
||||
else if (src.channels() == 1)
|
||||
dst = src;
|
||||
//qDebug() << "";
|
||||
QThread::sleep(2);
|
||||
qDebug() << "CvAlgorithmTools::CvImageRgb2Gray thread:" << QThread::currentThreadId();
|
||||
|
||||
emit sendCvImageRgb2GrayResult(dst);
|
||||
}
|
||||
|
28
NodeEditorPro/examples/opcv/CvAlgorithmTools.h
Normal file
28
NodeEditorPro/examples/opcv/CvAlgorithmTools.h
Normal file
@ -0,0 +1,28 @@
|
||||
#pragma once
|
||||
|
||||
#include <QObject>
|
||||
#include <QThread>
|
||||
#include <QDebug>
|
||||
|
||||
#include <opencv2/opencv.hpp>
|
||||
#include <opencv2/imgproc/types_c.h>
|
||||
|
||||
class CvAlgorithmTools : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
CvAlgorithmTools(QObject* parent = Q_NULLPTR);
|
||||
~CvAlgorithmTools();
|
||||
|
||||
public:
|
||||
void CvImageRgb2Gray(cv::Mat rgbImg);
|
||||
|
||||
|
||||
|
||||
signals:
|
||||
//CvImageRgb2Gray<61><79><EFBFBD>ؽ<EFBFBD><D8BD><EFBFBD>
|
||||
void sendCvImageRgb2GrayResult(cv::Mat grayImg);
|
||||
|
||||
|
||||
|
||||
};
|
222
NodeEditorPro/examples/opcv/CvGraphicsShowModel.cpp
Normal file
222
NodeEditorPro/examples/opcv/CvGraphicsShowModel.cpp
Normal file
@ -0,0 +1,222 @@
|
||||
#include "opcv/CvGraphicsShowModel.h"
|
||||
|
||||
|
||||
CvGraphicsShowModel::CvGraphicsShowModel()
|
||||
{
|
||||
//mCvImageView = new CvImageViewWidget();
|
||||
//mCvImageView->installEventFilter(this);
|
||||
//mCvImageView->resize(600, 450);
|
||||
//moveToThread(this);
|
||||
|
||||
mCvGraphicsView = new CvGraphicsViewWidget();
|
||||
mCvGraphicsView->setObjectName(QStringLiteral("graphicsView"));
|
||||
mCvGraphicsView->setStyleSheet(
|
||||
"QGraphicsView#graphicsView{ "
|
||||
"background-color:transparent; "
|
||||
"border: 1px solid #F0F2F4; "
|
||||
"border-radius: 4px; }");
|
||||
|
||||
widget = new QWidget();
|
||||
widget->resize(600, 450);
|
||||
widget->setObjectName(QStringLiteral("widget"));
|
||||
widget->setStyleSheet("QWidget#widget { background-color:transparent; }");
|
||||
|
||||
QGridLayout* gridLayout = new QGridLayout(widget);
|
||||
QVBoxLayout* verticalLayout = new QVBoxLayout();
|
||||
QHBoxLayout* horizontalLayout = new QHBoxLayout();
|
||||
horizontalLayout->setDirection(QHBoxLayout::LeftToRight);
|
||||
|
||||
QLabel* label = new QLabel();
|
||||
label->setObjectName(QStringLiteral("label"));
|
||||
label->setText(QStringLiteral("ͼƬ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>:"));
|
||||
label->setStyleSheet("QLabel#label { color:#FFFFFF; }");
|
||||
QSizePolicy sizePolicy(QSizePolicy::Preferred, QSizePolicy::Preferred);
|
||||
sizePolicy.setHorizontalStretch(0);
|
||||
sizePolicy.setVerticalStretch(0);
|
||||
sizePolicy.setHeightForWidth(label->sizePolicy().hasHeightForWidth());
|
||||
label->setSizePolicy(sizePolicy);
|
||||
label->setMaximumSize(QSize(60, 16777215));
|
||||
|
||||
horizontalSlider = new QSlider();
|
||||
horizontalSlider->setObjectName(QString::fromUtf8("horizontalSlider"));
|
||||
horizontalSlider->setMinimum(-14);
|
||||
horizontalSlider->setMaximum(14);
|
||||
horizontalSlider->setPageStep(2);
|
||||
horizontalSlider->setOrientation(Qt::Horizontal);
|
||||
horizontalSlider->setTickPosition(QSlider::TicksBelow);
|
||||
QObject::connect(horizontalSlider, &QSlider::valueChanged, this, &CvGraphicsShowModel::onQSliderValueChanged);
|
||||
|
||||
QSpacerItem* horizontalSpacer = new QSpacerItem(15, 20, QSizePolicy::Fixed, QSizePolicy::Minimum);
|
||||
horizontalLayout->addItem(horizontalSpacer);
|
||||
|
||||
horizontalLayout->addWidget(label);
|
||||
horizontalLayout->addWidget(horizontalSlider);
|
||||
|
||||
horizontalSpacer = new QSpacerItem(40, 20, QSizePolicy::Expanding, QSizePolicy::Minimum);
|
||||
horizontalLayout->addItem(horizontalSpacer);
|
||||
|
||||
verticalLayout->addLayout(horizontalLayout);
|
||||
verticalLayout->addWidget(mCvGraphicsView);
|
||||
|
||||
gridLayout->addLayout(verticalLayout, 0, 0, 1, 1);
|
||||
|
||||
mCvImageData = std::make_shared<CvImageData>();
|
||||
}
|
||||
|
||||
void CvGraphicsShowModel::onQSliderValueChanged(int val)
|
||||
{
|
||||
qDebug() << "onQSliderValueChanged:" << val;
|
||||
qreal scale = 1.0;
|
||||
if (val > 0)
|
||||
{
|
||||
scale = qPow(1.2, val);
|
||||
qreal temp = scale;
|
||||
scale = scale / mScaledNum;
|
||||
mScaledNum = temp;//<2F><><EFBFBD>±<EFBFBD><C2B1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ϵ<EFBFBD><CFB5>
|
||||
}
|
||||
else if (val < 0)
|
||||
{
|
||||
scale = qPow(1.2, val);
|
||||
qreal temp = scale;
|
||||
scale = scale / mScaledNum;
|
||||
mScaledNum = temp;//<2F><><EFBFBD>±<EFBFBD><C2B1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ϵ<EFBFBD><CFB5>
|
||||
}
|
||||
else if (val == 0)
|
||||
{
|
||||
qreal temp = scale;
|
||||
scale = scale / mScaledNum;
|
||||
mScaledNum = temp;//<2F><><EFBFBD>±<EFBFBD><C2B1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ϵ<EFBFBD><CFB5>
|
||||
}
|
||||
mCvGraphicsView->scale(scale, scale);
|
||||
}
|
||||
|
||||
void CvGraphicsShowModel::inputConnectionDeleted(QtNodes::Connection const&)
|
||||
{
|
||||
mCvGraphicsView->setScene(new QGraphicsScene());
|
||||
|
||||
mCvImageData = std::make_shared<CvImageData>();
|
||||
|
||||
PortIndex const outPortIndex = 0;
|
||||
modelValidationState = NodeValidationState::Warning;
|
||||
modelValidationError = QStringLiteral("ͼƬ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>δ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>!");
|
||||
Q_EMIT dataUpdated(outPortIndex);
|
||||
}
|
||||
|
||||
unsigned int CvGraphicsShowModel::nPorts(PortType portType) const
|
||||
{
|
||||
unsigned int result = 1;
|
||||
|
||||
switch (portType)
|
||||
{
|
||||
case PortType::In:
|
||||
result = 1;
|
||||
break;
|
||||
|
||||
case PortType::Out:
|
||||
result = 1;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
NodeDataType CvGraphicsShowModel::dataType(PortType portType, PortIndex portIndex) const
|
||||
{
|
||||
switch (portIndex)
|
||||
{
|
||||
case 0:
|
||||
return CvImageData().type();
|
||||
break;
|
||||
case 1:
|
||||
return CvImageData().type();
|
||||
break;
|
||||
}
|
||||
return CvImageData().type();
|
||||
}
|
||||
|
||||
bool CvGraphicsShowModel::RunTask()
|
||||
{
|
||||
PortIndex const outPortIndex = 0;
|
||||
try
|
||||
{
|
||||
//qDebug() << "11show";
|
||||
//QThread::sleep(3);
|
||||
//QThread* thread = new QThread();
|
||||
//qDebug() << "CvGraphicsShowModel::RunTask thread:" << thread->currentThreadId();
|
||||
|
||||
mCvGraphicsView->showImage(*mCvImageData->CvImage());
|
||||
mCvGraphicsView->scale(0.85, 0.85);
|
||||
modelValidationState = NodeValidationState::Valid;
|
||||
modelValidationError = QString();
|
||||
}
|
||||
catch (...)
|
||||
{
|
||||
modelValidationState = NodeValidationState::Warning;
|
||||
modelValidationError = QStringLiteral("ȱʧ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʧ<EFBFBD><EFBFBD>!");
|
||||
}
|
||||
|
||||
Q_EMIT dataUpdated(outPortIndex);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void CvGraphicsShowModel::setInData(std::shared_ptr<NodeData>data, int)
|
||||
{
|
||||
if (data == nullptr)
|
||||
return;
|
||||
if (data->type() == mCvImageData->type())
|
||||
{
|
||||
auto dataPtr = std::dynamic_pointer_cast<CvImageData>(data);
|
||||
if (dataPtr->CvImage()->empty())
|
||||
return;
|
||||
mCvImageData->setCvImage(*dataPtr->CvImage());
|
||||
}
|
||||
RunTask();
|
||||
}
|
||||
|
||||
bool CvGraphicsShowModel::eventFilter(QObject* object, QEvent* event)
|
||||
{
|
||||
if (event->type() == QEvent::Wheel)
|
||||
{
|
||||
|
||||
}
|
||||
//if (object == mCvGraphicsView->viewport())
|
||||
//{
|
||||
// qDebug() << event->type();
|
||||
// if (event->type() == QEvent::Wheel || event->type() == QEvent::GraphicsSceneWheel)
|
||||
// {
|
||||
// QWheelEvent* wheelEvent = static_cast<QWheelEvent*>(event);
|
||||
// qreal qrTmp = 1.0;
|
||||
// if (mScaledFactor < 0.01 || mScaledFactor > 2000)
|
||||
// return false;
|
||||
// if (wheelEvent->delta() > 0)
|
||||
// {
|
||||
// qrTmp = 1.2;
|
||||
// mCvGraphicsView->scale(qrTmp, qrTmp);
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// qrTmp = 1.0 / 1.2;
|
||||
// mCvGraphicsView->scale(qrTmp, qrTmp);
|
||||
// }
|
||||
// mScaledFactor = mScaledFactor * qrTmp; //<2F><><EFBFBD><EFBFBD><EFBFBD>Ŵ<EFBFBD><C5B4><EFBFBD><EFBFBD><EFBFBD>
|
||||
// qDebug() << "GraphicsSceneWheel";
|
||||
// return true;
|
||||
// }
|
||||
//}
|
||||
return false;
|
||||
}
|
||||
|
||||
std::shared_ptr<NodeData> CvGraphicsShowModel::outData(PortIndex index)
|
||||
{
|
||||
switch (index)
|
||||
{
|
||||
case 0:
|
||||
return std::dynamic_pointer_cast<CvImageData>(mCvImageData);
|
||||
break;
|
||||
}
|
||||
return std::dynamic_pointer_cast<CvImageData>(mCvImageData);
|
||||
}
|
||||
|
86
NodeEditorPro/examples/opcv/CvGraphicsShowModel.h
Normal file
86
NodeEditorPro/examples/opcv/CvGraphicsShowModel.h
Normal file
@ -0,0 +1,86 @@
|
||||
#pragma once
|
||||
|
||||
#include <QtCore>
|
||||
#include <QObject>
|
||||
#include <QWidget>
|
||||
#include <QEvent>
|
||||
#include <QMouseEvent>
|
||||
#include <QWheelEvent>
|
||||
#include <QHBoxLayout>
|
||||
#include <QVBoxLayout>
|
||||
#include <QGridLayout>
|
||||
|
||||
#include <QtWidgets/QGraphicsView>
|
||||
//#include <QtWidgets/QDoubleSpinBox>
|
||||
#include <QtWidgets/QLabel>
|
||||
#include <QtWidgets/QSlider>
|
||||
|
||||
#include "DataModelRegistry.hpp"
|
||||
#include "NodeDataModel.hpp"
|
||||
#include "Connection.hpp"
|
||||
|
||||
#include "opcv/CvImageData.h"
|
||||
#include "opcv/CvGraphicsViewWidget.h"
|
||||
|
||||
#include <opencv2/opencv.hpp>
|
||||
|
||||
using QtNodes::PortType;
|
||||
using QtNodes::PortIndex;
|
||||
using QtNodes::NodeData;
|
||||
using QtNodes::NodeDataType;
|
||||
using QtNodes::NodeDataModel;
|
||||
using QtNodes::NodeValidationState;
|
||||
using QtNodes::Connection;
|
||||
|
||||
class CvGraphicsShowModel :public NodeDataModel
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
CvGraphicsShowModel();
|
||||
virtual ~CvGraphicsShowModel() {}
|
||||
|
||||
public:
|
||||
QString caption() const override { return QStringLiteral("cvͼ<EFBFBD><EFBFBD>Graphics<EFBFBD><EFBFBD>ʾ"); }
|
||||
QString name() const override { return QStringLiteral("cvͼ<EFBFBD><EFBFBD>Graphics<EFBFBD><EFBFBD>ʾ"); }
|
||||
virtual QString modelName() const { return QStringLiteral("cvͼ<EFBFBD><EFBFBD>Graphics<EFBFBD><EFBFBD>ʾ"); }
|
||||
|
||||
QWidget* embeddedWidget() override { return widget; }
|
||||
//bool resizable() const override { return true; }
|
||||
bool resizable() const override { return false; }
|
||||
|
||||
NodeValidationState validationState() const override { return modelValidationState; }
|
||||
QString validationMessage() const override { return modelValidationError; }
|
||||
|
||||
unsigned int nPorts(PortType portType) const override;
|
||||
NodeDataType dataType(PortType portType, PortIndex portIndex) const override;
|
||||
|
||||
|
||||
public Q_SLOTS:
|
||||
void onQSliderValueChanged(int val);
|
||||
|
||||
//void onInputConnectionDeleted();
|
||||
|
||||
void inputConnectionDeleted(QtNodes::Connection const&) override;
|
||||
|
||||
protected:
|
||||
bool RunTask();
|
||||
bool eventFilter(QObject* watched, QEvent* event) override;
|
||||
|
||||
public:
|
||||
NodeValidationState modelValidationState = NodeValidationState::Warning;
|
||||
QString modelValidationError = QStringLiteral("ͼƬ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>δ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>!");
|
||||
|
||||
private:
|
||||
qreal mScaledNum = 1.0; //<2F>ӿ<EFBFBD><D3BF><EFBFBD><EFBFBD>ű<EFBFBD><C5B1><EFBFBD>
|
||||
|
||||
QSlider* horizontalSlider;
|
||||
QWidget* widget;
|
||||
CvGraphicsViewWidget* mCvGraphicsView;
|
||||
std::shared_ptr<CvImageData> mCvImageData;
|
||||
|
||||
public:
|
||||
void setInData(std::shared_ptr<NodeData>, int) override;
|
||||
std::shared_ptr<NodeData> outData(PortIndex port) override;
|
||||
|
||||
};
|
94
NodeEditorPro/examples/opcv/CvGraphicsViewWidget.cpp
Normal file
94
NodeEditorPro/examples/opcv/CvGraphicsViewWidget.cpp
Normal file
@ -0,0 +1,94 @@
|
||||
#include "opcv/CvGraphicsViewWidget.h"
|
||||
|
||||
#include <QThread>
|
||||
|
||||
CvGraphicsViewWidget::CvGraphicsViewWidget(QWidget* parent)
|
||||
:QGraphicsView(parent)
|
||||
{
|
||||
if (parent != Q_NULLPTR)
|
||||
this->setParent(parent);
|
||||
this->setStyleSheet("QGraphicsView{"
|
||||
"background-color:transparent;"
|
||||
"border:none;"
|
||||
"}");
|
||||
mGraphicsScene = new QGraphicsScene();
|
||||
|
||||
setMouseTracking(true);//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>λ<EFBFBD><CEBB>
|
||||
setDragMode(QGraphicsView::NoDrag);
|
||||
setTransformationAnchor(QGraphicsView::AnchorUnderMouse);
|
||||
setResizeAnchor(QGraphicsView::AnchorUnderMouse);
|
||||
|
||||
}
|
||||
|
||||
void CvGraphicsViewWidget::showImage(cv::Mat const& _cvimg)
|
||||
{
|
||||
QThread* thread =new QThread();
|
||||
qDebug() << "CvGraphicsViewWidget::showImage thread:"<<thread->currentThreadId();
|
||||
|
||||
if (_cvimg.empty())
|
||||
return;
|
||||
//QImage toShow;
|
||||
QPixmap pixmap;
|
||||
|
||||
CvImage2QPixmap(_cvimg, pixmap);
|
||||
|
||||
//QPixmap pixmap = QPixmap::fromImage(toShow);
|
||||
mGraphicsScene->clear();
|
||||
mGraphicsScene->addPixmap(pixmap);
|
||||
|
||||
setScene(mGraphicsScene);
|
||||
}
|
||||
|
||||
//void CvGraphicsViewWidget::paintEvent(QPaintEvent* event)
|
||||
//{
|
||||
// QGraphicsView::paintEvent(event);
|
||||
//}
|
||||
|
||||
void CvGraphicsViewWidget::CvImage2QPixmap(cv::Mat const& fromCv, QPixmap& toPix)
|
||||
{
|
||||
const uchar* pSrc = (const uchar*)fromCv.data;
|
||||
QImage image;
|
||||
if (fromCv.type() == CV_8UC1)
|
||||
{
|
||||
qDebug() << "CV_8UC1";
|
||||
image = QImage(pSrc, fromCv.cols, fromCv.rows, fromCv.step, QImage::Format_Grayscale8);
|
||||
}
|
||||
else if (fromCv.type() == CV_8UC3)
|
||||
{
|
||||
qDebug() << "CV_8UC3";
|
||||
image = QImage(pSrc, fromCv.cols, fromCv.rows, fromCv.step, QImage::Format_RGB888);
|
||||
}
|
||||
else if (fromCv.type() == CV_8UC4)
|
||||
{
|
||||
qDebug() << "CV_8UC4";
|
||||
image = QImage(pSrc, fromCv.cols, fromCv.rows, fromCv.step, QImage::Format_ARGB32);
|
||||
}
|
||||
else
|
||||
{
|
||||
qDebug() << "ERROR: Mat could not be converted to QImage.";
|
||||
return;
|
||||
}
|
||||
toPix = QPixmap::fromImage(image);
|
||||
}
|
||||
|
||||
bool CvGraphicsViewWidget::QImage2CvImage(QImage& fromQ, cv::Mat& toCv)
|
||||
{
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
//void CvGraphicsViewWidget::wheelEvent(QWheelEvent* ev)
|
||||
//{
|
||||
// qreal qrTmp = 1.0;
|
||||
// if (ev->delta() > 0)
|
||||
// {
|
||||
// qrTmp = 1.2;
|
||||
// this->scale(qrTmp, qrTmp);
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// qrTmp = 1.0 / 1.2;
|
||||
// this->scale(qrTmp, qrTmp);
|
||||
// }
|
||||
// mScaledFactor *= qrTmp; //<2F><><EFBFBD><EFBFBD><EFBFBD>Ŵ<EFBFBD><C5B4><EFBFBD><EFBFBD><EFBFBD>
|
||||
//}
|
43
NodeEditorPro/examples/opcv/CvGraphicsViewWidget.h
Normal file
43
NodeEditorPro/examples/opcv/CvGraphicsViewWidget.h
Normal file
@ -0,0 +1,43 @@
|
||||
#pragma once
|
||||
|
||||
#include <QWidget>
|
||||
#include <QObject>
|
||||
#include <QDebug>
|
||||
#include <QEvent>
|
||||
#include <QWheelEvent>
|
||||
|
||||
#include <QGraphicsView>
|
||||
#include <QGraphicsScene>
|
||||
//#include <QGraphicsItem>
|
||||
//#include <QPainter>
|
||||
|
||||
#include <opencv2/opencv.hpp>
|
||||
|
||||
class CvGraphicsViewWidget :public QGraphicsView
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
CvGraphicsViewWidget(QWidget* parent = Q_NULLPTR);
|
||||
virtual ~CvGraphicsViewWidget() {}
|
||||
|
||||
public:
|
||||
void showImage(cv::Mat const& _himg);
|
||||
|
||||
static void CvImage2QPixmap(cv::Mat const& fromCv, QPixmap& toPix);
|
||||
static bool QImage2CvImage(QImage& fromQ, cv::Mat& toCv);
|
||||
//static void QPixmapToCvRegion(QPixmap const& _pix, cv::Rect2d& tarImg);
|
||||
|
||||
protected:
|
||||
//void paintEvent(QPaintEvent* event) override;
|
||||
//void wheelEvent(QWheelEvent* ev);
|
||||
|
||||
private:
|
||||
QGraphicsScene* mGraphicsScene;
|
||||
//QGraphicsRectItem* item;
|
||||
|
||||
//QColor penColor = QColor(0, 180, 255);//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ɫ
|
||||
//int penWidth = 2;//<2F><><EFBFBD>ʿ<EFBFBD><CABF><EFBFBD>
|
||||
qreal mScaledFactor; //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ű<EFBFBD><C5B1><EFBFBD>
|
||||
|
||||
};
|
40
NodeEditorPro/examples/opcv/CvImageData.h
Normal file
40
NodeEditorPro/examples/opcv/CvImageData.h
Normal file
@ -0,0 +1,40 @@
|
||||
#pragma once
|
||||
|
||||
#include <QtGui/QPixmap>
|
||||
|
||||
#include "NodeDataModel.hpp"
|
||||
#include <opencv2/opencv.hpp>
|
||||
|
||||
using QtNodes::NodeData;
|
||||
using QtNodes::NodeDataType;
|
||||
|
||||
class CvImageData :public NodeData
|
||||
{
|
||||
public:
|
||||
CvImageData() { mCvImage = cv::Mat(); }
|
||||
CvImageData(cv::Mat inImg)
|
||||
{
|
||||
if (!inImg.empty())
|
||||
mCvImage = inImg;
|
||||
else
|
||||
mCvImage = cv::Mat();
|
||||
}
|
||||
virtual ~CvImageData() {}
|
||||
|
||||
NodeDataType type() const override { return { "CvImage","CvImg" }; }
|
||||
|
||||
bool empty() { return mCvImage.empty(); }
|
||||
|
||||
cv::Mat* CvImage() { return &mCvImage; }
|
||||
|
||||
void setCvImage(cv::Mat const& _img)
|
||||
{
|
||||
if (!_img.empty())
|
||||
mCvImage = _img;
|
||||
else
|
||||
return;
|
||||
}
|
||||
private:
|
||||
cv::Mat mCvImage;
|
||||
|
||||
};
|
94
NodeEditorPro/examples/opcv/CvImageLoaderModel.cpp
Normal file
94
NodeEditorPro/examples/opcv/CvImageLoaderModel.cpp
Normal file
@ -0,0 +1,94 @@
|
||||
#include "opcv/CvImageLoaderModel.h"
|
||||
|
||||
#include <QDir>
|
||||
#include <QEvent>
|
||||
#include <QFileDialog>
|
||||
|
||||
CvImageLoaderModel::CvImageLoaderModel()
|
||||
{
|
||||
mCvImageView = new CvImageViewWidget();
|
||||
mCvImageView->installEventFilter(this);
|
||||
mCvImageView->resize(200, 200);
|
||||
mCvImageData = std::make_shared<CvImageData>();
|
||||
}
|
||||
|
||||
unsigned int CvImageLoaderModel::nPorts(PortType portType) const
|
||||
{
|
||||
unsigned int result = 1;
|
||||
|
||||
switch (portType)
|
||||
{
|
||||
case PortType::In:
|
||||
result = 0;
|
||||
break;
|
||||
|
||||
case PortType::Out:
|
||||
result = 1;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
NodeDataType CvImageLoaderModel::dataType(PortType portType, PortIndex portIndex) const
|
||||
{
|
||||
return CvImageData().type();
|
||||
}
|
||||
|
||||
QJsonObject CvImageLoaderModel::save() const
|
||||
{
|
||||
|
||||
return QJsonObject();
|
||||
}
|
||||
|
||||
void CvImageLoaderModel::restore(QJsonObject const&)
|
||||
{
|
||||
QJsonObject modelJson = NodeDataModel::save();
|
||||
|
||||
}
|
||||
|
||||
void CvImageLoaderModel::loadImage(QString fileName)
|
||||
{
|
||||
if (fileName == "")
|
||||
return;
|
||||
|
||||
cv::Mat tempImg = cv::imread(fileName.toStdString().c_str());
|
||||
mCvImageData->setCvImage(tempImg);
|
||||
mCvImageView->showImage(*mCvImageData->CvImage());
|
||||
}
|
||||
|
||||
bool CvImageLoaderModel::eventFilter(QObject* object, QEvent* event)
|
||||
{
|
||||
if (object == mCvImageView)
|
||||
{
|
||||
if (event->type() == QEvent::MouseButtonPress)
|
||||
{
|
||||
imageName = QFileDialog::getOpenFileName(nullptr,
|
||||
tr("Open Image"),
|
||||
QDir::homePath(),
|
||||
tr("Image Files(*.png *.jpg *.jpeg *.bmp)"));
|
||||
if (imageName == "")
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
loadImage(imageName);
|
||||
|
||||
Q_EMIT dataUpdated(0);
|
||||
|
||||
return true;
|
||||
}
|
||||
else if (event->type() == QEvent::Resize)
|
||||
{
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
std::shared_ptr<NodeData> CvImageLoaderModel::outData(PortIndex port)
|
||||
{
|
||||
return std::dynamic_pointer_cast<CvImageData>(mCvImageData);
|
||||
}
|
||||
|
59
NodeEditorPro/examples/opcv/CvImageLoaderModel.h
Normal file
59
NodeEditorPro/examples/opcv/CvImageLoaderModel.h
Normal file
@ -0,0 +1,59 @@
|
||||
#pragma once
|
||||
|
||||
#include <iostream>
|
||||
|
||||
#include <QObject>
|
||||
#include <QWidget>
|
||||
#include <QLabel>
|
||||
|
||||
#include "DataModelRegistry.hpp"
|
||||
#include "NodeDataModel.hpp"
|
||||
|
||||
#include "opcv/CvImageViewWidget.h"
|
||||
#include "opcv/CvImageData.h"
|
||||
|
||||
using QtNodes::PortType;
|
||||
using QtNodes::PortIndex;
|
||||
using QtNodes::NodeData;
|
||||
using QtNodes::NodeDataType;
|
||||
using QtNodes::NodeDataModel;
|
||||
using QtNodes::NodeValidationState;
|
||||
|
||||
//class CvImageData;
|
||||
//class CvImageViewWidget;
|
||||
|
||||
class CvImageLoaderModel :public NodeDataModel
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
CvImageLoaderModel();
|
||||
virtual ~CvImageLoaderModel() {}
|
||||
|
||||
public:
|
||||
QString caption() const override { return QStringLiteral("cv图像输入"); }
|
||||
QString name() const override { return QStringLiteral("cv图像输入"); }
|
||||
virtual QString modelName() const { return QStringLiteral("cv图像输入"); }
|
||||
|
||||
void setInData(std::shared_ptr<NodeData>, int) override { }
|
||||
QWidget* embeddedWidget() override { return mCvImageView; }
|
||||
bool resizable() const override { return false; }
|
||||
|
||||
unsigned int nPorts(PortType portType) const override;
|
||||
NodeDataType dataType(PortType portType, PortIndex portIndex) const override;
|
||||
std::shared_ptr<NodeData> outData(PortIndex port) override;
|
||||
|
||||
QJsonObject save() const override;
|
||||
void restore(QJsonObject const&) override;
|
||||
void loadImage(QString fileName);
|
||||
|
||||
protected:
|
||||
bool eventFilter(QObject* object, QEvent* event) override;
|
||||
|
||||
private:
|
||||
QString imageName;
|
||||
CvImageViewWidget* mCvImageView;
|
||||
|
||||
std::shared_ptr<CvImageData> mCvImageData;
|
||||
|
||||
};
|
104
NodeEditorPro/examples/opcv/CvImageRGB2GrayModel.cpp
Normal file
104
NodeEditorPro/examples/opcv/CvImageRGB2GrayModel.cpp
Normal file
@ -0,0 +1,104 @@
|
||||
#include "opcv/CvImageRGB2GrayModel.h"
|
||||
|
||||
#include <QDebug>
|
||||
#include <QTime>
|
||||
|
||||
CvImageRGB2GrayModel::CvImageRGB2GrayModel()
|
||||
{
|
||||
qRegisterMetaType<cv::Mat>("cv::Mat");
|
||||
mCvImage = std::make_shared<CvImageData>();
|
||||
}
|
||||
|
||||
unsigned int CvImageRGB2GrayModel::nPorts(PortType portType) const
|
||||
{
|
||||
unsigned int result = 1;
|
||||
|
||||
switch (portType)
|
||||
{
|
||||
case PortType::In:
|
||||
result = 1;
|
||||
break;
|
||||
case PortType::Out:
|
||||
result = 1;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
bool CvImageRGB2GrayModel::RunTask()
|
||||
{
|
||||
Q_EMIT computingStarted();
|
||||
PortIndex const outPortIndex = 0;
|
||||
|
||||
try
|
||||
{
|
||||
qDebug() << "CvImageRGB2GrayModel::RunTask thread:" << QThread::currentThreadId();
|
||||
|
||||
mAlgoTool = new CvAlgorithmTools();
|
||||
mChildThread = new QThread();
|
||||
mAlgoTool->moveToThread(mChildThread);
|
||||
|
||||
QObject::connect(mChildThread, &QThread::finished, mChildThread, &QObject::deleteLater);
|
||||
QObject::connect(mChildThread, &QThread::finished, mAlgoTool, &QObject::deleteLater);
|
||||
|
||||
QObject::connect(this, &CvImageRGB2GrayModel::SignalCvImageRgb2Gray, mAlgoTool, &CvAlgorithmTools::CvImageRgb2Gray);
|
||||
QObject::connect(mAlgoTool, &CvAlgorithmTools::sendCvImageRgb2GrayResult, this, &CvImageRGB2GrayModel::GetRgb2GrayResult);
|
||||
|
||||
mChildThread->start();
|
||||
|
||||
cv::Mat src;
|
||||
mCvImage->CvImage()->copyTo(src);
|
||||
if (!src.empty())
|
||||
{
|
||||
emit computingStarted();
|
||||
emit SignalCvImageRgb2Gray(src);
|
||||
|
||||
modelValidationState = NodeValidationState::Valid;
|
||||
modelValidationError = QString();
|
||||
}
|
||||
}
|
||||
catch (...)
|
||||
{
|
||||
modelValidationState = NodeValidationState::Warning;
|
||||
modelValidationError = QStringLiteral("ȱʧ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʧ<EFBFBD><EFBFBD>!");
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
void CvImageRGB2GrayModel::GetRgb2GrayResult(cv::Mat grayImg)
|
||||
{
|
||||
mCvImage->setCvImage(grayImg);
|
||||
|
||||
if (mAlgoTool)
|
||||
{
|
||||
mChildThread->quit();
|
||||
mChildThread->wait();
|
||||
mAlgoTool = Q_NULLPTR;
|
||||
mChildThread = Q_NULLPTR;
|
||||
}
|
||||
|
||||
PortIndex const outPortIndex = 0;
|
||||
Q_EMIT dataUpdated(outPortIndex);
|
||||
Q_EMIT computingFinished();
|
||||
}
|
||||
|
||||
void CvImageRGB2GrayModel::setInData(std::shared_ptr<NodeData>data , int)
|
||||
{
|
||||
if (data == nullptr)
|
||||
return;
|
||||
if (data->type() == mCvImage->type())
|
||||
{
|
||||
auto dataPtr = std::dynamic_pointer_cast<CvImageData>(data);
|
||||
if (dataPtr->CvImage()->empty())
|
||||
return;
|
||||
mCvImage->setCvImage(*dataPtr->CvImage());
|
||||
}
|
||||
RunTask();
|
||||
}
|
||||
|
||||
std::shared_ptr<NodeData> CvImageRGB2GrayModel::outData(PortIndex port)
|
||||
{
|
||||
return std::dynamic_pointer_cast<CvImageData>(mCvImage);
|
||||
}
|
69
NodeEditorPro/examples/opcv/CvImageRGB2GrayModel.h
Normal file
69
NodeEditorPro/examples/opcv/CvImageRGB2GrayModel.h
Normal file
@ -0,0 +1,69 @@
|
||||
#pragma once
|
||||
|
||||
#include <iostream>
|
||||
#include <QObject>
|
||||
#include <QWidget>
|
||||
#include <QThread>
|
||||
|
||||
#include "DataModelRegistry.hpp"
|
||||
#include "NodeDataModel.hpp"
|
||||
|
||||
#include "opcv/CvImageData.h"
|
||||
#include "opcv/CvAlgorithmTools.h"
|
||||
|
||||
#include <opencv2/opencv.hpp>
|
||||
#include <opencv2/imgproc/types_c.h>
|
||||
|
||||
using QtNodes::PortType;
|
||||
using QtNodes::PortIndex;
|
||||
using QtNodes::NodeData;
|
||||
using QtNodes::NodeDataType;
|
||||
using QtNodes::NodeDataModel;
|
||||
using QtNodes::NodeValidationState;
|
||||
|
||||
class CvImageRGB2GrayModel :public NodeDataModel
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
CvImageRGB2GrayModel();
|
||||
virtual ~CvImageRGB2GrayModel() {}
|
||||
|
||||
public:
|
||||
QString caption() const override { return QStringLiteral("cvͼ<EFBFBD><EFBFBD>ת<EFBFBD>Ҷ<EFBFBD>"); }
|
||||
QString name() const override { return QStringLiteral("cvͼ<EFBFBD><EFBFBD>ת<EFBFBD>Ҷ<EFBFBD>"); }
|
||||
virtual QString modelName() const { return QStringLiteral("cvͼ<EFBFBD><EFBFBD>ת<EFBFBD>Ҷ<EFBFBD>"); }
|
||||
|
||||
QWidget* embeddedWidget() override { return Q_NULLPTR; }
|
||||
|
||||
bool resizable() const override { return false; }
|
||||
|
||||
NodeValidationState validationState() const override { return modelValidationState; }
|
||||
QString validationMessage() const override { return modelValidationError; }
|
||||
|
||||
unsigned int nPorts(PortType portType) const override;
|
||||
|
||||
NodeDataType dataType(PortType portType, PortIndex portIndex) const override { return CvImageData().type(); };
|
||||
|
||||
void setInData(std::shared_ptr<NodeData>, int) override;
|
||||
std::shared_ptr<NodeData> outData(PortIndex port) override;
|
||||
|
||||
protected:
|
||||
bool RunTask();
|
||||
|
||||
signals:
|
||||
void SignalCvImageRgb2Gray(cv::Mat rgbImg);
|
||||
|
||||
public slots:
|
||||
void GetRgb2GrayResult(cv::Mat grayImg);
|
||||
|
||||
public:
|
||||
NodeValidationState modelValidationState = NodeValidationState::Warning;
|
||||
QString modelValidationError = QStringLiteral("ͼƬ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>δ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>!");
|
||||
|
||||
private:
|
||||
CvAlgorithmTools* mAlgoTool = Q_NULLPTR;
|
||||
QThread* mChildThread = Q_NULLPTR;
|
||||
|
||||
std::shared_ptr<CvImageData> mCvImage;
|
||||
};
|
||||
|
128
NodeEditorPro/examples/opcv/CvImageShowModel.cpp
Normal file
128
NodeEditorPro/examples/opcv/CvImageShowModel.cpp
Normal file
@ -0,0 +1,128 @@
|
||||
#include "opcv/CvImageShowModel.h"
|
||||
|
||||
CvImageShowModel::CvImageShowModel()
|
||||
{
|
||||
//moveToThread(this);
|
||||
|
||||
mCvImageView = new CvImageViewWidget();
|
||||
mCvImageView->installEventFilter(this);
|
||||
mCvImageView->resize(200, 200);
|
||||
mCvImageData = std::make_shared<CvImageData>();
|
||||
//m_hRegion = std::make_shared<HRegionData>();
|
||||
}
|
||||
|
||||
void CvImageShowModel::inputConnectionDeleted(QtNodes::Connection const&)
|
||||
{
|
||||
mCvImageView->showImage(cv::Mat());
|
||||
|
||||
mCvImageData = std::make_shared<CvImageData>();
|
||||
|
||||
PortIndex const outPortIndex = 0;
|
||||
modelValidationState = NodeValidationState::Warning;
|
||||
modelValidationError = QStringLiteral("ͼƬ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>δ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>!");
|
||||
Q_EMIT dataUpdated(outPortIndex);
|
||||
}
|
||||
|
||||
bool CvImageShowModel::RunTask()
|
||||
{
|
||||
PortIndex const outPortIndex = 0;
|
||||
try
|
||||
{
|
||||
//qDebug() << "22show";
|
||||
//QThread::sleep(3);
|
||||
|
||||
mCvImageView->showImage(*mCvImageData->CvImage());
|
||||
modelValidationState = NodeValidationState::Valid;
|
||||
modelValidationError = QString();
|
||||
}
|
||||
catch (...)
|
||||
{
|
||||
modelValidationState = NodeValidationState::Warning;
|
||||
modelValidationError = QStringLiteral("ȱʧ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʧ<EFBFBD><EFBFBD>!");
|
||||
}
|
||||
|
||||
Q_EMIT dataUpdated(outPortIndex);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool CvImageShowModel::eventFilter(QObject* watched, QEvent* event)
|
||||
{
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
unsigned int CvImageShowModel::nPorts(PortType portType) const
|
||||
{
|
||||
unsigned int result = 1;
|
||||
|
||||
switch (portType)
|
||||
{
|
||||
case PortType::In:
|
||||
result = 1;
|
||||
break;
|
||||
|
||||
case PortType::Out:
|
||||
result = 1;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
NodeDataType CvImageShowModel::dataType(PortType portType, PortIndex portIndex) const
|
||||
{
|
||||
switch (portIndex)
|
||||
{
|
||||
case 0:
|
||||
return CvImageData().type();
|
||||
break;
|
||||
case 1:
|
||||
return CvImageData().type();
|
||||
break;
|
||||
}
|
||||
return CvImageData().type();
|
||||
}
|
||||
|
||||
void CvImageShowModel::setInData(std::shared_ptr<NodeData> data, int portIndex)
|
||||
{
|
||||
if (data == nullptr)
|
||||
return;
|
||||
if (data->type() == mCvImageData->type())
|
||||
{
|
||||
auto dataPtr = std::dynamic_pointer_cast<CvImageData>(data);
|
||||
if (dataPtr->CvImage()->empty())
|
||||
return;
|
||||
mCvImageData->setCvImage(*dataPtr->CvImage());
|
||||
}
|
||||
//else if (data->type() == m_hRegion->type())
|
||||
//{
|
||||
// auto dataPtr = std::dynamic_pointer_cast<HRegionData>(data);
|
||||
// if (!dataPtr->hRegion()->IsInitialized())
|
||||
// return;
|
||||
// m_hRegion->setHRegion(*dataPtr->hRegion());
|
||||
// m_hRegion->setSize(dataPtr->getSize());
|
||||
// HImage tmpImg = m_hRegion->hRegion()->RegionToBin(255, 0,
|
||||
// m_hRegion->getSize().width(), m_hRegion->getSize().height());
|
||||
// m_hImage->setHImage(tmpImg);
|
||||
//}
|
||||
RunTask();
|
||||
}
|
||||
|
||||
|
||||
|
||||
std::shared_ptr<NodeData> CvImageShowModel::outData(PortIndex index)
|
||||
{
|
||||
switch (index)
|
||||
{
|
||||
case 0:
|
||||
return std::dynamic_pointer_cast<CvImageData>(mCvImageData);
|
||||
break;
|
||||
case 1:
|
||||
return std::dynamic_pointer_cast<CvImageData>(mCvImageData);
|
||||
break;
|
||||
}
|
||||
return std::dynamic_pointer_cast<CvImageData>(mCvImageData);
|
||||
}
|
68
NodeEditorPro/examples/opcv/CvImageShowModel.h
Normal file
68
NodeEditorPro/examples/opcv/CvImageShowModel.h
Normal file
@ -0,0 +1,68 @@
|
||||
#pragma once
|
||||
|
||||
#include <iostream>
|
||||
|
||||
#include <QObject>
|
||||
#include <QWidget>
|
||||
#include <QLabel>
|
||||
#include <QThread>
|
||||
|
||||
#include "DataModelRegistry.hpp"
|
||||
#include "NodeDataModel.hpp"
|
||||
|
||||
#include "opcv/CvImageViewWidget.h"
|
||||
#include "opcv/CvImageData.h"
|
||||
|
||||
#include <opencv2/opencv.hpp>
|
||||
|
||||
using QtNodes::PortType;
|
||||
using QtNodes::PortIndex;
|
||||
using QtNodes::NodeData;
|
||||
using QtNodes::NodeDataType;
|
||||
using QtNodes::NodeDataModel;
|
||||
using QtNodes::NodeValidationState;
|
||||
|
||||
class CvImageShowModel :public NodeDataModel
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
CvImageShowModel();
|
||||
virtual ~CvImageShowModel() {}
|
||||
|
||||
public:
|
||||
QString caption() const override { return QStringLiteral("cvͼ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʾ"); }
|
||||
QString name() const override { return QStringLiteral("cvͼ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʾ"); }
|
||||
virtual QString modelName() const { return QStringLiteral("cvͼ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʾ"); }
|
||||
|
||||
QWidget* embeddedWidget() override { return mCvImageView; }
|
||||
bool resizable() const override { return false; }
|
||||
|
||||
unsigned int nPorts(PortType portType) const override;
|
||||
NodeDataType dataType(PortType portType, PortIndex portIndex) const override;
|
||||
|
||||
NodeValidationState validationState() const override { return modelValidationState; }
|
||||
QString validationMessage() const override { return modelValidationError; }
|
||||
|
||||
public Q_SLOTS:
|
||||
void inputConnectionDeleted(QtNodes::Connection const&) override;
|
||||
|
||||
protected:
|
||||
bool RunTask();
|
||||
bool eventFilter(QObject* watched, QEvent* event) override;
|
||||
|
||||
public:
|
||||
NodeValidationState modelValidationState = NodeValidationState::Warning;
|
||||
QString modelValidationError = QStringLiteral("ͼƬ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>δ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>!");
|
||||
|
||||
private:
|
||||
CvImageViewWidget* mCvImageView;
|
||||
|
||||
std::shared_ptr<CvImageData> mCvImageData;
|
||||
//std::shared_ptr<HRegionData> mCvRect;
|
||||
|
||||
public:
|
||||
std::shared_ptr<NodeData> outData(PortIndex port) override;
|
||||
void setInData(std::shared_ptr<NodeData>, int) override;
|
||||
|
||||
};
|
85
NodeEditorPro/examples/opcv/CvImageViewWidget.cpp
Normal file
85
NodeEditorPro/examples/opcv/CvImageViewWidget.cpp
Normal file
@ -0,0 +1,85 @@
|
||||
#include "opcv/CvImageViewWidget.h"
|
||||
|
||||
#include <QDebug>
|
||||
|
||||
CvImageViewWidget::CvImageViewWidget(QWidget* parent)
|
||||
{
|
||||
if (parent != Q_NULLPTR)
|
||||
this->setParent(parent);
|
||||
this->setStyleSheet("background-color:black;");
|
||||
curPixmap = new QPixmap();
|
||||
}
|
||||
|
||||
void CvImageViewWidget::showImage(cv::Mat const& _cvimg)
|
||||
{
|
||||
if (_cvimg.empty())
|
||||
{
|
||||
curPixmap = new QPixmap();
|
||||
this->setPixmap(*curPixmap);
|
||||
this->update();
|
||||
return;
|
||||
}
|
||||
|
||||
int width;
|
||||
int height;
|
||||
double zoomRatio = 1.0;
|
||||
|
||||
width = _cvimg.cols;
|
||||
height = _cvimg.rows;
|
||||
|
||||
if (width > this->width())
|
||||
zoomRatio = 1.0 * this->width() / width;
|
||||
|
||||
cv::resize(_cvimg, curImage, cv::Size(width * zoomRatio, height * zoomRatio));
|
||||
CvImageToQPixmap(curImage, *curPixmap);
|
||||
|
||||
this->update();
|
||||
}
|
||||
|
||||
void CvImageViewWidget::CvImageToQPixmap(cv::Mat const& _img, QPixmap& tarImg)
|
||||
{
|
||||
const uchar* pSrc = (const uchar*)_img.data;
|
||||
QImage image;
|
||||
if (_img.type() == CV_8UC1)
|
||||
{
|
||||
qDebug() << "CV_8UC1";
|
||||
image = QImage(pSrc, _img.cols, _img.rows, _img.step, QImage::Format_Grayscale8);
|
||||
}
|
||||
else if (_img.type() == CV_8UC3)
|
||||
{
|
||||
qDebug() << "CV_8UC3";
|
||||
image = QImage(pSrc, _img.cols, _img.rows, _img.step, QImage::Format_RGB888);
|
||||
}
|
||||
else if (_img.type() == CV_8UC4)
|
||||
{
|
||||
qDebug() << "CV_8UC4";
|
||||
image = QImage(pSrc, _img.cols, _img.rows, _img.step, QImage::Format_ARGB32);
|
||||
}
|
||||
else
|
||||
{
|
||||
qDebug() << "ERROR: Mat could not be converted to QImage.";
|
||||
return;
|
||||
}
|
||||
tarImg = QPixmap::fromImage(image);
|
||||
}
|
||||
|
||||
bool CvImageViewWidget::QImage2CvImage(QImage& from, cv::Mat& to)
|
||||
{
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
void CvImageViewWidget::QPixmapToCvRegion(QPixmap const& _pix, cv::Rect2d& tarImg)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void CvImageViewWidget::paintEvent(QPaintEvent* event)
|
||||
{
|
||||
//QPainter painter(this);
|
||||
if (!curPixmap->isNull())
|
||||
{
|
||||
this->setPixmap(curPixmap->scaled(this->width(), this->height(), Qt::KeepAspectRatio));
|
||||
}
|
||||
QLabel::paintEvent(event);
|
||||
}
|
34
NodeEditorPro/examples/opcv/CvImageViewWidget.h
Normal file
34
NodeEditorPro/examples/opcv/CvImageViewWidget.h
Normal file
@ -0,0 +1,34 @@
|
||||
#pragma once
|
||||
|
||||
#include <QWidget>
|
||||
#include <QLabel>
|
||||
#include <QGraphicsView>
|
||||
#include <QPixmap>
|
||||
#include <QPainter>
|
||||
|
||||
#include <opencv2/opencv.hpp>
|
||||
|
||||
class CvImageViewWidget :public QLabel
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
CvImageViewWidget(QWidget* parent = Q_NULLPTR);
|
||||
virtual ~CvImageViewWidget() {}
|
||||
|
||||
public:
|
||||
void showImage(cv::Mat const& _himg);
|
||||
|
||||
static void CvImageToQPixmap(cv::Mat const& _img, QPixmap& tarImg);
|
||||
static bool QImage2CvImage(QImage& from, cv::Mat& to);
|
||||
static void QPixmapToCvRegion(QPixmap const& _pix, cv::Rect2d& tarImg);
|
||||
|
||||
protected:
|
||||
void paintEvent(QPaintEvent* event) override;
|
||||
|
||||
private:
|
||||
cv::Mat curImage;
|
||||
QPixmap* curPixmap;
|
||||
// 实例化画家对象,this指定的是绘图设备
|
||||
QPainter painter;
|
||||
};
|
37
NodeEditorPro/examples/opcv/CvRectData.h
Normal file
37
NodeEditorPro/examples/opcv/CvRectData.h
Normal file
@ -0,0 +1,37 @@
|
||||
#pragma once
|
||||
|
||||
#include <QtGui/QPixmap>
|
||||
|
||||
#include "NodeDataModel.hpp"
|
||||
|
||||
#include <opencv2/opencv.hpp>
|
||||
|
||||
using QtNodes::NodeData;
|
||||
using QtNodes::NodeDataType;
|
||||
|
||||
class CvRectData :public NodeData
|
||||
{
|
||||
public:
|
||||
CvRectData() { mCvRect = cv::Rect(); }
|
||||
CvRectData(cv::Rect& _rect)
|
||||
{
|
||||
if (!_rect.empty())
|
||||
mCvRect = _rect;
|
||||
}
|
||||
|
||||
NodeDataType type() const override { return { "CvRect","Rect" }; }
|
||||
|
||||
cv::Rect* CvRect() { return &mCvRect; }
|
||||
void setCvRect(cv::Rect const& _rect)
|
||||
{
|
||||
if (_rect.empty())
|
||||
return;
|
||||
mCvRect = _rect;
|
||||
}
|
||||
void setSize(QSize const& _size) { mSize = _size; }
|
||||
QSize getSize() { return mSize; }
|
||||
|
||||
private:
|
||||
cv::Rect mCvRect;
|
||||
QSize mSize;
|
||||
};
|
7
NodeEditorPro/examples/opcv/MoudleOpencvNodes.h
Normal file
7
NodeEditorPro/examples/opcv/MoudleOpencvNodes.h
Normal file
@ -0,0 +1,7 @@
|
||||
#pragma once
|
||||
|
||||
#include "opcv/CvImageLoaderModel.h"
|
||||
#include "opcv/CvImageShowModel.h"
|
||||
#include "opcv/CvImageRGB2GrayModel.h"
|
||||
|
||||
#include "opcv/CvGraphicsShowModel.h"
|
83
NodeEditorPro/examples/opcv/Widget.ui
Normal file
83
NodeEditorPro/examples/opcv/Widget.ui
Normal file
@ -0,0 +1,83 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<ui version="4.0">
|
||||
<class>Form</class>
|
||||
<widget class="QWidget" name="Form">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>391</width>
|
||||
<height>293</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="windowTitle">
|
||||
<string>Form</string>
|
||||
</property>
|
||||
<layout class="QGridLayout" name="gridLayout">
|
||||
<item row="0" column="0">
|
||||
<layout class="QVBoxLayout" name="verticalLayout">
|
||||
<item>
|
||||
<layout class="QHBoxLayout" name="horizontalLayout">
|
||||
<item>
|
||||
<widget class="QLabel" name="label">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Preferred" vsizetype="Preferred">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="maximumSize">
|
||||
<size>
|
||||
<width>60</width>
|
||||
<height>16777215</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>图片缩放</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QSlider" name="horizontalSlider">
|
||||
<property name="minimum">
|
||||
<number>-20</number>
|
||||
</property>
|
||||
<property name="maximum">
|
||||
<number>20</number>
|
||||
</property>
|
||||
<property name="pageStep">
|
||||
<number>2</number>
|
||||
</property>
|
||||
<property name="orientation">
|
||||
<enum>Qt::Horizontal</enum>
|
||||
</property>
|
||||
<property name="tickPosition">
|
||||
<enum>QSlider::TicksBelow</enum>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<spacer name="horizontalSpacer">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Horizontal</enum>
|
||||
</property>
|
||||
<property name="sizeHint" stdset="0">
|
||||
<size>
|
||||
<width>40</width>
|
||||
<height>20</height>
|
||||
</size>
|
||||
</property>
|
||||
</spacer>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QGraphicsView" name="graphicsView"/>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<resources/>
|
||||
<connections/>
|
||||
</ui>
|
Reference in New Issue
Block a user