29constexpr float kFloatEpsilon = std::numeric_limits<float>::epsilon();
52ObjectTemplateManager::ObjectTemplateManager() {}
60 nr_dim_per_tmplt_ = 3;
65 AERROR <<
"Read config failed: " << config_file;
69 ACHECK(proto.has_max_dim_change_ratio());
71 ACHECK(proto.has_unknown());
72 ACHECK(proto.has_unknown_movable());
73 ACHECK(proto.has_unknown_unmovable());
78 ACHECK(proto.has_cyclist());
79 ACHECK(proto.has_motorcyclist());
80 ACHECK(proto.has_tricyclist());
81 ACHECK(proto.has_pedestrian());
82 ACHECK(proto.has_trafficcone());
84 CHECK_LE(proto.
car().dim_size(), 3);
85 CHECK_LE(proto.
van().dim_size(), 3);
86 CHECK_LE(proto.
truck().dim_size(), 3);
87 CHECK_LE(proto.
bus().dim_size(), 3);
88 CHECK_LE(proto.
cyclist().dim_size(), 3);
109 total_nr_tmplts_veh_ = proto.
car().dim_size() + proto.
van().dim_size() +
110 proto.
truck().dim_size() + proto.
bus().dim_size();
112 look_up_table_min_volume_index_.clear();
115 static_cast<int>(veh_hwl_.size());
116 LoadVehTemplates(proto.
car());
118 static_cast<int>(veh_hwl_.size());
119 LoadVehTemplates(proto.
van());
121 static_cast<int>(veh_hwl_.size());
122 LoadVehTemplates(proto.
truck());
124 static_cast<int>(veh_hwl_.size());
125 LoadVehTemplates(proto.
bus());
127 min_template_hwl_.clear();
128 mid_template_hwl_.clear();
129 max_template_hwl_.clear();
144 template_hwl_.resize(0);
145 template_hwl_.push_back(min_template_hwl_);
146 template_hwl_.push_back(mid_template_hwl_);
147 template_hwl_.push_back(max_template_hwl_);
149 type_speed_limit_.clear();
176 AINFO <<
"Init object_template_manager success.";
180void ObjectTemplateManager::LoadVehTemplates(
const ObjectTemplate &tmplt) {
181 std::vector<std::tuple<float, float, float>> list_tpl;
183 for (
int i = 0; i < tmplt.dim_size(); ++i) {
185 list_tpl.push_back(std::make_tuple(dim.h(), dim.w(), dim.l()));
187 std::sort(list_tpl.begin(), list_tpl.end());
188 for (
size_t i = 0; i < list_tpl.size(); ++i) {
189 veh_hwl_.push_back(std::get<0>(list_tpl[i]));
190 veh_hwl_.push_back(std::get<1>(list_tpl[i]));
191 veh_hwl_.push_back(std::get<2>(list_tpl[i]));
195void ObjectTemplateManager::LoadVehMinMidMaxTemplates(
197 std::vector<std::tuple<float, float, float>> list_tpl;
199 for (
int i = 0; i < tmplt.dim_size(); ++i) {
200 Dim dim = tmplt.dim(i);
201 list_tpl.push_back(std::make_tuple(dim.h(), dim.w(), dim.l()));
204 std::sort(list_tpl.begin(), list_tpl.end());
207 int ind_max =
static_cast<int>(list_tpl.size()) - 1;
208 int ind_mid = (ind_min + ind_max) / 2;
209 std::vector<float> tmplt_min = {std::get<0>(list_tpl[ind_min]),
210 std::get<1>(list_tpl[ind_min]),
211 std::get<2>(list_tpl[ind_min])};
212 std::vector<float> tmplt_mid = {std::get<0>(list_tpl[ind_mid]),
213 std::get<1>(list_tpl[ind_mid]),
214 std::get<2>(list_tpl[ind_mid])};
215 std::vector<float> tmplt_max = {std::get<0>(list_tpl[ind_max]),
216 std::get<1>(list_tpl[ind_max]),
217 std::get<2>(list_tpl[ind_max])};
218 min_template_hwl_[type] = tmplt_min;
219 mid_template_hwl_[type] = tmplt_mid;
220 max_template_hwl_[type] = tmplt_max;
224float ObjectTemplateManager::Get3dDimensionSimilarity(
const float *hwl1,
229 float max_h = std::max(hwl1[0], hwl2[0]);
230 float min_h = hwl1[0] + hwl2[0] - max_h;
231 float max_w = std::max(hwl1[1], hwl2[1]);
232 float min_w = hwl1[1] + hwl2[1] - max_w;
233 float max_l = std::max(hwl1[2], hwl2[2]);
234 float min_l = hwl1[2] + hwl2[2] - max_l;
240 return iou_h * iou_h * iou_w * iou_l;
249 float hwl_flip[3] = {hwl[0], hwl[2], hwl[1]};
250 float score_best = -std::numeric_limits<float>::max();
253 bool from_flip =
false;
254 for (
int i = 0; i < total_nr_tmplts_veh_; ++i) {
255 float score = Get3dDimensionSimilarity(hwl, &veh_hwl_[i3]);
256 float score_flip = Get3dDimensionSimilarity(hwl_flip, &veh_hwl_[i3]);
257 bool from_flip_cur =
false;
258 if (score_flip > score) {
260 from_flip_cur =
true;
262 if (score > score_best) {
265 from_flip = from_flip_cur;
269 int i_best_by_3 = i_best * 3;
270 float hwl_tmplt_matched[3] = {veh_hwl_[i_best_by_3],
271 veh_hwl_[i_best_by_3 + 1],
272 veh_hwl_[i_best_by_3 + 2]};
274 std::swap(hwl_tmplt_matched[1], hwl_tmplt_matched[2]);
277 float dh = fabsf(hwl[0] - hwl_tmplt_matched[0]);
278 float dh_ratio = dh / hwl_tmplt_matched[0];
279 float dw = fabsf(hwl[1] - hwl_tmplt_matched[1]);
280 float dw_ratio = dw / hwl_tmplt_matched[1];
281 float dl = fabsf(hwl[2] - hwl_tmplt_matched[2]);
282 float dl_ratio = dl / hwl_tmplt_matched[2];
283 float dh_dw_dl_ratio_mean = (dh_ratio + dw_ratio + dl_ratio) / 3;
284 float dh_ratio_check = std::min(dh_ratio, dh_dw_dl_ratio_mean);
285 if (score_best < kFloatEpsilon || dh_ratio_check > max_dim_change_ratio_) {
288 ADEBUG << dh_ratio <<
", " << dw_ratio <<
", " << dl_ratio;
290 hwl[0] = veh_hwl_[i_best_by_3];
291 hwl[1] = veh_hwl_[i_best_by_3 + 1];
292 hwl[2] = veh_hwl_[i_best_by_3 + 2];
293 if (index !=
nullptr) {
296 if (is_flip !=
nullptr) {
297 *is_flip = from_flip;
float VehObjHwlBySearchTemplates(float *hwl, int *index=nullptr, bool *is_flip=nullptr)
bool GetProtoFromFile(const std::string &file_name, google::protobuf::Message *message)
Parses the content of the file specified by the file_name as a representation of protobufs,...
std::vector< base::ObjectSubType > kTypeRefinedByTemplate
std::vector< base::ObjectSubType > kTypeCanBeRef
std::vector< base::ObjectSubType > kTypeRefinedByRef
std::string GetCommonConfigFile(const std::string &config_file)
Get the perception common config path
constexpr float kFloatEpsilon
optional float speed_limit