|
@@ -109,8 +109,8 @@ public:
|
|
|
{
|
|
|
T cx = variable[0];
|
|
|
T cy = variable[1];
|
|
|
- T w_ratio = variable[2]/T(inner_width);
|
|
|
- T h_ratio = variable[3]/T(chassis_height);
|
|
|
+ // T w_ratio = variable[2]/T(inner_width);
|
|
|
+ // T h_ratio = variable[3]/T(chassis_height);
|
|
|
|
|
|
const GridArrayAdapter adapter(m_mat);
|
|
|
ceres::BiCubicInterpolator<GridArrayAdapter> interpolator(adapter);
|
|
@@ -120,14 +120,14 @@ public:
|
|
|
//先平移后旋转
|
|
|
const Eigen::Matrix<T, 2, 1> point((T(m_cloud->points[i].x)-cx),
|
|
|
(T(m_cloud->points[i].z)-cy));
|
|
|
- T kx=(point(0,0)/w_ratio-T(startx)) / T(resolutionx) + T(0.5+kPadding);
|
|
|
- T ky=(point(1,0)/h_ratio-T(starty)) / T(resolutiony) + T(0.5+kPadding);
|
|
|
+ T kx=(point(0,0)-T(startx)) / T(resolutionx) + T(0.5+kPadding);
|
|
|
+ T ky=(point(1,0)-T(starty)) / T(resolutiony) + T(0.5+kPadding);
|
|
|
interpolator.Evaluate(kx, ky, &residual[i]);
|
|
|
|
|
|
// residual[i] = fx * fy; //+(50./m_cloud->size())/(w*h+1e-16);
|
|
|
}
|
|
|
- residual[m_cloud->size()] = (w_ratio - T(1.0));
|
|
|
- residual[m_cloud->size()+1] = (h_ratio - T(1.0));
|
|
|
+ // residual[m_cloud->size()] = (w_ratio - T(1.0));
|
|
|
+ // residual[m_cloud->size()+1] = (h_ratio - T(1.0));
|
|
|
return true;
|
|
|
}
|
|
|
|
|
@@ -135,13 +135,13 @@ public:
|
|
|
void generate_mat(cv::Mat &mat, pcl::PointCloud<pcl::PointXYZ>::Ptr cloud, double *variables)
|
|
|
{
|
|
|
mat = m_mat.clone();
|
|
|
- double w_ratio = variables[2] / inner_width;
|
|
|
- double h_ratio = variables[3] / chassis_height;
|
|
|
+ // double w_ratio = variables[2] / inner_width;
|
|
|
+ // double h_ratio = variables[3] / chassis_height;
|
|
|
for (size_t i = 0; i < cloud->size(); i++)
|
|
|
{
|
|
|
const Eigen::Vector2d point(
|
|
|
- ((cloud->points[i].x - variables[0]) * w_ratio - startx) / resolutionx,
|
|
|
- ((cloud->points[i].z - variables[1]) * h_ratio - starty) / resolutiony);
|
|
|
+ ((cloud->points[i].x - variables[0]) - startx) / resolutionx,
|
|
|
+ ((cloud->points[i].z - variables[1]) - starty) / resolutiony);
|
|
|
cv::circle(mat, cv::Point2d(point.y(), point.x()), 2, cv::Scalar(0.4), 1);
|
|
|
// std::cout << point.y() << ", " << point.x() << std::endl;
|
|
|
}
|
|
@@ -190,6 +190,8 @@ Error_manager chassis_ceres_solver::solve(pcl::PointCloud<pcl::PointXYZ>::Ptr cl
|
|
|
|
|
|
x=variable[0];
|
|
|
y=variable[1];
|
|
|
+ w = variable[2];
|
|
|
+ h = variable[3];
|
|
|
// printf(" loss : %f x:%.5f y:%.5f w:%.5f h:%.5f\n",
|
|
|
// loss,variable[0],variable[1],variable[2],variable[3]);
|
|
|
|
|
@@ -220,8 +222,8 @@ Error_manager chassis_ceres_solver::solve_mat(pcl::PointCloud<pcl::PointXYZ>::Pt
|
|
|
chassis_mat_cost *cost_func = new chassis_mat_cost(cloud, m_model);
|
|
|
//使用自动求导,将之前的代价函数结构体传入,第一个1是输出维度,即残差的维度,第二个1是输入维度,即待寻优参数x的维度。
|
|
|
ceres::CostFunction* cost_function =new
|
|
|
- ceres::AutoDiffCostFunction<chassis_mat_cost, ceres::DYNAMIC, 4>(
|
|
|
- cost_func, cloud->size()+2);
|
|
|
+ ceres::AutoDiffCostFunction<chassis_mat_cost, ceres::DYNAMIC, 2>(
|
|
|
+ cost_func, cloud->size());
|
|
|
problem.AddResidualBlock(cost_function, new ceres::HuberLoss(1.0), variable); //向问题中添加误差项,本问题比较简单,添加一个就行。
|
|
|
|
|
|
//第三部分: 配置并运行求解器
|
|
@@ -235,14 +237,14 @@ Error_manager chassis_ceres_solver::solve_mat(pcl::PointCloud<pcl::PointXYZ>::Pt
|
|
|
ceres::Solver::Summary summary;//优化信息
|
|
|
ceres::Solve(options, &problem, &summary);//求解!!!
|
|
|
|
|
|
- std::cout << summary.BriefReport() << std::endl;
|
|
|
+ // std::cout << summary.BriefReport() << std::endl;
|
|
|
|
|
|
double loss=summary.final_cost/(cloud->size());
|
|
|
|
|
|
x = variable[0];
|
|
|
y = variable[1];
|
|
|
- w = variable[2];
|
|
|
- h = variable[3];
|
|
|
+ // w = variable[2];
|
|
|
+ // h = variable[3];
|
|
|
// printf(" loss : %f x:%.5f y:%.5f w:%.5f h:%.5f\n",
|
|
|
// loss,variable[0],variable[1],variable[2],variable[3]);
|
|
|
|
|
@@ -251,10 +253,11 @@ Error_manager chassis_ceres_solver::solve_mat(pcl::PointCloud<pcl::PointXYZ>::Pt
|
|
|
|
|
|
if(update_debug_img)
|
|
|
{
|
|
|
+ // printf("midx:%.3f, midz:%.3f\n", x, y);
|
|
|
cost_func->generate_mat(m_projected_mat, cloud, variable);
|
|
|
cv::namedWindow("win", cv::WINDOW_FREERATIO);
|
|
|
cv::imshow("win", m_projected_mat);
|
|
|
- cv::waitKey(30);
|
|
|
+ cv::waitKey();
|
|
|
}
|
|
|
|
|
|
|