33 std::string config_file =
37 AERROR <<
"Read config failed: " << config_file;
40 AINFO << multicue_param_.DebugString();
50void MultiCueTransformer::SetObjMapperOptions(
56 obj->camera_supplement.box.xmin, obj->camera_supplement.box.ymin,
57 obj->camera_supplement.box.xmax, obj->camera_supplement.box.ymax};
59 bbox2d[0] = std::max(0.0f, bbox2d[0]);
60 bbox2d[1] = std::max(0.0f, bbox2d[1]);
61 bbox2d[2] = std::min(
static_cast<float>(width_image) - 1.0f, bbox2d[2]);
62 bbox2d[3] = std::min(
static_cast<float>(height_image) - 1.0f, bbox2d[3]);
63 bbox2d[2] = std::max(bbox2d[0] + 1.0f, bbox2d[2]);
64 bbox2d[3] = std::max(bbox2d[1] + 1.0f, bbox2d[3]);
67 float dimension_hwl[3] = {obj->size(2), obj->size(1), obj->size(0)};
70 float box_cent_x = (bbox2d[0] + bbox2d[2]) / 2;
71 Eigen::Vector3f image_point_low_center(box_cent_x, bbox2d[3], 1);
72 Eigen::Vector3f point_in_camera =
73 static_cast<Eigen::Matrix<float, 3, 1, 0, 3, 1>
>(
74 camera_k_matrix.inverse() * image_point_low_center);
76 static_cast<float>(atan2(point_in_camera.x(), point_in_camera.z()));
78 *theta_ray +
static_cast<float>(obj->camera_supplement.alpha);
82 const float PI = algorithm::Constant<float>::PI();
83 if (rotation_y < -
PI) {
85 }
else if (rotation_y >=
PI) {
89 memcpy(obj_mapper_options->
bbox, bbox2d,
sizeof(
float) * 4);
90 memcpy(obj_mapper_options->
hwl, dimension_hwl,
sizeof(
float) * 3);
91 obj_mapper_options->
ry = rotation_y;
95 MatchTemplates(sub_type, dimension_hwl);
97 ADEBUG <<
"#2D-to-3D for one obj:";
98 ADEBUG <<
"Obj pred ry:" << rotation_y;
99 ADEBUG <<
"Obj pred type: " <<
static_cast<int>(sub_type);
100 ADEBUG <<
"Bbox: " << bbox2d[0] <<
", " << bbox2d[1] <<
", " << bbox2d[2]
101 <<
", " << bbox2d[3];
105 float *dimension_hwl) {
113 int type_min_vol_index = 0;
114 float min_dimension_val =
115 std::min(std::min(dimension_hwl[0], dimension_hwl[1]), dimension_hwl[2]);
117 const std::map<TemplateIndex, int> &kLookUpTableMinVolumeIndex =
122 const float *min_tmplt_cur_type = kMinTemplateHWL.at(sub_type).data();
123 const float *max_tmplt_cur_type = kMaxTemplateHWL.at(sub_type).data();
124 dimension_hwl[0] = std::min(dimension_hwl[0], max_tmplt_cur_type[0]);
125 dimension_hwl[0] = std::max(dimension_hwl[0], min_tmplt_cur_type[0]);
131 const float *min_tmplt_cur_type = kMinTemplateHWL.at(sub_type).data();
132 const float *mid_tmplt_cur_type = kMidTemplateHWL.at(sub_type).data();
133 const float *max_tmplt_cur_type = kMaxTemplateHWL.at(sub_type).data();
134 float dh_min = fabsf(dimension_hwl[0] - min_tmplt_cur_type[0]);
135 float dh_mid = fabsf(dimension_hwl[0] - mid_tmplt_cur_type[0]);
136 float dh_max = fabsf(dimension_hwl[0] - max_tmplt_cur_type[0]);
137 std::vector<std::pair<float, float>> diff_hs;
138 diff_hs.push_back(std::make_pair(dh_min, min_tmplt_cur_type[0]));
139 diff_hs.push_back(std::make_pair(dh_mid, mid_tmplt_cur_type[0]));
140 diff_hs.push_back(std::make_pair(dh_max, max_tmplt_cur_type[0]));
141 std::sort(diff_hs.begin(), diff_hs.end(),
142 [](
const std::pair<float, float> &a,
143 const std::pair<float, float> &b) ->
bool {
144 return a.first < b.first;
146 dimension_hwl[0] = diff_hs[0].second;
173 return type_min_vol_index;
176void MultiCueTransformer::FillResults(
float object_center[3],
177 float dimension_hwl[3],
float rotation_y,
178 const Eigen::Affine3d &camera2world_pose,
180 if (obj ==
nullptr) {
183 object_center[1] -= dimension_hwl[0] / 2;
184 obj->camera_supplement.local_center(0) = object_center[0];
185 obj->camera_supplement.local_center(1) = object_center[1];
186 obj->camera_supplement.local_center(2) = object_center[2];
187 ADEBUG <<
"Obj id: " << obj->track_id;
188 ADEBUG <<
"Obj type: " <<
static_cast<int>(obj->sub_type);
189 ADEBUG <<
"Obj ori dimension: " << obj->size[2] <<
", " << obj->size[1]
190 <<
", " << obj->size[0];
191 obj->center(0) =
static_cast<double>(object_center[0]);
192 obj->center(1) =
static_cast<double>(object_center[1]);
193 obj->center(2) =
static_cast<double>(object_center[2]);
194 obj->center = camera2world_pose * obj->center;
196 obj->size(2) = dimension_hwl[0];
197 obj->size(1) = dimension_hwl[1];
198 obj->size(0) = dimension_hwl[2];
200 Eigen::Matrix3d pos_var = mapper_->get_position_uncertainty();
201 obj->center_uncertainty(0) =
static_cast<float>(pos_var(0));
202 obj->center_uncertainty(1) =
static_cast<float>(pos_var(1));
203 obj->center_uncertainty(2) =
static_cast<float>(pos_var(2));
205 float theta = rotation_y;
206 Eigen::Vector3d dir = (camera2world_pose.matrix().block(0, 0, 3, 3) *
207 Eigen::Vector3d(
cos(theta), 0, -
sin(theta)));
208 obj->direction[0] =
static_cast<float>(dir[0]);
209 obj->direction[1] =
static_cast<float>(dir[1]);
210 obj->direction[2] =
static_cast<float>(dir[2]);
211 obj->theta =
static_cast<float>(atan2(dir[1], dir[0]));
212 obj->theta_variance =
static_cast<float>((mapper_->get_orientation_var())(0));
214 obj->camera_supplement.alpha = rotation_y - theta_ray;
216 ADEBUG <<
"Dimension hwl: " << dimension_hwl[0] <<
", " << dimension_hwl[1]
217 <<
", " << dimension_hwl[2];
218 ADEBUG <<
"Obj ry:" << rotation_y;
219 ADEBUG <<
"Obj theta: " << obj->theta;
220 ADEBUG <<
"Obj center from transformer: " << obj->center.transpose();
225 ADEBUG <<
"No object input to transformer.";
230 float k_mat[9] = {0};
231 for (
size_t i = 0; i < 3; ++i) {
232 for (
size_t j = 0; j < 3; ++j) {
233 k_mat[i * 3 + j] = camera_k_matrix(i, j);
236 ADEBUG <<
"Camera k matrix input to transformer: \n"
237 << k_mat[0] <<
", " << k_mat[1] <<
", " << k_mat[2] <<
"\n"
238 << k_mat[3] <<
", " << k_mat[4] <<
", " << k_mat[5] <<
"\n"
239 << k_mat[6] <<
", " << k_mat[7] <<
", " << k_mat[8] <<
"\n";
244 mapper_->Init(k_mat, width_image, height_image);
247 float object_center[3] = {0};
248 float dimension_hwl[3] = {0};
249 float rotation_y = 0.0f;
250 int nr_transformed_obj = 0;
253 if (obj ==
nullptr) {
254 ADEBUG <<
"Empty object input to transformer.";
259 float theta_ray = 0.0f;
260 SetObjMapperOptions(obj, camera_k_matrix, width_image, height_image,
261 &obj_mapper_options, &theta_ray);
264 mapper_->Solve3dBbox(obj_mapper_options, object_center, dimension_hwl,
268 FillResults(object_center, dimension_hwl, rotation_y, camera2world_pose,
271 ++nr_transformed_obj;
274 return nr_transformed_obj > 0;
const std::map< TemplateIndex, int > & LookUpTableMinVolumeIndex()
const TemplateMap & MinTemplateHWL()
const TemplateMap & MaxTemplateHWL()
const TemplateMap & MidTemplateHWL()
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,...
void IScale3(T x[3], T sf)
std::shared_ptr< Object > ObjectPtr
std::map< base::ObjectSubType, std::vector< float > > TemplateMap
std::string GetConfigFile(const std::string &config_path, const std::string &config_file)
optional bool check_dimension
optional float min_dimension_val
std::vector< base::ObjectPtr > detected_objects
Eigen::Matrix3f camera_k_matrix
Eigen::Affine3d camera2world_pose
std::shared_ptr< camera::DataProvider > data_provider