For the planar tracker, initialize the warp from the four correspondences after
authorKeir Mierle <mierle@gmail.com>
Thu, 17 May 2012 21:26:06 +0000 (21:26 +0000)
committerKeir Mierle <mierle@gmail.com>
Thu, 17 May 2012 21:26:06 +0000 (21:26 +0000)
brute force translation search.

extern/libmv/libmv-capi.cpp
extern/libmv/libmv/tracking/track_region.cc

index 482a4c98245fee7e452fc99d6ee6ca689d5b507a..1781eaa747c00d327c32c5e7ab1e19acfdcb4c91 100644 (file)
@@ -400,8 +400,7 @@ int libmv_trackRegion(const struct libmv_trackRegionOptions *options,
        if (track_region_result.termination == libmv::TrackRegionResult::PARAMETER_TOLERANCE ||
            track_region_result.termination == libmv::TrackRegionResult::FUNCTION_TOLERANCE  ||
            track_region_result.termination == libmv::TrackRegionResult::GRADIENT_TOLERANCE  ||
-           track_region_result.termination == libmv::TrackRegionResult::NO_CONVERGENCE      ||
-           track_region_result.termination == libmv::TrackRegionResult::INSUFFICIENT_CORRELATION)
+           track_region_result.termination == libmv::TrackRegionResult::NO_CONVERGENCE)
        {
                tracking_result = true;
        }
index 22c86a7f5b948f5686e067cf3f22b11a0882cb36..22b417c22f62b948dd845607cd03be0942adb883 100644 (file)
@@ -398,7 +398,7 @@ class Quad {
 struct TranslationWarp {
   TranslationWarp(const double *x1, const double *y1,
                   const double *x2, const double *y2) {
-    Vec2 t = Quad(x2, y2).Centroid() - Quad(x1, y1).Centroid() ;
+    Vec2 t = Quad(x2, y2).Centroid() - Quad(x1, y1).Centroid();
     parameters[0] = t[0];
     parameters[1] = t[1];
   }
@@ -908,19 +908,6 @@ void TemplatedTrackRegion(const FloatImage &image1,
   }
   // TODO(keir): Check quads to ensure there is some area.
 
-  // Prepare the initial warp parameters from the four correspondences.
-  Warp warp(x1, y1, x2, y2);
-
-  // Decide how many samples to use in the x and y dimensions.
-  int num_samples_x;
-  int num_samples_y;
-  PickSampling(x1, y1, x2, y2, &num_samples_x, &num_samples_y);
-
-  // Compute the warp from rectangular coordinates.
-  Mat3 canonical_homography = ComputeCanonicalHomography(x1, y1,
-                                                         num_samples_x,
-                                                         num_samples_y);
-
   // Prepare the image and gradient.
   Array3Df image_and_gradient1;
   Array3Df image_and_gradient2;
@@ -938,8 +925,22 @@ void TemplatedTrackRegion(const FloatImage &image1,
                                          image2,
                                          options.num_extra_points,
                                          x1, y1, x2, y2);
+    for (int i = 0; i < 4; ++i) {
+      LG << "P" << i << ": (" << x1[i] << ", " << y1[i] << "); brute ("
+         << x2[i] << ", " << y2[i] << "); (dx, dy): (" << (x2[i] - x1[i]) << ", "
+         << (y2[i] - y1[i]) << ").";
+    }
   }
 
+  // Prepare the initial warp parameters from the four correspondences.
+  // Note: This must happen after the brute initialization runs.
+  Warp warp(x1, y1, x2, y2);
+
+  // Decide how many samples to use in the x and y dimensions.
+  int num_samples_x;
+  int num_samples_y;
+  PickSampling(x1, y1, x2, y2, &num_samples_x, &num_samples_y);
+
   ceres::Solver::Options solver_options;
   solver_options.linear_solver_type = ceres::DENSE_QR;
   solver_options.max_num_iterations = options.max_iterations;
@@ -957,6 +958,11 @@ void TemplatedTrackRegion(const FloatImage &image1,
   BoundaryCheckingCallback<Warp> callback(image2, warp, x1, y1);
   solver_options.callbacks.push_back(&callback);
 
+  // Compute the warp from rectangular coordinates.
+  Mat3 canonical_homography = ComputeCanonicalHomography(x1, y1,
+                                                         num_samples_x,
+                                                         num_samples_y);
+
   // Construct the warp cost function. AutoDiffCostFunction takes ownership.
   WarpCostFunctor<Warp> *warp_cost_function =
       new WarpCostFunctor<Warp>(options,