Add check for points behind camera in euclidan BA cost functor
authorSergey Sharybin <sergey.vfx@gmail.com>
Thu, 9 May 2013 16:38:58 +0000 (16:38 +0000)
committerSergey Sharybin <sergey.vfx@gmail.com>
Thu, 9 May 2013 16:38:58 +0000 (16:38 +0000)
In cases keyframes are no so good, algebraic two frames construction
could produce result, for which more aggressive Ceres-based BA code
will fall to a solution for which points goes behind the camera,
which is not so nice.

Seems in newer Ceres returning false from cost functor wouldn't
abort solution, but will restrict solver from moving points behind
the camera.

Works fine in own tests, but requires more tests.

extern/libmv/libmv/simple_pipeline/bundle.cc

index f068e050b486f1a92a6a0b969d66dff37699f580..17996f70defe84060136f00f403fbd50d8c3f0ce 100644 (file)
@@ -83,6 +83,10 @@ struct OpenCVReprojectionError {
     x[1] += R_t[4];
     x[2] += R_t[5];
 
+    // Prevent points from going behind the camera.
+    if (x[2] < T(0))
+      return false;
+
     // Compute normalized coordinates: x /= x[2].
     T xn = x[0] / x[2];
     T yn = x[1] / x[2];