58 const EigenVector<Target> &targets) {
61 static_cast<int>(img_width_),
62 static_cast<int>(img_height_));
63 auto &ground_estimator = ground_estimator_mapper_[sensor];
65 auto &refs = reference_[sensor];
66 auto &ref_map = ref_map_[sensor];
67 if (ref_map.empty()) {
68 ref_map = init_ref_map_;
70 for (
auto &&reference : refs) {
73 for (
auto &&target : targets) {
74 if (!target.isTracked()) {
77 if (target.isLost()) {
80 auto obj = target[-1]->object;
84 auto &box = obj->camera_supplement.box;
92 if (box.ymax >= img_height_ + 1) {
93 AERROR <<
"box.ymax (" << box.ymax <<
") is larger than img_height_ + 1 ("
94 << img_height_ + 1 <<
")";
97 if (box.xmax >= img_width_ + 1) {
98 AERROR <<
"box.xmax (" << box.xmax <<
") is larger than img_width_ + 1 ("
99 << img_width_ + 1 <<
")";
102 float x = box.Center().x;
105 AINFO <<
"Target: " << target.id
108 static_cast<int>(y /
static_cast<float>(ref_param_.
down_sampling()));
110 static_cast<int>(x /
static_cast<float>(ref_param_.
down_sampling()));
111 if (ref_map[y_discrete][x_discrete] == 0) {
115 r.
k = obj->size[2] / (y - box.ymin);
117 ref_map[y_discrete][x_discrete] =
static_cast<int>(refs.size());
118 }
else if (ref_map[y_discrete][x_discrete] > 0) {
119 int index = ref_map[y_discrete][x_discrete] - 1;
120 if (box.Area() > refs[index].area) {
121 refs[index].area = box.Area();
122 refs[index].ymax = y;
123 refs[index].k = obj->size[2] / (y - box.ymin);
129 std::vector<float> vd_samples(
static_cast<int>(refs.size() * 2), 0);
131 for (
auto &&reference : refs) {
133 vd_samples[count_vd++] = reference.ymax;
137 int count_samples =
static_cast<int>(vd_samples.size() / 2);
138 if (count_samples > ground_estimator.get_min_nr_samples() &&
140 ground_estimator.DetetGround(
143 vd_samples.data(), count_samples);
151 const std::vector<TemplateMap> &kTemplateHWL =
155 float volume_object = obj->size[0] * obj->size[1] * obj->size[2];
157 <<
"ori size:" << obj->size.transpose() <<
" "
158 <<
"type: " <<
static_cast<int>(obj->sub_type) <<
" "
159 << volume_object <<
" " << frame->
data_provider->sensor_name();
164 float min_template_volume = 0.0f;
165 float max_template_volume = 0.0f;
166 auto min_tmplt = kMinTemplateHWL.at(obj->sub_type);
167 auto max_tmplt = kMaxTemplateHWL.at(obj->sub_type);
168 min_template_volume = min_tmplt[0] * min_tmplt[1] * min_tmplt[2];
169 max_template_volume = max_tmplt[0] * max_tmplt[1] * max_tmplt[2];
170 if (volume_object < min_template_volume ||
172 obj->size[0] = min_tmplt[2];
173 obj->size[1] = min_tmplt[1];
174 obj->size[2] = min_tmplt[0];
175 }
else if (volume_object > max_template_volume ||
178 obj->size[0] = max_tmplt[2];
179 obj->size[1] = max_tmplt[1];
180 obj->size[2] = max_tmplt[0];
186 std::vector<float> height;
193 static_cast<int>(img_width_),
194 static_cast<int>(img_height_));
195 auto &ground_estimator = ground_estimator_mapper_[sensor];
197 if (ground_estimator.GetGroundModel(l)) {
198 double z_ground_reversed =
201 z_ground = std::max(z_ground, z_obj);
202 float k2 =
static_cast<float>(z_ground / frame->
camera_k_matrix(1, 1));
204 h = std::max(std::min(h, kMaxTemplateHWL.at(obj->sub_type).at(0)),
205 kMinTemplateHWL.at(obj->sub_type).at(0));
211 double z_calib = 0.0;
214 static_cast<int>(supplement.
box.
ymax), &z_calib);
216 z_calib = std::max(z_calib, z_obj);
219 h = std::max(std::min(h, kMaxTemplateHWL.at(obj->sub_type).at(0)),
220 kMinTemplateHWL.at(obj->sub_type).at(0));
223 height.push_back(kMaxTemplateHWL.at(obj->sub_type).at(0));
225 Eigen::Vector4d plane_param;
233 cy = std::min(supplement.
box.
ymax - 1, cy);
234 for (
auto &&reference : reference_[sensor]) {
236 float dy = std::abs(reference.ymax - supplement.
box.
ymax);
237 float scale_y = (supplement.
box.
ymax - cy) / (img_height_ - cy);
239 std::max(
static_cast<float>(ref_param_.
down_sampling()) * scale_y,
240 static_cast<float>(ref_param_.
margin()) * 2.0f);
242 float k2 = reference.k;
243 k2 *= (reference.ymax - cy) / (supplement.
box.
ymax - cy);
246 h = std::max(std::min(h, kMaxTemplateHWL.at(obj->sub_type).at(0)),
247 kMinTemplateHWL.at(obj->sub_type).at(0));
251 height.push_back(obj->size[2]);
254 if (height.empty()) {
255 AERROR <<
"height vector is empty";
258 std::sort(height.begin(), height.end());
259 int nr_hs =
static_cast<int>(height.size());
260 float h_updated = height[nr_hs / 2];
261 AINFO <<
"Estimate " << h_updated <<
" with " << height.size();
263 std::min(h_updated, kMaxTemplateHWL.at(obj->sub_type).at(0));
265 std::max(obj->size[2], kMinTemplateHWL.at(obj->sub_type).at(0));
266 std::vector<float> height_error(kTemplateHWL.size(), 0);
268 float obj_h = obj->size[2];
269 for (
size_t i = 0; i < height_error.size(); ++i) {
271 std::abs(kTemplateHWL[i].at(obj->sub_type).at(0) - obj_h);
274 std::min_element(height_error.begin(), height_error.end());
275 auto min_index = std::distance(height_error.begin(), min_error);
276 auto &tmplt = kTemplateHWL.at(min_index).at(obj->sub_type);
277 float scale_factor = obj->size[2] / tmplt[0];
278 obj->size[1] = tmplt[1] * scale_factor;
279 obj->size[0] = tmplt[2] * scale_factor;
281 ADEBUG <<
"correct size:" << obj->size.transpose();