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
17
#include <cmath>
18
19
namespace
firevision {
20
21
/** @class ColorModelBlack <fvmodels/color/thresholds_black.h>
22
* Detect configurable shades/hues of "black" as a cuboid in YUV space.
23
*/
24
25
/**
26
* Initialize black colormodel. The Y reference component is always 0,
27
* i.e. the accepted cuboid extends from Y=0 to Y=y_thresh, by u_thresh
28
* around ref_u, and by v_thresh around ref_v.
29
*
30
* @param y_thresh maximum brightness
31
* @param u_thresh maximum difference from ref_u
32
* @param v_thresh maximum difference from ref_v
33
* @param ref_u U component of the "black" reference color (default 128)
34
* @param ref_v V component of the "black" reference color (default 128)
35
*/
36
ColorModelBlack::ColorModelBlack
(
unsigned
int
y_thresh,
37
unsigned
int
u_thresh,
38
unsigned
int
v_thresh,
39
unsigned
int
ref_u,
40
unsigned
int
ref_v)
41
: y_thresh_(y_thresh), u_thresh_(u_thresh), v_thresh_(v_thresh), ref_u_(ref_u), ref_v_(ref_v)
42
{
43
}
44
45
color_t
46
ColorModelBlack::determine
(
unsigned
int
y,
unsigned
int
u,
unsigned
int
v)
const
47
{
48
int
diff_u = ref_u_ - u;
49
int
diff_v = ref_v_ - v;
50
if
(y <= y_thresh_
51
#
if
defined(__GNUC__) && ((__GNUC__ == 4 && __GNUC_MINOR__ >= 6) || (__GNUC__ > 4))
52
&& std::abs(diff_u) < u_thresh_ && std::abs(diff_v) < v_thresh_
53
#
else
54
&& (diff_u < 0)
55
? (diff_u > -1 * (
int
)u_thresh_)
56
: (diff_u < (
int
)u_thresh_) && (diff_v < 0) ? (diff_v > -1 * (
int
)v_thresh_)
57
: (diff_v < (
int
)v_thresh_)
58
#endif
59
) {
60
return
C_BLACK;
61
}
else
{
62
return
C_OTHER;
63
}
64
}
65
66
const
char
*
67
ColorModelBlack::get_name
()
68
{
69
return
"ColorModelBlack"
;
70
}
71
72
}
// end namespace firevision
firevision::ColorModelBlack::ColorModelBlack
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.
Definition:
thresholds_black.cpp:36
firevision::ColorModelBlack::determine
color_t determine(unsigned int y, unsigned int u, unsigned int v) const
Definition:
thresholds_black.cpp:46
firevision::ColorModelBlack::get_name
const char * get_name()
Definition:
thresholds_black.cpp:67
src
libs
fvmodels
color
thresholds_black.cpp
Generated by
1.8.16