Skip to content

Commit 42605eb

Browse files
committed
Added CountNonZero processor
1 parent 07358e5 commit 42605eb

File tree

6 files changed

+86
-2
lines changed

6 files changed

+86
-2
lines changed

cvcomposer.pro

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,8 @@ SOURCES += main.cpp\
8585
plugwidget/dataviewerwidget.cpp \
8686
processor/viewer/dataviewerprocessor.cpp \
8787
processor/viewer/imageviewerprocessor.cpp \
88-
plugwidget/imageviewerwidget.cpp
88+
plugwidget/imageviewerwidget.cpp \
89+
processor/math/countnonzeroprocessor.cpp
8990

9091
HEADERS += gui/mainwidget.h \
9192
gui/composerwidget.h \
@@ -152,7 +153,8 @@ HEADERS += gui/mainwidget.h \
152153
plugwidget/dataviewerwidget.h \
153154
processor/viewer/dataviewerprocessor.h \
154155
processor/viewer/imageviewerprocessor.h \
155-
plugwidget/imageviewerwidget.h
156+
plugwidget/imageviewerwidget.h \
157+
processor/math/countnonzeroprocessor.h
156158

157159
FORMS += \
158160
gui/mainwidget.ui \

gui/plugitem.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,9 @@ PlugItem::PlugItem(Plug *plug, QGraphicsItem *parent) :
6060
case PlugType::Rectangle:
6161
brush = QColor(142, 68, 173);
6262
break;
63+
case PlugType::Double:
64+
brush = QColor(230, 126, 34);
65+
break;
6366
default:
6467
brush = Qt::white;
6568
break;

plugwidget/dataviewerwidget.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,10 @@ void DataViewerWidget::onNodeProcessed(const Properties &inputs, const Propertie
5151
_text = _text.arg(rect.width);
5252
_text = _text.arg(rect.height);
5353
}
54+
else if(output.type() == QVariant::Int)
55+
{
56+
_text = QString::number(output.toInt());
57+
}
5458
#warning TBD display kernel
5559

5660
update();
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
// Copyright 2016 Erwan MATHIEU <[email protected]>
2+
//
3+
// This file is part of CvComposer.
4+
//
5+
// CvComposer is free software: you can redistribute it and/or modify
6+
// it under the terms of the GNU General Public License as published by
7+
// the Free Software Foundation, either version 3 of the License, or
8+
// (at your option) any later version.
9+
//
10+
// CvComposer is distributed in the hope that it will be useful,
11+
// but WITHOUT ANY WARRANTY; without even the implied warranty of
12+
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13+
// GNU General Public License for more details.
14+
//
15+
// You should have received a copy of the GNU General Public License
16+
// along with CvComposer. If not, see <http://www.gnu.org/licenses/>.
17+
18+
#include "countnonzeroprocessor.h"
19+
20+
#include "global/cvutils.h"
21+
22+
23+
CountNonZeroProcessor::CountNonZeroProcessor()
24+
{
25+
addInput("image", PlugType::Image);
26+
27+
addOutput("count", PlugType::Double);
28+
}
29+
30+
Properties CountNonZeroProcessor::processImpl(const Properties &inputs)
31+
{
32+
Properties outputs;
33+
outputs.insert("count", cv::countNonZero(inputs["image"].value<cv::Mat>()));
34+
return outputs;
35+
}
36+
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
// Copyright 2016 Erwan MATHIEU <[email protected]>
2+
//
3+
// This file is part of CvComposer.
4+
//
5+
// CvComposer is free software: you can redistribute it and/or modify
6+
// it under the terms of the GNU General Public License as published by
7+
// the Free Software Foundation, either version 3 of the License, or
8+
// (at your option) any later version.
9+
//
10+
// CvComposer is distributed in the hope that it will be useful,
11+
// but WITHOUT ANY WARRANTY; without even the implied warranty of
12+
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13+
// GNU General Public License for more details.
14+
//
15+
// You should have received a copy of the GNU General Public License
16+
// along with CvComposer. If not, see <http://www.gnu.org/licenses/>.
17+
18+
#pragma once
19+
20+
#include "processor/abstractprocessor.h"
21+
22+
class CountNonZeroProcessor : public AbstractProcessor
23+
{
24+
public:
25+
CountNonZeroProcessor();
26+
27+
protected:
28+
virtual Properties processImpl(const Properties &inputs) override;
29+
};
30+

processor/processorsfactory.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
#include "processor/geometry/makeborderprocessor.h"
3737
#include "processor/input/cameraprocessor.h"
3838
#include "processor/input/imagefromfileprocessor.h"
39+
#include "processor/math/countnonzeroprocessor.h"
3940
#include "processor/shape/drawcircleprocessor.h"
4041
#include "processor/shape/drawellipseprocessor.h"
4142
#include "processor/shape/drawlineprocessor.h"
@@ -68,6 +69,10 @@ QList<QPair<QString, QStringList> > ProcessorsFactory::getProcessors()
6869
data << "Kernel";
6970
processors << QPair<QString, QStringList>("Data", data);
7071

72+
QStringList math;
73+
math << "CountNonZero";
74+
processors << QPair<QString, QStringList>("Math", math);
75+
7176
QStringList shapes;
7277
shapes << "Rectangle" << "DrawRectangle" << "DrawCircle" << "DrawEllipse" << "DrawLine"
7378
<< "DrawText";
@@ -218,6 +223,10 @@ AbstractProcessor *ProcessorsFactory::createProcessor(const QString &rawProcesso
218223
{
219224
return new LaplacianProcessor();
220225
}
226+
else if(rawProcessorName == "CountNonZero")
227+
{
228+
return new CountNonZeroProcessor();
229+
}
221230
else
222231
{
223232
qCritical() << "Unknown processor type" << rawProcessorName;

0 commit comments

Comments
 (0)