|
@@ -74,6 +74,13 @@ public:
|
|
|
T length = variable[3];
|
|
|
T width = variable[4];
|
|
|
T theta_front = variable[5];
|
|
|
+ T theta_front_weight = T(0.006);
|
|
|
+ T wheel_length_img_ratio = variable[6];
|
|
|
+ T wheel_width_length_ratio = variable[7];
|
|
|
+ // [1/3, 5/3]
|
|
|
+ T limited_wheel_length_img_ratio = T(4.0/5.0) / (T(1) + ceres::exp(T(-wheel_length_img_ratio))) + T(4.0/5.0);
|
|
|
+ // [0.2, 0.8]
|
|
|
+ T limited_wheel_length_ratio = T(0.6) / (T(1) + ceres::exp(T(-wheel_width_length_ratio))) + T(0.2);
|
|
|
|
|
|
//整车旋转
|
|
|
Eigen::Rotation2D<T> rotation(theta);
|
|
@@ -107,11 +114,11 @@ public:
|
|
|
const Eigen::Matrix<T, 2, 1> tanslate_point = rotation_matrix * point - wheel_center_normal_left_front;
|
|
|
//旋转
|
|
|
const Eigen::Matrix<T, 2, 1> point_rotation = rotation_matrix_front * tanslate_point;
|
|
|
- interpolator.Evaluate(point_rotation(1, 0) * m_scale + rows / 2.0 + 0.5 + T(kPadding),
|
|
|
- point_rotation(0, 0) * m_scale + cols / 2.0 + 0.5 + T(kPadding),
|
|
|
+ interpolator.Evaluate(point_rotation(1, 0) * limited_wheel_length_img_ratio / limited_wheel_length_ratio* m_scale + rows / 2.0 + 0.5 + T(kPadding),
|
|
|
+ point_rotation(0, 0) * limited_wheel_length_img_ratio * m_scale + cols / 2.0 + 0.5 + T(kPadding),
|
|
|
&residual[i]);
|
|
|
+ residual[i] += theta_front*theta_front_weight;
|
|
|
costs[0] += residual[i];
|
|
|
-
|
|
|
}
|
|
|
//右前轮
|
|
|
int right_front_num = m_right_front_cloud.size();
|
|
@@ -122,9 +129,10 @@ public:
|
|
|
const Eigen::Matrix<T, 2, 1> tanslate_point = rotation_matrix * point - wheel_center_normal_right_front;
|
|
|
//旋转
|
|
|
const Eigen::Matrix<T, 2, 1> point_rotation = rotation_matrix_front * tanslate_point;
|
|
|
- interpolator.Evaluate(point_rotation(1, 0) * m_scale + rows / 2.0 + 0.5 + T(kPadding),
|
|
|
- point_rotation(0, 0) * m_scale + cols / 2.0 + 0.5 + T(kPadding),
|
|
|
+ interpolator.Evaluate(point_rotation(1, 0) * limited_wheel_length_img_ratio / limited_wheel_length_ratio* m_scale + rows / 2.0 + 0.5 + T(kPadding),
|
|
|
+ point_rotation(0, 0) * limited_wheel_length_img_ratio * m_scale + cols / 2.0 + 0.5 + T(kPadding),
|
|
|
&residual[left_front_num + i]);
|
|
|
+ residual[left_front_num + i] += theta_front*theta_front_weight;
|
|
|
costs[1] += residual[left_front_num+i];
|
|
|
}
|
|
|
//左后轮
|
|
@@ -136,8 +144,8 @@ public:
|
|
|
//减去经过车辆旋转计算的左前中心
|
|
|
const Eigen::Matrix<T, 2, 1> tanslate_point = rotation_matrix * point - wheel_center_normal_left_rear;
|
|
|
|
|
|
- interpolator.Evaluate(tanslate_point(1, 0) * m_scale + rows / 2.0 + 0.5 + T(kPadding),
|
|
|
- tanslate_point(0, 0) * m_scale + cols / 2.0 + 0.5 + T(kPadding),
|
|
|
+ interpolator.Evaluate(tanslate_point(1, 0) * limited_wheel_length_img_ratio / limited_wheel_length_ratio * m_scale + rows / 2.0 + 0.5 + T(kPadding),
|
|
|
+ tanslate_point(0, 0) * limited_wheel_length_img_ratio * m_scale + cols / 2.0 + 0.5 + T(kPadding),
|
|
|
&residual[left_front_num + right_front_num + i]);
|
|
|
costs[2] += residual[left_front_num + right_front_num + i];
|
|
|
}
|
|
@@ -150,8 +158,8 @@ public:
|
|
|
//减去经过车辆旋转计算的左前中心
|
|
|
const Eigen::Matrix<T, 2, 1> tanslate_point = rotation_matrix * point - wheel_center_normal_right_rear;
|
|
|
|
|
|
- interpolator.Evaluate(tanslate_point(1, 0) * m_scale + rows / 2.0 + 0.5 + T(kPadding),
|
|
|
- tanslate_point(0, 0) * m_scale + cols / 2.0 + 0.5 + T(kPadding),
|
|
|
+ interpolator.Evaluate(tanslate_point(1, 0) * limited_wheel_length_img_ratio / limited_wheel_length_ratio * m_scale + rows / 2.0 + 0.5 + T(kPadding),
|
|
|
+ tanslate_point(0, 0) * limited_wheel_length_img_ratio * m_scale + cols / 2.0 + 0.5 + T(kPadding),
|
|
|
&residual[left_front_num + right_front_num + left_rear_num + i]);
|
|
|
costs[3] += residual[left_front_num + right_front_num + left_rear_num + i];
|
|
|
}
|
|
@@ -202,15 +210,16 @@ bool detect_wheel_ceres::update_mat(int rows, int cols)
|
|
|
cv::Size size(n+2,n+2);
|
|
|
cv::Rect rect(center-cv::Point(n/2,n/2),size);
|
|
|
double x = n / double(L);
|
|
|
- double sigma = 0.06;
|
|
|
+ double sigma = 0.08;
|
|
|
double miu = 0.0;
|
|
|
double scale = 0.02;
|
|
|
- double translation = -0.05;
|
|
|
+ double translation = -0.03;
|
|
|
double gauss_value = (scale/(sqrt(2*M_PI)*sigma))*exp(-pow(x-miu, 2)/(2*sigma*sigma))+translation;
|
|
|
- double quadratic_value = x-0.08;
|
|
|
+ double quadratic_value = std::max(x-0.1, 0.03);
|
|
|
// LOG(INFO) << rect.tl().x<<", "<<rect.tl().y<<", "<<rect.br().x<<", "<<rect.br().y;
|
|
|
// 对内外分别取色
|
|
|
cv::rectangle(map,rect,std::max(gauss_value, quadratic_value));
|
|
|
+ // cv::circle(map, center, n/2, std::max(gauss_value, quadratic_value));
|
|
|
|
|
|
// if(n<K*2){
|
|
|
// cv::rectangle(map,rect,1.0*float(K*2-n)/float(L));
|
|
@@ -226,14 +235,12 @@ bool detect_wheel_ceres::update_mat(int rows, int cols)
|
|
|
|
|
|
detect_wheel_ceres::detect_wheel_ceres()
|
|
|
{
|
|
|
- int cols=800;
|
|
|
- int rows=200;
|
|
|
+ int cols=500;
|
|
|
+ int rows=500; // 200
|
|
|
update_mat(rows, cols);
|
|
|
}
|
|
|
detect_wheel_ceres::~detect_wheel_ceres(){}
|
|
|
|
|
|
-
|
|
|
-
|
|
|
bool detect_wheel_ceres::detect(std::vector<pcl::PointCloud<pcl::PointXYZ>> cloud_vec, Detect_result &detect_result)
|
|
|
{
|
|
|
//清理点云
|
|
@@ -349,21 +356,24 @@ bool detect_wheel_ceres::detect(std::vector<pcl::PointCloud<pcl::PointXYZ>> clou
|
|
|
Loss_result loss_result;
|
|
|
// 平均误差值,用于获取最小整体平均误差
|
|
|
double avg_loss = 100;
|
|
|
- // 定义图像列数,控制图像大小
|
|
|
- int map_cols = 800;
|
|
|
- // 优化后图像行数,用于保存优化后结果图像
|
|
|
- int optimized_map_rows = 200;
|
|
|
+ // // 定义图像列数,控制图像大小
|
|
|
+ // int map_cols = 800;
|
|
|
+ // // 优化后图像行数,用于保存优化后结果图像
|
|
|
+ // int optimized_map_rows = 200;
|
|
|
// 优化结果
|
|
|
bool solve_result = false;
|
|
|
double total_solve_time = 0;
|
|
|
- for (int j = 2; j < 4; 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);
|
|
|
+ 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 = -5; i < 6; i++)
|
|
|
+ for (int i = -3; i < 4&&!stop_sign; i+=6)
|
|
|
{
|
|
|
t_detect_result.theta = (-angle_x + i) * M_PI / 180.0;
|
|
|
// printf("double x:%.3f y: %.3f wheel:%.3f width:%.3f theta : %.3f front theta: %.3f\n",input_vars[0],input_vars[1],input_vars[3],input_vars[4],input_vars[2],input_vars[5]);
|
|
@@ -376,10 +386,11 @@ bool detect_wheel_ceres::detect(std::vector<pcl::PointCloud<pcl::PointXYZ>> clou
|
|
|
t_detect_result.front_theta *= (-M_PI) / 180.0;
|
|
|
}
|
|
|
auto t1=std::chrono::system_clock::now();
|
|
|
- bool current_result = Solve(t_detect_result, t_loss_result);
|
|
|
+ bool current_result = Solve(t_detect_result, t_loss_result, true);
|
|
|
auto t2=std::chrono::system_clock::now();
|
|
|
auto duration=t2-t1;
|
|
|
- double second=std::chrono::duration_cast<std::chrono::milliseconds>(duration).count()/1000.0;
|
|
|
+ static double second=0.0;
|
|
|
+ second=std::chrono::duration_cast<std::chrono::milliseconds>(duration).count()/1000.0;
|
|
|
total_solve_time+=second;
|
|
|
// std::cout<<" time "<<second<<std::endl;
|
|
|
// std::cout<<"current_result: "<<current_result<<std::endl;
|
|
@@ -393,23 +404,29 @@ bool detect_wheel_ceres::detect(std::vector<pcl::PointCloud<pcl::PointXYZ>> clou
|
|
|
detect_result = t_detect_result;
|
|
|
solve_result = current_result;
|
|
|
loss_result = t_loss_result;
|
|
|
- optimized_map_rows = map_rows;
|
|
|
+ // optimized_map_rows = map_rows;
|
|
|
calc_count++;
|
|
|
+ // // 新增,优化时间足够长则认为已找到正确结果
|
|
|
+ // if(second > 0.02)
|
|
|
+ // {
|
|
|
+ // stop_sign = true;
|
|
|
+ // break;
|
|
|
+ // }
|
|
|
}
|
|
|
}
|
|
|
- }
|
|
|
- std::cout<<"solve time "<<total_solve_time<<std::endl;
|
|
|
+ // }
|
|
|
+ // 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;
|
|
|
+ // // // 生成并保存图片
|
|
|
+ // // update_mat(optimized_map_rows, map_cols);
|
|
|
+ // Detect_result tt_detect_result = detect_result;
|
|
|
+ // tt_detect_result.theta *= (-M_PI) / 180.0;
|
|
|
+ // tt_detect_result.front_theta *= (-M_PI) / 180.0;
|
|
|
// Loss_result t_loss_result;
|
|
|
- // // LOG(INFO) <<"going to show img ";
|
|
|
+ // LOG(INFO) <<"going to show img ";
|
|
|
// Solve(detect_result, t_loss_result, true);
|
|
|
|
|
|
return solve_result;
|
|
@@ -559,7 +576,6 @@ bool detect_wheel_ceres::Solve(Detect_result &detect_result, double &avg_loss)
|
|
|
|
|
|
}
|
|
|
|
|
|
-
|
|
|
bool detect_wheel_ceres::Solve(Detect_result &detect_result, Loss_result &loss_result, bool save_img)
|
|
|
{
|
|
|
double SCALE=300.0;
|
|
@@ -569,26 +585,29 @@ bool detect_wheel_ceres::Solve(Detect_result &detect_result, Loss_result &loss_r
|
|
|
double init_wheel_base=2.7;
|
|
|
double init_width=1.55;
|
|
|
double init_theta_front=0*M_PI/180.0;
|
|
|
+ // 车轮长图比, 比例取值1/3-5/3, 当前变量无限制
|
|
|
+ double init_wheel_length_img_ratio = 0;
|
|
|
+ // 车轮宽长比, 默认长为1,比例取值范围0.2-0.8, 当前变量范围无限制
|
|
|
+ double init_wheel_width_length_ratio = 0;
|
|
|
|
|
|
- double variable[] = {cx,cy,init_theta,init_wheel_base,init_width,init_theta_front};
|
|
|
+ double variable[] = {cx, cy, init_theta, init_wheel_base, init_width, init_theta_front, init_wheel_length_img_ratio, init_wheel_width_length_ratio};
|
|
|
// printf("solve x:%.3f y: %.3f wheel:%.3f width:%.3f theta : %.3f front theta: %.3f\n", variable[0], variable[1], variable[3], variable[4], variable[2], variable[5]);
|
|
|
// 第二部分:构建寻优问题
|
|
|
ceres::Problem problem;
|
|
|
CostFunctor *cost_func = new CostFunctor(m_left_front_cloud,m_right_front_cloud,m_left_rear_cloud,m_right_rear_cloud,m_map,SCALE);
|
|
|
//使用自动求导,将之前的代价函数结构体传入,第一个1是输出维度,即残差的维度,第二个1是输入维度,即待寻优参数x的维度。
|
|
|
ceres::CostFunction* cost_function =new
|
|
|
- ceres::AutoDiffCostFunction<CostFunctor, ceres::DYNAMIC, 6>(
|
|
|
+ ceres::AutoDiffCostFunction<CostFunctor, ceres::DYNAMIC, 8>(
|
|
|
cost_func,
|
|
|
m_left_front_cloud.size()+m_right_front_cloud.size()+m_left_rear_cloud.size()+m_right_rear_cloud.size());
|
|
|
problem.AddResidualBlock(cost_function, NULL, variable); //向问题中添加误差项,本问题比较简单,添加一个就行。
|
|
|
|
|
|
-
|
|
|
//第三部分: 配置并运行求解器
|
|
|
ceres::Solver::Options options;
|
|
|
options.use_nonmonotonic_steps=false;
|
|
|
options.linear_solver_type = ceres::DENSE_QR; //配置增量方程的解法
|
|
|
options.max_num_iterations=60;
|
|
|
- options.num_threads=1;
|
|
|
+ options.num_threads=3;
|
|
|
options.minimizer_progress_to_stdout = false;//输出到cout
|
|
|
ceres::Solver::Summary summary;//优化信息
|
|
|
ceres::Solve(options, &problem, &summary);//求解!!!
|
|
@@ -609,14 +628,18 @@ bool detect_wheel_ceres::Solve(Detect_result &detect_result, Loss_result &loss_r
|
|
|
if(detect_result.theta<0)
|
|
|
detect_result.theta+=180.0;
|
|
|
|
|
|
+ // [1/3, 5/3]
|
|
|
+ double limited_wheel_length_img_ratio = (4.0/5.0) / (1 + std::exp(-variable[6])) + (4.0/5.0);
|
|
|
+ // [0.2, 0.8]
|
|
|
+ double limited_wheel_length_ratio = 0.6 / (1 + std::exp(-variable[7])) + 0.2;
|
|
|
//检验
|
|
|
// printf("loss: %.5f\n", loss);
|
|
|
- // printf("middle x:%.3f y: %.3f wheel:%.3f width:%.3f theta : %.3f front theta: %.3f\n", variable[0], variable[1], variable[3], variable[4], variable[2], variable[5]);
|
|
|
- if(loss>0.01)
|
|
|
- {
|
|
|
- LOG(WARNING) <<"总loss过大 "<<loss;
|
|
|
- return false;
|
|
|
- }
|
|
|
+ printf("middle x:%.3f y: %.3f wheel:%.3f width:%.3f theta : %.3f front theta: %.3f, ratio: %.3f %.3f\n", variable[0], variable[1], variable[3], variable[4], variable[2], variable[5], limited_wheel_length_img_ratio, limited_wheel_length_ratio);
|
|
|
+ // if(loss>0.0006)//0.0141
|
|
|
+ // {
|
|
|
+ // LOG(WARNING) <<"总loss过大 "<<loss;
|
|
|
+ // return false;
|
|
|
+ // }
|
|
|
if (detect_result.width < 1.350 || detect_result.width > 2.000 || detect_result.wheel_base > 3.000 || detect_result.wheel_base < 2.200)
|
|
|
{
|
|
|
LOG(WARNING) <<"宽度(1.35, 2.00) 轴距(2.20, 3.00): "<<detect_result.width<<", "<<detect_result.wheel_base;
|
|
@@ -658,15 +681,15 @@ bool detect_wheel_ceres::Solve(Detect_result &detect_result, Loss_result &loss_r
|
|
|
loss_result.rb_loss = loss;
|
|
|
}
|
|
|
// 判断每个轮子平均loss是否满足条件
|
|
|
- double single_wheel_loss_threshold = 0.09;
|
|
|
- if(loss_result.lf_loss > single_wheel_loss_threshold || loss_result.rf_loss > single_wheel_loss_threshold || loss_result.lb_loss > single_wheel_loss_threshold || loss_result.rb_loss > single_wheel_loss_threshold)
|
|
|
- {
|
|
|
- LOG(WARNING) <<"四轮loss过大";
|
|
|
- return false;
|
|
|
- }
|
|
|
+ double single_wheel_loss_threshold = 0.023;//0.115
|
|
|
+ // if(loss_result.lf_loss > single_wheel_loss_threshold || loss_result.rf_loss > single_wheel_loss_threshold || loss_result.lb_loss > single_wheel_loss_threshold || loss_result.rb_loss > single_wheel_loss_threshold)
|
|
|
+ // {
|
|
|
+ // 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;
|
|
|
- debug_img(detect_result, loss_result, save_img);
|
|
|
+ debug_img(detect_result, loss_result, save_img, limited_wheel_length_img_ratio, limited_wheel_length_ratio);
|
|
|
}
|
|
|
else
|
|
|
{
|
|
@@ -683,7 +706,7 @@ bool detect_wheel_ceres::Solve(Detect_result &detect_result, Loss_result &loss_r
|
|
|
}
|
|
|
|
|
|
// 显示/保存图片供调试用
|
|
|
-void detect_wheel_ceres::debug_img(Detect_result detect_result, Loss_result loss_result, bool save_img, std::string out_img_path)
|
|
|
+void detect_wheel_ceres::debug_img(Detect_result detect_result, Loss_result loss_result, bool save_img, double li_ratio , double wl_ratio, std::string out_img_path)
|
|
|
{
|
|
|
double SCALE=300.0;
|
|
|
cv::Mat lf = m_map.clone();
|
|
@@ -691,7 +714,7 @@ void detect_wheel_ceres::debug_img(Detect_result detect_result, Loss_result loss
|
|
|
cv::Mat lb = m_map.clone();
|
|
|
cv::Mat rb = m_map.clone();
|
|
|
//整车旋转
|
|
|
- Eigen::Rotation2D<double> rotation(detect_result.theta);
|
|
|
+ Eigen::Rotation2D<double> rotation(detect_result.theta*(-M_PI/180.0));
|
|
|
|
|
|
Eigen::Matrix<double, 2, 2> rotation_matrix = rotation.toRotationMatrix();
|
|
|
|
|
@@ -705,7 +728,7 @@ void detect_wheel_ceres::debug_img(Detect_result detect_result, Loss_result loss
|
|
|
Eigen::Matrix<double, 2, 1> wheel_center_normal_right_rear(-detect_result.wheel_base / 2.0, (-detect_result.width + 0.15) / 2.0);
|
|
|
|
|
|
//前轮旋转
|
|
|
- Eigen::Rotation2D<double> rotation_front(detect_result.front_theta);
|
|
|
+ Eigen::Rotation2D<double> rotation_front(detect_result.front_theta*(-M_PI/180.0));
|
|
|
Eigen::Matrix<double, 2, 2> rotation_matrix_front = rotation_front.toRotationMatrix();
|
|
|
|
|
|
// 左前轮
|
|
@@ -717,8 +740,8 @@ void detect_wheel_ceres::debug_img(Detect_result detect_result, Loss_result loss
|
|
|
Eigen::Matrix<double, 2, 1> tanslate_point = rotation_matrix * point - wheel_center_normal_left_front;
|
|
|
//旋转
|
|
|
Eigen::Matrix<double, 2, 1> point_rotation = rotation_matrix_front * tanslate_point;
|
|
|
- int r = (int)(point_rotation(1, 0) * SCALE + m_map.rows / 2.0 + 0.5);
|
|
|
- int c = (int)(point_rotation(0, 0) * SCALE + m_map.cols / 2.0 + 0.5);
|
|
|
+ int r = (int)(point_rotation(1, 0) *li_ratio/ wl_ratio * SCALE + m_map.rows / 2.0 + 0.5);
|
|
|
+ int c = (int)(point_rotation(0, 0) *li_ratio * SCALE + m_map.cols / 2.0 + 0.5);
|
|
|
cv::circle(lf, cv::Point(c, r), 1, cv::Scalar(150));
|
|
|
// std::cout<<"map r,c "<<m_map.rows<<", "<<m_map.cols<<std::endl;
|
|
|
// std::cout<<"r,c "<<r<<", "<<c<<std::endl;
|
|
@@ -733,8 +756,8 @@ void detect_wheel_ceres::debug_img(Detect_result detect_result, Loss_result loss
|
|
|
Eigen::Matrix<double, 2, 1> tanslate_point = rotation_matrix * point - wheel_center_normal_right_front;
|
|
|
//旋转
|
|
|
Eigen::Matrix<double, 2, 1> point_rotation = rotation_matrix_front * tanslate_point;
|
|
|
- int r = (int)(point_rotation(1, 0) * SCALE + m_map.rows / 2.0 + 0.5);
|
|
|
- int c = (int)(point_rotation(0, 0) * SCALE + m_map.cols / 2.0 + 0.5);
|
|
|
+ int r = (int)(point_rotation(1, 0)*li_ratio/ wl_ratio * SCALE + m_map.rows / 2.0 + 0.5);
|
|
|
+ int c = (int)(point_rotation(0, 0)*li_ratio * SCALE + m_map.cols / 2.0 + 0.5);
|
|
|
cv::circle(rf, cv::Point(c, r), 1, cv::Scalar(150));
|
|
|
}
|
|
|
//左后轮
|
|
@@ -744,8 +767,8 @@ void detect_wheel_ceres::debug_img(Detect_result detect_result, Loss_result loss
|
|
|
(double(m_left_rear_cloud[i].y) - detect_result.cy));
|
|
|
//减去经过车辆旋转计算的左前中心
|
|
|
Eigen::Matrix<double, 2, 1> tanslate_point = rotation_matrix * point - wheel_center_normal_left_rear;
|
|
|
- int r = (int)(tanslate_point(1, 0) * SCALE + m_map.rows / 2.0 + 0.5);
|
|
|
- int c = (int)(tanslate_point(0, 0) * SCALE + m_map.cols / 2.0 + 0.5);
|
|
|
+ int r = (int)(tanslate_point(1, 0)*li_ratio / wl_ratio * SCALE + m_map.rows / 2.0 + 0.5);
|
|
|
+ int c = (int)(tanslate_point(0, 0)*li_ratio * SCALE + m_map.cols / 2.0 + 0.5);
|
|
|
cv::circle(lb, cv::Point(c, r), 1, cv::Scalar(150));
|
|
|
}
|
|
|
|
|
@@ -756,8 +779,8 @@ void detect_wheel_ceres::debug_img(Detect_result detect_result, Loss_result loss
|
|
|
(double(m_right_rear_cloud[i].y) - detect_result.cy));
|
|
|
//减去经过车辆旋转计算的左前中心
|
|
|
Eigen::Matrix<double, 2, 1> tanslate_point = rotation_matrix * point - wheel_center_normal_right_rear;
|
|
|
- int r = (int)(tanslate_point(1, 0) * SCALE + m_map.rows / 2.0 + 0.5);
|
|
|
- int c = (int)(tanslate_point(0, 0) * SCALE + m_map.cols / 2.0 + 0.5);
|
|
|
+ int r = (int)(tanslate_point(1, 0)*li_ratio / wl_ratio * SCALE + m_map.rows / 2.0 + 0.5);
|
|
|
+ int c = (int)(tanslate_point(0, 0)*li_ratio * SCALE + m_map.cols / 2.0 + 0.5);
|
|
|
cv::circle(rb, cv::Point(c, r), 1, cv::Scalar(150));
|
|
|
}
|
|
|
|
|
@@ -798,23 +821,25 @@ void detect_wheel_ceres::debug_img(Detect_result detect_result, Loss_result loss
|
|
|
rft.copyTo(total_img(cv::Rect(m_map.rows, 0, m_map.rows, m_map.cols)));
|
|
|
lbt.copyTo(total_img(cv::Rect(0, m_map.cols, m_map.rows, m_map.cols)));
|
|
|
rbt.copyTo(total_img(cv::Rect(m_map.rows, m_map.cols, m_map.rows, m_map.cols)));
|
|
|
- // cv::namedWindow("total img", CV_WINDOW_FREERATIO);
|
|
|
- // cv::imshow("total img", total_img);
|
|
|
- // cv::waitKey(20);
|
|
|
- if(save_img)
|
|
|
+ // std::cout << "save? " << save_img << std::endl;
|
|
|
+ if (save_img)
|
|
|
{
|
|
|
- cv::Mat cvted_img = cv::Mat::zeros(m_map.cols * 2, m_map.rows * 2, CV_8U);
|
|
|
- int total_milli = (std::chrono::time_point_cast<std::chrono::milliseconds>(std::chrono::system_clock::now())).time_since_epoch().count();
|
|
|
- std::string img_filename="";
|
|
|
- if(out_img_path.empty()){
|
|
|
- img_filename = std::string("/home/youchen/Documents/measure/MainStructure/elecfence_ws/img/img").append(std::to_string(total_milli)).append(".jpg");
|
|
|
- }
|
|
|
- else{
|
|
|
- img_filename = out_img_path;
|
|
|
- }
|
|
|
- LOG(INFO) << "write to " << img_filename.c_str();
|
|
|
- // cv::cvtColor(total_img*255, cvted_img, CV_8U);
|
|
|
- cv::convertScaleAbs(total_img * 255, cvted_img);
|
|
|
- cv::imwrite(img_filename, cvted_img);
|
|
|
+ cv::namedWindow("total img", CV_WINDOW_FREERATIO);
|
|
|
+ cv::imshow("total img", total_img);
|
|
|
+ cv::waitKey(20);
|
|
|
+
|
|
|
+ // cv::Mat cvted_img = cv::Mat::zeros(m_map.cols * 2, m_map.rows * 2, CV_8U);
|
|
|
+ // int total_milli = (std::chrono::time_point_cast<std::chrono::milliseconds>(std::chrono::system_clock::now())).time_since_epoch().count();
|
|
|
+ // std::string img_filename = "";
|
|
|
+ // if(out_img_path.empty()){
|
|
|
+ // img_filename = std::string("/home/youchen/Documents/measure/MainStructure/elecfence_ws/img/img").append(std::to_string(total_milli)).append(".jpg");
|
|
|
+ // }
|
|
|
+ // else{
|
|
|
+ // img_filename = out_img_path;
|
|
|
+ // }
|
|
|
+ // LOG(INFO) << "write to " << img_filename.c_str();
|
|
|
+ // // cv::cvtColor(total_img*255, cvted_img, CV_8U);
|
|
|
+ // cv::convertScaleAbs(total_img * 255, cvted_img);
|
|
|
+ // cv::imwrite(img_filename, cvted_img);
|
|
|
}
|
|
|
}
|