Commit fd9094e27713402d6f4c4ea02dc9f37d2a325bd0

Authored by Scott Klum
1 parent eaf723c9

Added FillContours

openbr/plugins/imgproc/fillcontours.cpp 0 → 100644
  1 +/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
  2 + * Copyright 2012 The MITRE Corporation *
  3 + * *
  4 + * Licensed under the Apache License, Version 2.0 (the "License"); *
  5 + * you may not use this file except in compliance with the License. *
  6 + * You may obtain a copy of the License at *
  7 + * *
  8 + * http://www.apache.org/licenses/LICENSE-2.0 *
  9 + * *
  10 + * Unless required by applicable law or agreed to in writing, software *
  11 + * distributed under the License is distributed on an "AS IS" BASIS, *
  12 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. *
  13 + * See the License for the specific language governing permissions and *
  14 + * limitations under the License. *
  15 + * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
  16 +
  17 +#include <openbr/plugins/openbr_internal.h>
  18 +#include <openbr/core/opencvutils.h>
  19 +#include <opencv2/imgproc/imgproc.hpp>
  20 +
  21 +using namespace cv;
  22 +
  23 +namespace br
  24 +{
  25 +
  26 +/*!
  27 + * \ingroup transforms
  28 + * \brief Fills contours with with white pixels.
  29 + * \author Scott Klum \cite sklum
  30 + */
  31 +class FillContoursTransform : public UntrainableTransform
  32 +{
  33 + Q_OBJECT
  34 +
  35 + Q_PROPERTY(float epsilon READ get_epsilon WRITE set_epsilon RESET reset_epsilon STORED false)
  36 + Q_PROPERTY(float minSize READ get_minSize WRITE set_minSize RESET reset_minSize STORED false)
  37 + BR_PROPERTY(float, epsilon, 3)
  38 + BR_PROPERTY(int, minSize, 40)
  39 +
  40 + void project(const Template &src, Template &dst) const
  41 + {
  42 + dst.m() = Mat::zeros(src.m().rows,src.m().cols,src.m().type());
  43 +
  44 + vector<vector<Point> > contours;
  45 + vector<Vec4i> hierarchy;
  46 +
  47 + /// Find contours
  48 + findContours(src.m(), contours, hierarchy, CV_RETR_TREE, CV_CHAIN_APPROX_SIMPLE, Point(0, 0));
  49 +
  50 + if (smooth)
  51 + for(size_t i=0; i<contours.size(); i++)
  52 + approxPolyDP(Mat(contours[i]), contours[i], epsilon, true);
  53 +
  54 + for(size_t i=0; i<contours.size(); i++)
  55 + if (contours[i].size() > minSize)
  56 + drawContours(dst, contours, i, Scalar(255,255,255), CV_FILLED);
  57 + }
  58 +};
  59 +
  60 +BR_REGISTER(Transform, FillContoursTransform)
  61 +
  62 +} // namespace br
  63 +
  64 +#include "imgproc/fillcontours.moc"
  65 +
... ...