|
|
@@ -372,13 +372,6 @@ bool detect_wheel_ceres::detect(std::vector<pcl::PointCloud<pcl::PointXYZ>::Ptr>
|
|
|
|
|
|
}
|
|
|
|
|
|
- // // 仅优化一次,不调整图像比例与角度初值。
|
|
|
- // detect_result.cx=center_x;
|
|
|
- // detect_result.cy=center_y;
|
|
|
- // detect_result.theta=-angle_x*M_PI/180.0;
|
|
|
- // Loss_result one_shot_loss_result;
|
|
|
- // return Solve(detect_result, one_shot_loss_result);
|
|
|
-
|
|
|
// 多次优化,获取最佳优化结果
|
|
|
detect_result.cx=center_x;
|
|
|
detect_result.cy=center_y;
|
|
|
@@ -397,13 +390,7 @@ bool detect_wheel_ceres::detect(std::vector<pcl::PointCloud<pcl::PointXYZ>::Ptr>
|
|
|
bool solve_result = false;
|
|
|
double total_solve_time = 0;
|
|
|
bool stop_sign = false;
|
|
|
- // for (int j = 2; j < 4&&!stop_sign; j++)
|
|
|
- // {
|
|
|
- // // double input_vars[] = {detect_result.cx, detect_result.cy, detect_result.theta, detect_result.wheel_base, detect_result.width, detect_result.front_theta};
|
|
|
- // double map_rows = map_cols * 1.0 / j ;
|
|
|
- // update_mat(map_rows, map_cols);
|
|
|
|
|
|
- // !!! 将车轮比例添加到优化模型中
|
|
|
Detect_result t_detect_result = detect_result;
|
|
|
// 寻找最小loss值对应的初始旋转角
|
|
|
for (int i = -3; i < 4&&!stop_sign; i+=6)
|
|
|
@@ -415,7 +402,6 @@ bool detect_wheel_ceres::detect(std::vector<pcl::PointCloud<pcl::PointXYZ>::Ptr>
|
|
|
//输出角度已变化,需恢复成弧度
|
|
|
if(calc_count > 0)
|
|
|
{
|
|
|
- // t_detect_result.theta *= (-M_PI) / 180.0;
|
|
|
t_detect_result.front_theta *= (-M_PI) / 180.0;
|
|
|
}
|
|
|
std::string t_error_info;
|
|
|
@@ -435,34 +421,37 @@ bool detect_wheel_ceres::detect(std::vector<pcl::PointCloud<pcl::PointXYZ>::Ptr>
|
|
|
loss_result = t_loss_result;
|
|
|
// optimized_map_rows = map_rows;
|
|
|
calc_count++;
|
|
|
- // // 新增,优化时间足够长则认为已找到正确结果
|
|
|
- // if(second > 0.02)
|
|
|
- // {
|
|
|
- // stop_sign = true;
|
|
|
- // break;
|
|
|
- // }
|
|
|
+
|
|
|
}
|
|
|
}
|
|
|
- // }
|
|
|
- // std::cout<<"solve time "<<total_solve_time<<std::endl;
|
|
|
- // LOG(INFO) << "final avg cost for four wheels: "<<whole_loss[0]<<" "<<whole_loss[1]<<" "<<whole_loss[2]<<" "<<whole_loss[3]<<" ";
|
|
|
-
|
|
|
-// if(solve_result)
|
|
|
-// printf("final avg cost for four wheels: %7.6f %7.6f %7.6f %7.6f---%7.6f\n", loss_result.lf_loss, loss_result.rf_loss, loss_result.lb_loss, loss_result.rb_loss, loss_result.total_avg_loss);
|
|
|
-
|
|
|
- // // 生成并保存图片
|
|
|
- // update_mat(optimized_map_rows, map_cols);
|
|
|
- // Detect_result t_detect_result = detect_result;
|
|
|
- // t_detect_result.theta *= (-M_PI) / 180.0;
|
|
|
- // t_detect_result.front_theta *= (-M_PI) / 180.0;
|
|
|
- // Loss_result t_loss_result;
|
|
|
- // // LOG(INFO) <<"going to show img ";
|
|
|
- // Solve(detect_result, t_loss_result, true);
|
|
|
-
|
|
|
-// printf(" x:%.3f y: %.3f wheel:%.3f width:%.3f theta : %.3f front theta: %.3f\n",
|
|
|
-// detect_result.cx,detect_result.cy,detect_result.wheel_base,detect_result.width,detect_result.theta,detect_result.front_theta);
|
|
|
+
|
|
|
if(solve_result)
|
|
|
- error_info="";
|
|
|
+ {
|
|
|
+ error_info = "";
|
|
|
+ //按照车身角,旋转后轮, 计算车宽
|
|
|
+ pcl::PointCloud<pcl::PointXYZ>::Ptr rear_cloud(new pcl::PointCloud<pcl::PointXYZ>);
|
|
|
+ *rear_cloud+=m_left_rear_cloud;
|
|
|
+ *rear_cloud+=m_right_rear_cloud;
|
|
|
+ if(rear_cloud->size()>0)
|
|
|
+ {
|
|
|
+ double body_theta = detect_result.theta / 180.0 * M_PI;
|
|
|
+ Eigen::Vector2d vec(sin(body_theta), cos(body_theta));
|
|
|
+
|
|
|
+ double dot_min = 9999999., dot_max = -9999999.9;
|
|
|
+ for (int i = 0; i < rear_cloud->size(); ++i)
|
|
|
+ {
|
|
|
+ pcl::PointXYZ pt = rear_cloud->points[i];
|
|
|
+ double dot = pt.x * vec[0] + pt.y * vec[1];
|
|
|
+ if (dot > dot_max)
|
|
|
+ dot_max = dot;
|
|
|
+ if (dot < dot_min)
|
|
|
+ dot_min = dot;
|
|
|
+ }
|
|
|
+ detect_result.body_width=fabs(dot_max-dot_min);
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
return solve_result;
|
|
|
|
|
|
}
|
|
|
@@ -686,21 +675,18 @@ bool detect_wheel_ceres::Solve(Detect_result &detect_result, Loss_result &loss_r
|
|
|
return false;
|
|
|
}
|
|
|
|
|
|
- detect_result.width += 0.22; //车宽一边+11cm
|
|
|
-// printf(" x:%.3f y: %.3f wheel:%.3f width:%.3f theta : %.3f front theta: %.3f\n",
|
|
|
-// detect_result.cx,detect_result.cy,detect_result.wheel_base,detect_result.width,detect_result.theta,detect_result.front_theta);
|
|
|
+ // detect_result.width += 0.22; //车宽一边+11cm
|
|
|
|
|
|
// //added by yct
|
|
|
if(detect_result.theta > 120 || detect_result.theta < 60)
|
|
|
{
|
|
|
- error_info.append("总角度错误 ").append(std::to_string(detect_result.theta)).append("\t");
|
|
|
+ error_info.append("车身角度错误 ").append(std::to_string(detect_result.theta)).append("\t");
|
|
|
// LOG(WARNING) <<"总角度错误 "<<detect_result.theta;
|
|
|
return false;
|
|
|
}
|
|
|
if(fabs(detect_result.front_theta)>35)
|
|
|
{
|
|
|
error_info.append("前轮角度错误 ").append(std::to_string(detect_result.front_theta)).append("\t");
|
|
|
-// LOG(WARNING) <<"前轮角度错误 "<<detect_result.front_theta;
|
|
|
return false;
|
|
|
}
|
|
|
// 将loss传出
|
|
|
@@ -732,8 +718,6 @@ bool detect_wheel_ceres::Solve(Detect_result &detect_result, Loss_result &loss_r
|
|
|
.append(std::to_string(loss_result.rf_loss)).append(", ")
|
|
|
.append(std::to_string(loss_result.lb_loss)).append(", ")
|
|
|
.append(std::to_string(loss_result.rb_loss)).append("\t");
|
|
|
-// LOG(WARNING)<<error_info;
|
|
|
-// LOG(WARNING) <<"四轮loss过大"<<loss_result.lf_loss<<", "<<loss_result.rf_loss<<", "<<loss_result.lb_loss<<", "<<loss_result.rb_loss;
|
|
|
return false;
|
|
|
}
|
|
|
//std::cout<<"save img: "<<save_img<<std::endl;
|
|
|
@@ -747,7 +731,7 @@ bool detect_wheel_ceres::Solve(Detect_result &detect_result, Loss_result &loss_r
|
|
|
Detect_result t_detect_result = detect_result;
|
|
|
t_detect_result.theta *= -M_PI/180.0;
|
|
|
t_detect_result.front_theta *= -M_PI/180.0;
|
|
|
- t_detect_result.width -= 0.22;
|
|
|
+ //t_detect_result.width -= 0.22;
|
|
|
transform_src(t_detect_result);
|
|
|
|
|
|
|