From fd9094e27713402d6f4c4ea02dc9f37d2a325bd0 Mon Sep 17 00:00:00 2001 From: Scott Klum Date: Thu, 9 Apr 2015 15:17:47 -0400 Subject: [PATCH] Added FillContours --- openbr/plugins/imgproc/fillcontours.cpp | 65 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 65 insertions(+), 0 deletions(-) create mode 100644 openbr/plugins/imgproc/fillcontours.cpp diff --git a/openbr/plugins/imgproc/fillcontours.cpp b/openbr/plugins/imgproc/fillcontours.cpp new file mode 100644 index 0000000..aa3036b --- /dev/null +++ b/openbr/plugins/imgproc/fillcontours.cpp @@ -0,0 +1,65 @@ +/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * + * Copyright 2012 The MITRE Corporation * + * * + * Licensed under the Apache License, Version 2.0 (the "License"); * + * you may not use this file except in compliance with the License. * + * You may obtain a copy of the License at * + * * + * http://www.apache.org/licenses/LICENSE-2.0 * + * * + * Unless required by applicable law or agreed to in writing, software * + * distributed under the License is distributed on an "AS IS" BASIS, * + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * + * See the License for the specific language governing permissions and * + * limitations under the License. * + * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ + +#include +#include +#include + +using namespace cv; + +namespace br +{ + +/*! + * \ingroup transforms + * \brief Fills contours with with white pixels. + * \author Scott Klum \cite sklum + */ +class FillContoursTransform : public UntrainableTransform +{ + Q_OBJECT + + Q_PROPERTY(float epsilon READ get_epsilon WRITE set_epsilon RESET reset_epsilon STORED false) + Q_PROPERTY(float minSize READ get_minSize WRITE set_minSize RESET reset_minSize STORED false) + BR_PROPERTY(float, epsilon, 3) + BR_PROPERTY(int, minSize, 40) + + void project(const Template &src, Template &dst) const + { + dst.m() = Mat::zeros(src.m().rows,src.m().cols,src.m().type()); + + vector > contours; + vector hierarchy; + + /// Find contours + findContours(src.m(), contours, hierarchy, CV_RETR_TREE, CV_CHAIN_APPROX_SIMPLE, Point(0, 0)); + + if (smooth) + for(size_t i=0; i minSize) + drawContours(dst, contours, i, Scalar(255,255,255), CV_FILLED); + } +}; + +BR_REGISTER(Transform, FillContoursTransform) + +} // namespace br + +#include "imgproc/fillcontours.moc" + -- libgit2 0.21.4