Skip to content

Commit

Permalink
Added CountNonZero processor
Browse files Browse the repository at this point in the history
  • Loading branch information
wawanbreton committed Aug 22, 2016
1 parent 07358e5 commit 42605eb
Show file tree
Hide file tree
Showing 6 changed files with 86 additions and 2 deletions.
6 changes: 4 additions & 2 deletions cvcomposer.pro
Original file line number Diff line number Diff line change
Expand Up @@ -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 \
Expand Down Expand Up @@ -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 \
Expand Down
3 changes: 3 additions & 0 deletions gui/plugitem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
4 changes: 4 additions & 0 deletions plugwidget/dataviewerwidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
36 changes: 36 additions & 0 deletions processor/math/countnonzeroprocessor.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
// Copyright 2016 Erwan MATHIEU <[email protected]>
//
// 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 <http://www.gnu.org/licenses/>.

#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<cv::Mat>()));
return outputs;
}

30 changes: 30 additions & 0 deletions processor/math/countnonzeroprocessor.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
// Copyright 2016 Erwan MATHIEU <[email protected]>
//
// 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 <http://www.gnu.org/licenses/>.

#pragma once

#include "processor/abstractprocessor.h"

class CountNonZeroProcessor : public AbstractProcessor
{
public:
CountNonZeroProcessor();

protected:
virtual Properties processImpl(const Properties &inputs) override;
};

9 changes: 9 additions & 0 deletions processor/processorsfactory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -68,6 +69,10 @@ QList<QPair<QString, QStringList> > ProcessorsFactory::getProcessors()
data << "Kernel";
processors << QPair<QString, QStringList>("Data", data);

QStringList math;
math << "CountNonZero";
processors << QPair<QString, QStringList>("Math", math);

QStringList shapes;
shapes << "Rectangle" << "DrawRectangle" << "DrawCircle" << "DrawEllipse" << "DrawLine"
<< "DrawText";
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit 42605eb

Please sign in to comment.