Commit 148f52d1a669c9014c9ec1d6539e7cf5ec6bf292

Authored by Josh Klontz
1 parent f201d423

Revert "remove skinmask"

This reverts commit e4eb1beb22657cc35dc74c1adc555a5af7c4818e.
openbr/plugins/imgproc/skinmask.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 <opencv2/imgproc/imgproc.hpp>
  18 +
  19 +#include <openbr/plugins/openbr_internal.h>
  20 +
  21 +using namespace cv;
  22 +
  23 +namespace br
  24 +{
  25 +
  26 +/*!
  27 + * \ingroup transforms
  28 + * \brief Make a mask over skin in an image
  29 + * \br_link http://worldofcameras.wordpress.com/tag/skin-detection-opencv/
  30 + * \author Josh Klontz \cite jklontz
  31 + */
  32 +class SkinMaskTransform : public UntrainableTransform
  33 +{
  34 + Q_OBJECT
  35 +
  36 + void project(const Template &src, Template &dst) const
  37 + {
  38 + Mat m;
  39 + cvtColor(src, m, COLOR_BGR2YCrCb);
  40 + std::vector<Mat> mv;
  41 + split(m, mv);
  42 + Mat mask = Mat(m.rows, m.cols, CV_8UC1);
  43 +
  44 + for (int i=0; i<m.rows; i++) {
  45 + for (int j=0; j<m.cols; j++) {
  46 + int Cr= mv[1].at<quint8>(i,j);
  47 + int Cb =mv[2].at<quint8>(i,j);
  48 + mask.at<quint8>(i, j) = (Cr>130 && Cr<170) && (Cb>70 && Cb<125) ? 255 : 0;
  49 + }
  50 + }
  51 +
  52 + dst = mask;
  53 + }
  54 +};
  55 +
  56 +BR_REGISTER(Transform, SkinMaskTransform)
  57 +
  58 +} // namespace br
  59 +
  60 +#include "imgproc/skinmask.moc"
... ...