12 void Distinguisher::distingishColor()
16 std::int8_t black_threthold = 10;
17 std::int8_t white_threthold = 40;
19 judgement(RED, min_distance);
20 judgement(AltRED, min_distance);
21 judgement(BLUE, min_distance);
22 judgement(YELLOW, min_distance);
23 judgement(GREEN, min_distance);
24 judgement(GREY, min_distance);
25 judgement(BLACK, min_distance);
26 judgement(WHITE, min_distance);
36 if(
hsv.
v < black_threthold) {
38 }
else if(
hsv.
v > white_threthold) {
43 void Distinguisher::judgement(
const Hsv& hsv_,
double& min)
45 double tmp = distanceColor(hsv_);
53 double Distinguisher::distanceColor(
Hsv target_color)
55 std::uint16_t pow_h = std::pow(
hsv.
h - target_color.
h, 2);
56 std::uint16_t pow_s = std::pow(
hsv.
s - target_color.
s, 2);
57 std::uint16_t pow_v = std::pow(
hsv.
v - target_color.
v, 2);
58 return std::sqrt(pow_h + pow_s + pow_v);
61 void Distinguisher::setRawColor2Rgb()
63 std::uint32_t total_r, total_g, total_b;
64 std::int8_t times = 10;
66 total_r = total_g = total_b = 0;
67 for(
int i = 0; i < times; i++) {
73 rgb.
r = total_r / times;
74 rgb.
g = total_g / times;
75 rgb.
b = total_b / times;
78 void Distinguisher::convertRgbToHsv(
Rgb rgb_)
80 double max = std::max((std::max(rgb_.
r, rgb_.
g)), rgb_.
b);
81 double min = std::min((std::min(rgb_.
r, rgb_.
g)), rgb_.
b);
82 hsv.
v = max / 256 * 100;
89 hsv.
h = 60.0 * (rgb_.
g - rgb_.
b) / (max - min) + 0;
90 else if(max == rgb_.
g)
91 hsv.
h = 60.0 * (rgb_.
b - rgb_.
r) / (max - min) + 120.0;
92 else if(max == rgb_.
b)
93 hsv.
h = 60.0 * (rgb_.
r - rgb_.
g) / (max - min) + 240.0;
97 }
else if(
hsv.
h < 0) {
100 hsv.
s = (max - min) / max * 100.0;
void getRawColor(uint16_t &r, uint16_t &g, uint16_t &b)
double threshold_distance
走行体のカラーセンサを用いて、RGB情報より色を推定するクラス。