39 memcpy(hwl, options.
hwl,
sizeof(
float) * 3);
41 memcpy(bbox, options.
bbox,
sizeof(
float) * 4);
46 AdjustCenterWithGround(bbox, hwl, *ry, options.
plane, center);
52 bool adjust_hard = PostRefineCenterWithGroundBoundary(
56 return adjust_soft || adjust_hard;
65bool ObjPostProcessor::AdjustCenterWithGround(
const float *bbox,
66 const float *hwl,
float ry,
68 float *center)
const {
69 float iou_ini = GetProjectionScore(ry, bbox, hwl, center);
74 const float EPS_COST_DELTA = 1e-1f;
79 float cost_pre = std::numeric_limits<float>::max();
80 float cost_delta = 0.0f;
81 float center_input[3] = {center[0], center[1], center[2]};
82 float center_test[3] = {0};
93 x, k_mat_, plane, center_test);
95 memcpy(center, center_input,
sizeof(
float) * 3);
98 float iou_cur = GetProjectionScore(ry, bbox, hwl, center);
99 float iou_test = GetProjectionScore(ry, bbox, hwl, center_test);
102 float cost_cur = dist + WEIGHT_IOU * (1.0f - (iou_cur + iou_test) / 2);
104 if (cost_cur >= cost_pre) {
107 cost_delta = (cost_pre - cost_cur) / cost_pre;
109 center[0] += (center_test[0] - center[0]) * lr;
110 center[2] += (center_test[2] - center[2]) * lr;
112 stop = iter >= MAX_ITERATION || cost_delta < EPS_COST_DELTA ||
117 float iou_res = GetProjectionScore(ry, bbox, hwl, center);
119 memcpy(center, center_input,
sizeof(
float) * 3);
125bool ObjPostProcessor::PostRefineCenterWithGroundBoundary(
126 const float *bbox,
const float *hwl,
float ry,
const float *plane,
127 const std::vector<LineSegment2D<float>> &line_seg_limits,
float *center,
128 bool check_lowerbound)
const {
129 bool truncated_on_bottom =
130 bbox[3] >=
static_cast<float>(height_) -
132 if (truncated_on_bottom) {
136 float iou_before = GetProjectionScore(ry, bbox, hwl, center);
137 int nr_line_segs =
static_cast<int>(line_seg_limits.size());
138 float depth_pts[4] = {0};
139 float pts_c[12] = {0};
142 GetDepthXPair(bbox, hwl, center, ry, depth_pts, x_pts, &pts_c[0]);
144 float dxdz_acc[2] = {0};
146 for (
int i = 0; i < nr_line_segs; ++i) {
149 width_, height_, ratio_x_over_z, dxdz,
151 dxdz_acc[0] += dxdz[0];
152 dxdz_acc[1] += dxdz[1];
154 center[0] += dxdz_acc[0];
155 center[2] += dxdz_acc[1];
157 float iou_after = GetProjectionScore(ry, bbox, hwl, center);
159 center[0] -= dxdz_acc[0];
160 center[2] -= dxdz_acc[1];
166int ObjPostProcessor::GetDepthXPair(
const float *bbox,
const float *hwl,
167 const float *center,
float ry,
168 float *depth_pts,
int *x_pts,
169 float *pts_c)
const {
171 float w_half = hwl[1] / 2;
172 float l_half = hwl[2] / 2;
173 float x_cor[4] = {l_half, l_half, -l_half, -l_half};
174 float z_cor[4] = {w_half, -w_half, -w_half, w_half};
175 float pts[12] = {x_cor[0], 0.0f, z_cor[0], x_cor[1], 0.0f, z_cor[1],
176 x_cor[2], 0.0f, z_cor[2], x_cor[3], 0.0f, z_cor[3]};
179 float pt_proj[3] = {0};
182 bool save_pts_c = pts_c !=
nullptr;
183 for (
int i = 0; i < 4; ++i) {
186 depth_pts[i] = pt_c[2];
189 if (y_proj < y_min) {
195 pts_c[i3 + 1] = pt_c[1];
196 pts_c[i3 + 2] = pt_c[2];
bool PostProcessObjWithGround(const ObjPostProcessorOptions &options, float center[3], float hwl[3], float *ry)
init params
bool PostProcessObjWithDispmap(const ObjPostProcessorOptions &options, float center[3], float hwl[3], float *ry)
none
void IProjectThroughExtrinsic(const T *R, const T *t, const T *X, T *x)
bool IBackprojectPlaneIntersectionCanonical(const T *x, const T *K, const T *pi, T *X)
void IProjectThroughIntrinsic(const T *K, const T *X, T *x)
void GenRotMatrix(const T &ry, T *rot)
void GetDxDzForCenterFromGroundLineSeg(const LineSegment2D< T > &ls, const T *plane, const T *pts_c, const T *k_mat, int width, int height, T ratio_x_over_z, T *dx_dz, bool check_lowerbound=true)
std::vector< LineSegment2D< float > > line_segs