diff --git a/cvcomposer.pro b/cvcomposer.pro index 8fac246..666de07 100644 --- a/cvcomposer.pro +++ b/cvcomposer.pro @@ -85,7 +85,8 @@ SOURCES += main.cpp\ plugwidget/dataviewerwidget.cpp \ processor/viewer/dataviewerprocessor.cpp \ processor/viewer/imageviewerprocessor.cpp \ - plugwidget/imageviewerwidget.cpp + plugwidget/imageviewerwidget.cpp \ + processor/math/countnonzeroprocessor.cpp HEADERS += gui/mainwidget.h \ gui/composerwidget.h \ @@ -152,7 +153,8 @@ HEADERS += gui/mainwidget.h \ plugwidget/dataviewerwidget.h \ processor/viewer/dataviewerprocessor.h \ processor/viewer/imageviewerprocessor.h \ - plugwidget/imageviewerwidget.h + plugwidget/imageviewerwidget.h \ + processor/math/countnonzeroprocessor.h FORMS += \ gui/mainwidget.ui \ diff --git a/gui/plugitem.cpp b/gui/plugitem.cpp index 00848ce..382b2e5 100644 --- a/gui/plugitem.cpp +++ b/gui/plugitem.cpp @@ -60,6 +60,9 @@ PlugItem::PlugItem(Plug *plug, QGraphicsItem *parent) : case PlugType::Rectangle: brush = QColor(142, 68, 173); break; + case PlugType::Double: + brush = QColor(230, 126, 34); + break; default: brush = Qt::white; break; diff --git a/plugwidget/dataviewerwidget.cpp b/plugwidget/dataviewerwidget.cpp index 1f47e67..57b506c 100644 --- a/plugwidget/dataviewerwidget.cpp +++ b/plugwidget/dataviewerwidget.cpp @@ -51,6 +51,10 @@ void DataViewerWidget::onNodeProcessed(const Properties &inputs, const Propertie _text = _text.arg(rect.width); _text = _text.arg(rect.height); } + else if(output.type() == QVariant::Int) + { + _text = QString::number(output.toInt()); + } #warning TBD display kernel update(); diff --git a/processor/math/countnonzeroprocessor.cpp b/processor/math/countnonzeroprocessor.cpp new file mode 100644 index 0000000..9a8877c --- /dev/null +++ b/processor/math/countnonzeroprocessor.cpp @@ -0,0 +1,36 @@ +// Copyright 2016 Erwan MATHIEU +// +// This file is part of CvComposer. +// +// CvComposer is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// CvComposer is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with CvComposer. If not, see . + +#include "countnonzeroprocessor.h" + +#include "global/cvutils.h" + + +CountNonZeroProcessor::CountNonZeroProcessor() +{ + addInput("image", PlugType::Image); + + addOutput("count", PlugType::Double); +} + +Properties CountNonZeroProcessor::processImpl(const Properties &inputs) +{ + Properties outputs; + outputs.insert("count", cv::countNonZero(inputs["image"].value())); + return outputs; +} + diff --git a/processor/math/countnonzeroprocessor.h b/processor/math/countnonzeroprocessor.h new file mode 100644 index 0000000..1be0d5d --- /dev/null +++ b/processor/math/countnonzeroprocessor.h @@ -0,0 +1,30 @@ +// Copyright 2016 Erwan MATHIEU +// +// This file is part of CvComposer. +// +// CvComposer is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// CvComposer is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with CvComposer. If not, see . + +#pragma once + +#include "processor/abstractprocessor.h" + +class CountNonZeroProcessor : public AbstractProcessor +{ + public: + CountNonZeroProcessor(); + + protected: + virtual Properties processImpl(const Properties &inputs) override; +}; + diff --git a/processor/processorsfactory.cpp b/processor/processorsfactory.cpp index b61602b..687dbe5 100644 --- a/processor/processorsfactory.cpp +++ b/processor/processorsfactory.cpp @@ -36,6 +36,7 @@ #include "processor/geometry/makeborderprocessor.h" #include "processor/input/cameraprocessor.h" #include "processor/input/imagefromfileprocessor.h" +#include "processor/math/countnonzeroprocessor.h" #include "processor/shape/drawcircleprocessor.h" #include "processor/shape/drawellipseprocessor.h" #include "processor/shape/drawlineprocessor.h" @@ -68,6 +69,10 @@ QList > ProcessorsFactory::getProcessors() data << "Kernel"; processors << QPair("Data", data); + QStringList math; + math << "CountNonZero"; + processors << QPair("Math", math); + QStringList shapes; shapes << "Rectangle" << "DrawRectangle" << "DrawCircle" << "DrawEllipse" << "DrawLine" << "DrawText"; @@ -218,6 +223,10 @@ AbstractProcessor *ProcessorsFactory::createProcessor(const QString &rawProcesso { return new LaplacianProcessor(); } + else if(rawProcessorName == "CountNonZero") + { + return new CountNonZeroProcessor(); + } else { qCritical() << "Unknown processor type" << rawProcessorName;