[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [50758] trunk/blender/extern/libmv/libmv/ tracking: Detect too-small planar tracking patches.

Keir Mierle mierle at gmail.com
Thu Sep 20 00:25:03 CEST 2012


Revision: 50758
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=50758
Author:   keir
Date:     2012-09-19 22:25:02 +0000 (Wed, 19 Sep 2012)
Log Message:
-----------
Detect too-small planar tracking patches.

The planar tracker did not detect very skinny patches which have
effectively zero area and are untrackable. This adds detection and
rejection of patterns with zero area. This fixes a crash found by
during Mango production.

Modified Paths:
--------------
    trunk/blender/extern/libmv/libmv/tracking/track_region.cc
    trunk/blender/extern/libmv/libmv/tracking/track_region.h

Modified: trunk/blender/extern/libmv/libmv/tracking/track_region.cc
===================================================================
--- trunk/blender/extern/libmv/libmv/tracking/track_region.cc	2012-09-19 22:01:42 UTC (rev 50757)
+++ trunk/blender/extern/libmv/libmv/tracking/track_region.cc	2012-09-19 22:25:02 UTC (rev 50758)
@@ -1123,6 +1123,9 @@
 // correlation. Instead, this is a dumb implementation. Surprisingly, it is
 // fast enough in practice.
 //
+// Returns true if any alignment was found, and false if the projected pattern
+// is zero sized.
+//
 // TODO(keir): The normalization is less effective for the brute force search
 // than it is with the Ceres solver. It's unclear if this is a bug or due to
 // the original frame being too different from the reprojected reference in the
@@ -1133,7 +1136,7 @@
 // totally different warping interface, since access to more than a the source
 // and current destination frame is necessary.
 template<typename Warp>
-void BruteTranslationOnlyInitialize(const FloatImage &image1,
+bool BruteTranslationOnlyInitialize(const FloatImage &image1,
                                     const FloatImage *image1_mask,
                                     const FloatImage &image2,
                                     const int num_extra_points,
@@ -1179,6 +1182,7 @@
   int best_c = -1;
   int w = pattern.cols();
   int h = pattern.rows();
+
   for (int r = 0; r < (image2.Height() - h); ++r) {
     for (int c = 0; c < (image2.Width() - w); ++c) {
       // Compute the weighted sum of absolute differences, Eigen style. Note
@@ -1203,9 +1207,13 @@
       }
     }
   }
-  CHECK_NE(best_r, -1);
-  CHECK_NE(best_c, -1);
 
+  // This mean the effective pattern area is zero. This check could go earlier,
+  // but this is less code.
+  if (best_r == -1 || best_c == -1) {
+    return false;
+  }
+
   LG << "Brute force translation found a shift. "
      << "best_c: " << best_c << ", best_r: " << best_r << ", "
      << "origin_x: " << origin_x << ", origin_y: " << origin_y << ", "
@@ -1219,6 +1227,7 @@
     x2[i] += best_c - origin_x;
     y2[i] += best_r - origin_y;
   }
+  return true;
 }
 
 }  // namespace
@@ -1270,12 +1279,19 @@
   if (SearchAreaTooBigForDescent(image2, x2, y2) &&
       options.use_brute_initialization) {
     LG << "Running brute initialization...";
-    BruteTranslationOnlyInitialize<Warp>(image_and_gradient1,
-                                         options.image1_mask,
-                                         image2,
-                                         options.num_extra_points,
-                                         options.use_normalized_intensities,
-                                         x1, y1, x2, y2);
+    bool found_any_alignment = BruteTranslationOnlyInitialize<Warp>(
+        image_and_gradient1,
+        options.image1_mask,
+        image2,
+        options.num_extra_points,
+        options.use_normalized_intensities,
+        x1, y1, x2, y2);
+    if (!found_any_alignment) {
+      LG << "Brute failed to find an alignment; pattern too small. "
+         << "Failing entire track operation.";
+      result->termination = TrackRegionResult::INSUFFICIENT_PATTERN_AREA;
+      return;
+    }
     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])

Modified: trunk/blender/extern/libmv/libmv/tracking/track_region.h
===================================================================
--- trunk/blender/extern/libmv/libmv/tracking/track_region.h	2012-09-19 22:01:42 UTC (rev 50757)
+++ trunk/blender/extern/libmv/libmv/tracking/track_region.h	2012-09-19 22:25:02 UTC (rev 50758)
@@ -111,6 +111,7 @@
     DESTINATION_OUT_OF_BOUNDS,
     FELL_OUT_OF_BOUNDS,
     INSUFFICIENT_CORRELATION,
+    INSUFFICIENT_PATTERN_AREA,
     CONFIGURATION_ERROR,
   };
   Termination termination;




More information about the Bf-blender-cvs mailing list