Fawkes API  Fawkes Development Version
thresholds_black.cpp
1 /* This program is free software; you can redistribute it and/or modify
2  * it under the terms of the GNU General Public License as published by
3  * the Free Software Foundation; either version 2 of the License, or
4  * (at your option) any later version. A runtime exception applies to
5  * this software (see LICENSE.GPL_WRE file mentioned below for details).
6  *
7  * This program is distributed in the hope that it will be useful,
8  * but WITHOUT ANY WARRANTY; without even the implied warranty of
9  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10  * GNU Library General Public License for more details.
11  *
12  * Read the full text in the LICENSE.GPL_WRE file in the doc directory.
13  */
14 
15 #include "thresholds_black.h"
16 #include <cmath>
17 
18 namespace firevision
19 {
20 #if 0 /* just to make Emacs auto-indent happy */
21 }
22 #endif
23 
24 /** @class ColorModelBlack <fvmodels/color/thresholds_black.h>
25  * Detect configurable shades/hues of "black" as a cuboid in YUV space.
26  */
27 
28 /**
29  * Initialize black colormodel. The Y reference component is always 0,
30  * i.e. the accepted cuboid extends from Y=0 to Y=y_thresh, by u_thresh
31  * around ref_u, and by v_thresh around ref_v.
32  *
33  * @param y_thresh maximum brightness
34  * @param u_thresh maximum difference from ref_u
35  * @param v_thresh maximum difference from ref_v
36  * @param ref_u U component of the "black" reference color (default 128)
37  * @param ref_v V component of the "black" reference color (default 128)
38  */
39 ColorModelBlack::ColorModelBlack(unsigned int y_thresh, unsigned int u_thresh, unsigned int v_thresh,
40  unsigned int ref_u, unsigned int ref_v) :
41  y_thresh_(y_thresh),
42  u_thresh_(u_thresh),
43  v_thresh_(v_thresh),
44  ref_u_ (ref_u),
45  ref_v_ (ref_v) {}
46 
47 color_t
49  unsigned int u,
50  unsigned int v) const
51 {
52  int diff_u = ref_u_ - u;
53  int diff_v = ref_v_ - v;
54  if ( y <= y_thresh_
55 #if defined(__GNUC__) && ((__GNUC__ == 4 && __GNUC_MINOR__ >= 6) || (__GNUC__ > 4))
56  && std::abs(diff_u) < u_thresh_ && std::abs(diff_v) < v_thresh_
57 #else
58  && (diff_u < 0) ? (diff_u > -1*(int)u_thresh_) : (diff_u < (int)u_thresh_)
59  && (diff_v < 0) ? (diff_v > -1*(int)v_thresh_) : (diff_v < (int)v_thresh_)
60 #endif
61  )
62  {
63  return C_BLACK;
64  } else {
65  return C_OTHER;
66  }
67 }
68 
69 const char *
71 {
72  return "ColorModelBlack";
73 }
74 
75 } // end namespace firevision
color_t determine(unsigned int y, unsigned int u, unsigned int v) const
Determine classification of YUV pixel.
ColorModelBlack(unsigned int y_thresh=30, unsigned int u_thresh=30, unsigned int v_thresh=30, unsigned int ref_u=128, unsigned int ref_v=128)
Initialize black colormodel.
const char * get_name()
Get name of color model.