Scale search area when doing planar tracking
authorSergey Sharybin <sergey.vfx@gmail.com>
Mon, 11 Jun 2012 11:40:54 +0000 (11:40 +0000)
committerSergey Sharybin <sergey.vfx@gmail.com>
Mon, 11 Jun 2012 11:40:54 +0000 (11:40 +0000)
Helps keeping features tracked when there's large scale happens
without need to manually re-adjust search area.

Currently using factor of pattern's boundbox scale, but probably
could be done in more accurate way?

extern/libmv/libmv-capi.cpp
extern/libmv/libmv-capi.h
source/blender/blenkernel/BKE_tracking.h
source/blender/blenkernel/intern/tracking.c

index ffa065f08fe372efcfabd1a89ff5c463e405483d..8751e1e190b5595b0ba6a72b390fa1e54e2f6193 100644 (file)
@@ -357,8 +357,8 @@ void libmv_regionTrackerDestroy(libmv_RegionTracker *libmv_tracker)
 
 /* TrackRegion (new planar tracker) */
 int libmv_trackRegion(const struct libmv_trackRegionOptions *options,
-                      const float *image1, const float *image2,
-                      int width, int height, 
+                      const float *image1, int image1_width, int image1_height,
+                      const float *image2, int image2_width, int image2_height,
                       const double *x1, const double *y1,
                       struct libmv_trackRegionResult *result,
                       double *x2, double *y2)
@@ -400,8 +400,8 @@ int libmv_trackRegion(const struct libmv_trackRegionOptions *options,
 
        /* Convert from raw float buffers to libmv's FloatImage. */
        libmv::FloatImage old_patch, new_patch;
-       floatBufToImage(image1, width, height, 1, &old_patch);
-       floatBufToImage(image2, width, height, 1, &new_patch);
+       floatBufToImage(image1, image1_width, image1_height, 1, &old_patch);
+       floatBufToImage(image2, image2_width, image2_height, 1, &new_patch);
 
        libmv::TrackRegionResult track_region_result;
        libmv::TrackRegion(old_patch, new_patch, xx1, yy1, track_region_options, xx2, yy2, &track_region_result);
index 6f4b5dea3849cd6bf33a104c4ba86902b0311ba8..fe759b06fe436b5043e25d628153eb6e372ede64 100644 (file)
@@ -65,8 +65,8 @@ struct libmv_trackRegionResult {
   double correlation;
 };
 int libmv_trackRegion(const struct libmv_trackRegionOptions *options,
-                      const float *image1, const float *image2,
-                      int width, int height, 
+                      const float *image1, int image1_width, int image1_height,
+                      const float *image2, int image2_width, int image2_height,
                       const double *x1, const double *y1,
                       struct libmv_trackRegionResult *result,
                       double *x2, double *y2);
index a13674cd6e5baaf1505395c057683da83f9f7855..716b65408e10706954e9d1ee3315296cd1347215 100644 (file)
@@ -57,7 +57,7 @@ struct MovieTrackingMarker *BKE_tracking_insert_marker(struct MovieTrackingTrack
                                                        struct MovieTrackingMarker *marker);
 void BKE_tracking_delete_marker(struct MovieTrackingTrack *track, int framenr);
 
-void BKE_tracking_marker_pattern_minmax(struct MovieTrackingMarker *marker, float min[2], float max[2]);
+void BKE_tracking_marker_pattern_minmax(const struct MovieTrackingMarker *marker, float min[2], float max[2]);
 struct MovieTrackingMarker *BKE_tracking_get_marker(struct MovieTrackingTrack *track, int framenr);
 struct MovieTrackingMarker *BKE_tracking_ensure_marker(struct MovieTrackingTrack *track, int framenr);
 struct MovieTrackingMarker *BKE_tracking_exact_marker(struct MovieTrackingTrack *track, int framenr);
index a3d66012303cf4ead9f53a0d57b9a06be98b4952..4cfa8461f2e399f0568202fd6f7bbc6a72c27c8d 100644 (file)
@@ -440,7 +440,7 @@ void BKE_tracking_delete_marker(MovieTrackingTrack *track, int framenr)
        }
 }
 
-void BKE_tracking_marker_pattern_minmax(MovieTrackingMarker *marker, float min[2], float max[2])
+void BKE_tracking_marker_pattern_minmax(const MovieTrackingMarker *marker, float min[2], float max[2])
 {
        INIT_MINMAX2(min, max);
 
@@ -1606,6 +1606,25 @@ static ImBuf *get_adjust_ibuf(MovieTrackingContext *context, MovieTrackingTrack
        return ibuf;
 }
 
+static void marker_search_scale_after_tracking(const MovieTrackingMarker *old_marker, MovieTrackingMarker *new_marker)
+{
+       float old_pat_min[2], old_pat_max[2];
+       float new_pat_min[2], new_pat_max[2];
+       float scale_x, scale_y;
+
+       BKE_tracking_marker_pattern_minmax(old_marker, old_pat_min, old_pat_max);
+       BKE_tracking_marker_pattern_minmax(new_marker, new_pat_min, new_pat_max);
+
+       scale_x = (new_pat_max[0] - new_pat_min[0]) / (old_pat_max[0] - old_pat_min[0]);
+       scale_y = (new_pat_max[1] - new_pat_min[1]) / (old_pat_max[1] - old_pat_min[1]);
+
+       new_marker->search_min[0] *= scale_x;
+       new_marker->search_min[1] *= scale_y;
+
+       new_marker->search_max[0] *= scale_x;
+       new_marker->search_max[1] *= scale_y;
+}
+
 #endif
 
 void BKE_tracking_sync(MovieTrackingContext *context)
@@ -1752,8 +1771,10 @@ int BKE_tracking_next(MovieTrackingContext *context)
 
                                /* Run the tracker! */
                                tracked = libmv_trackRegion(&options,
-                                                           track_context->search_area, patch_new,
-                                                           width, height,
+                                                           track_context->search_area,
+                                                                                       track_context->search_area_width,
+                                                                                       track_context->search_area_height,
+                                                                                       patch_new, width, height,
                                                            src_pixel_x, src_pixel_y,
                                                            &result,
                                                            dst_pixel_x, dst_pixel_y);
@@ -1767,6 +1788,8 @@ int BKE_tracking_next(MovieTrackingContext *context)
                                marker_new.flag |= MARKER_TRACKED;
                                marker_new.framenr = nextfra;
 
+                               marker_search_scale_after_tracking(marker, &marker_new);
+
                                #pragma omp critical
                                {
                                        if (context->first_time) {