From 00acb984360439d5480bd84d5a212a5524984900 Mon Sep 17 00:00:00 2001 From: Sergey Sharybin Date: Thu, 27 Feb 2014 14:27:30 +0600 Subject: [PATCH] Fix T38844: Crash if weight track = 0 Avoid zero-sized problem when doing euclidean intersection Zero-sized problem might occur when intersecting track with constant zero weight. For such tracks we'll just use result of algebraic intersection. TODO: We probably need to have a separate BA step to adjust positions of tracks with constant zero weight. --- .../libmv/libmv/simple_pipeline/intersect.cc | 20 +++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/extern/libmv/libmv/simple_pipeline/intersect.cc b/extern/libmv/libmv/simple_pipeline/intersect.cc index 6a098da272d..ddb713684a4 100644 --- a/extern/libmv/libmv/simple_pipeline/intersect.cc +++ b/extern/libmv/libmv/simple_pipeline/intersect.cc @@ -100,6 +100,8 @@ bool EuclideanIntersect(const vector &markers, ceres::Problem problem; + // Add residual blocks to the problem. + int num_residuals = 0; for (int i = 0; i < markers.size(); ++i) { const Marker &marker = markers[i]; if (marker.weight != 0.0) { @@ -113,9 +115,27 @@ bool EuclideanIntersect(const vector &markers, 3>(new EuclideanIntersectCostFunctor(marker, camera)), NULL, &X(0)); + num_residuals++; } } + // TODO(sergey): Once we'll update Ceres to the next version + // we wouldn't need this check anymore -- Ceres will deal with + // zero-sized problems nicely. + LG << "Number of residuals: " << num_residuals; + if (!num_residuals) { + LG << "Skipping running minimizer with zero residuals"; + + // We still add 3D point for the track regardless it was + // optimized or not. If track is a constant zero it'll use + // algebraic intersection result as a 3D coordinate. + + Vec3 point = X.head<3>(); + reconstruction->InsertPoint(markers[0].track, point); + + return true; + } + // Configure the solve. ceres::Solver::Options solver_options; solver_options.linear_solver_type = ceres::DENSE_QR; -- 2.26.2