-
Notifications
You must be signed in to change notification settings - Fork 104
/
plugin_detect_robots.cpp
156 lines (129 loc) · 5.81 KB
/
plugin_detect_robots.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
//========================================================================
// This software is free: you can redistribute it and/or modify
// it under the terms of the GNU General Public License Version 3,
// as published by the Free Software Foundation.
//
// This software is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// Version 3 in the file COPYING that came with this distribution.
// If not, see <http://www.gnu.org/licenses/>.
//========================================================================
/*!
\file plugin_detect_robots.cpp
\brief C++ Implementation: plugin_detect_robots
\author Author Name, 2009
*/
//========================================================================
#include "plugin_detect_robots.h"
PluginDetectRobots::PluginDetectRobots(FrameBuffer * _buffer, LUT3D * lut, const CameraParameters& camera_params, const RoboCupField& field, CMPattern::TeamSelector * _global_team_selector_blue, CMPattern::TeamSelector * _global_team_selector_yellow, CMPattern::TeamDetectorSettings * _global_team_settings)
: VisionPlugin(_buffer), camera_parameters(camera_params), field(field)
{
_lut=lut;
color_id_yellow = _lut->getChannelID("Yellow");
if (color_id_yellow == -1) printf("WARNING color label 'Yellow' not defined in LUT!!!\n");
color_id_blue = _lut->getChannelID("Blue");
if (color_id_yellow == -1) printf("WARNING color label 'Blue' not defined in LUT!!!\n");
color_id_clear = 0;
color_id_ball = _lut->getChannelID("Orange");
if (color_id_ball == -1) printf("WARNING color label 'Orange' not defined in LUT!!!\n");
color_id_black = _lut->getChannelID("Black");
if (color_id_black == -1) printf("WARNING color label 'Black' not defined in LUT!!!\n");
color_id_field = _lut->getChannelID("Field Green");
if (color_id_field == -1) printf("WARNING color label 'Field Green' not defined in LUT!!!\n");
global_team_selector_blue=_global_team_selector_blue;
global_team_selector_yellow=_global_team_selector_yellow;
global_team_detector_settings=_global_team_settings;
team_detector_blue=new CMPattern::TeamDetector(_lut,camera_params,field);
team_detector_yellow=new CMPattern::TeamDetector(_lut,camera_params,field);
_settings=new VarList("Robot Detection");
_notifier.addRecursive(_settings);
connect(_global_team_selector_blue,SIGNAL(signalTeamDataChanged()),&_notifier,SLOT(changeSlotOtherChange()));
connect(_global_team_selector_yellow,SIGNAL(signalTeamDataChanged()),&_notifier,SLOT(changeSlotOtherChange()));
connect(_global_team_settings,SIGNAL(signalTeamDataChanged()),&_notifier,SLOT(changeSlotOtherChange()));
}
PluginDetectRobots::~PluginDetectRobots()
{
}
VarList * PluginDetectRobots::getSettings() {
return _settings;
}
string PluginDetectRobots::getName() {
return "DetectRobots";
}
void PluginDetectRobots::buildRegionTree(CMVision::ColorRegionList * colorlist) {
reg_tree.clear();
int num_colors=colorlist->getNumColorRegions();
for(int c=0;c<num_colors;c++) {
//ONLY ADD ROBOT MARKER COLORS:
if (c!= color_id_clear && c!=color_id_field && c!= color_id_ball && c!= color_id_black) {
CMVision::Region *reg = colorlist->getRegionList(c).getInitialElement();
while(reg!=0) {
reg_tree.add(reg);
reg = reg->next;
}
}
}
reg_tree.build();
}
ProcessResult PluginDetectRobots::process(FrameData * data, RenderOptions * options)
{
(void)options;
if (data==0) return ProcessingFailed;
SSL_DetectionFrame * detection_frame = 0;
detection_frame=(SSL_DetectionFrame *)data->map.get("ssl_detection_frame");
if (detection_frame == 0) detection_frame=(SSL_DetectionFrame *)data->map.insert("ssl_detection_frame",new SSL_DetectionFrame());
//acquire orange region list from data-map:
CMVision::ColorRegionList * colorlist;
colorlist=(CMVision::ColorRegionList *)data->map.get("cmv_colorlist");
if (colorlist==0) {
printf("error in robot detection plugin: no region-lists were found!\n");
return ProcessingFailed;
}
//acquire color-labeled image from data-map:
const Image<raw8> * image = (Image<raw8> *)(data->map.get("cmv_threshold"));
if (image==0) {
printf("error in robot detection plugin: no color-thresholded image was found!\n");
return ProcessingFailed;
}
CMPattern::Team * team=0;
::google::protobuf::RepeatedPtrField< ::SSL_DetectionRobot >* robotlist=0;
int color_id;
int num_robots;
CMPattern::TeamDetector * detector;
//TODO: lookup color label from LUT
buildRegionTree(colorlist);
bool need_reinit=_notifier.hasChanged();
for (int team_i = 0; team_i < 2; team_i++) {
//team_i: 0==blue, 1==yellow
if (team_i==0) {
color_id=color_id_blue;
team=global_team_selector_blue->getSelectedTeam();
num_robots=global_team_selector_blue->getNumberRobots();
detection_frame->clear_robots_blue();
robotlist=detection_frame->mutable_robots_blue();
detector=team_detector_blue;
} else {
color_id=color_id_yellow;
team=global_team_selector_yellow->getSelectedTeam();
num_robots=global_team_selector_yellow->getNumberRobots();
detection_frame->clear_robots_yellow();
robotlist=detection_frame->mutable_robots_yellow();
detector=team_detector_yellow;
}
if (team!=0) {
if (need_reinit) {
detector->init(global_team_detector_settings->getRobotPattern(), team);
}
detector->update(robotlist, color_id, num_robots, image, colorlist, reg_tree);
} else {
_notifier.changeSlotOtherChange();
}
// printf("DETECTED %d robots on team %d\n",robotlist->size(),team_i);
// fflush(stdout);
}
return ProcessingOk;
}