struct DepthPlaneFittingCostFunction {
DepthPlaneFittingCostFunction(const cv::Mat &img_1, const cv::Mat &img_2,
const SphericalCamera &cam_1, const SphericalCamera &cam_2, const cv::Point &initial_pt, int meas_type_ = CV_TM_SQDIFF_NORMED)
: p_g_image_1(&img_1), p_g_image_2(&img_2), p_cam_1(&cam_1), p_cam_2(&cam_2), meas_type(meas_type_), image_pt(initial_pt)
{
cam_1_ray = cam_1.GetRay(openMVG::Vec2(image_pt.x, image_pt.y));
image_rect = cv::Rect(0, 0, img_1.cols, img_1.rows);
}
bool operator()(const double* const plane, double* residuals) const
{
auto dist = abs(plane[3]/(cam_1_ray.x()*plane[0] + cam_1_ray.y()*plane[1] + cam_1_ray.z()*plane[2]));
openMVG::Vec3 obj_pt = p_cam_1->_C + dist*cam_1_ray;
openMVG::Vec2 prj_pt = p_cam_2->Project(obj_pt);
cv::Rect template_1(image_pt.x - template_size, image_pt.y - template_size, 2*template_size + 1, 2*template_size + 1);
cv::Rect template_2(cvRound(prj_pt.x()) - template_size, cvRound(prj_pt.y()) - template_size, 2*template_size + 1, 2*template_size + 1);
if((template_1 & image_rect) != template_1 || (template_2 & image_rect) != template_2)
{
residuals[0] = 1.;
return true;
}
cv::Mat res;
cv::matchTemplate((*p_g_image_1)(template_1), (*p_g_image_2)(template_2), res, meas_type);
residuals[0] = res.at<float>(0);
return true;
}
// Factory to hide the construction of the CostFunction object from
// the client code.
static ceres::CostFunction* Create(const cv::Mat &img_1, const cv::Mat &img_2,
const SphericalCamera &cam_1, const SphericalCamera &cam_2, const cv::Point &initial_pt, int meas_type_ = CV_TM_SQDIFF_NORMED) {
return (new ceres::NumericDiffCostFunction<DepthPlaneFittingCostFunction, ceres::CENTRAL, 1, 4>(
new DepthPlaneFittingCostFunction(img_1, img_2, cam_1, cam_2, initial_pt, meas_type_)));
}
const cv::Mat *p_g_image_1, *p_g_image_2;
int meas_type;
const SphericalCamera *p_cam_1, *p_cam_2;
openMVG::Vec3 cam_1_ray;
cv::Point image_pt;
static size_t template_size;
cv::Rect image_rect;
};
ceres::Solver::Options options;
options.preconditioner_type = ceres::JACOBI;
options.linear_solver_type = ceres::DENSE_SCHUR;
options.minimizer_progress_to_stdout = true;
options.max_num_iterations = 100;
ceres::Solver::Summary summary;
ceres::Solve(options, &problem, &summary);
--
You received this message because you are subscribed to the Google Groups "Ceres Solver" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ceres-solver...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ceres-solver/adb89c6e-1003-4ef5-8a06-3050743f3665%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Have a look at the options struct for dynamicautodiffcostfunction
To view this discussion on the web visit https://groups.google.com/d/msgid/ceres-solver/ea8c4769-b69a-4750-b69b-c7b36f8626ac%40googlegroups.com.