[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [47638] branches/soc-2011-tomato: Homography correction for track preview widget

Sergey Sharybin sergey.vfx at gmail.com
Sat Jun 9 13:14:54 CEST 2012


Revision: 47638
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=47638
Author:   nazgul
Date:     2012-06-09 11:14:36 +0000 (Sat, 09 Jun 2012)
Log Message:
-----------
Homography correction for track preview widget

Use homography transformation for pattern displayed in track preview widget.
Sampling of this pattern happens to resolution of preview widget itself,
which implied some bigger changes in how scopes are working:

- Instead of real pattern store search area in BKE_movieclip_update_scopes,
  which is later used for sampling pattern.
- Sampling of pattern happens in ui_draw_but_TRACKPREVIEW from search area
  which allows to sample it to actual resolution of preview widget.
- If size of preview widget is not changing, this sampled pattern wouldn't
  be re-sampled until scopes are tagged to update.

There are some issues with pattern sampling which seems to happen SamplePlanarPatch,
changing linear sampling to nearest removes that unwanted 1px offset.

Left commented saving of sampled image in ui_draw_but_TRACKPREVIEW which should
help figuring the issue out.

Modified Paths:
--------------
    branches/soc-2011-tomato/extern/libmv/libmv/tracking/track_region.cc
    branches/soc-2011-tomato/extern/libmv/libmv/tracking/track_region.h
    branches/soc-2011-tomato/extern/libmv/libmv-capi.cpp
    branches/soc-2011-tomato/extern/libmv/libmv-capi.h
    branches/soc-2011-tomato/source/blender/blenkernel/BKE_tracking.h
    branches/soc-2011-tomato/source/blender/blenkernel/intern/movieclip.c
    branches/soc-2011-tomato/source/blender/blenkernel/intern/tracking.c
    branches/soc-2011-tomato/source/blender/blenloader/intern/readfile.c
    branches/soc-2011-tomato/source/blender/compositor/operations/COM_KeyingScreenOperation.cpp
    branches/soc-2011-tomato/source/blender/editors/interface/interface_draw.c
    branches/soc-2011-tomato/source/blender/editors/space_clip/space_clip.c
    branches/soc-2011-tomato/source/blender/makesdna/DNA_movieclip_types.h
    branches/soc-2011-tomato/source/blender/nodes/composite/nodes/node_composite_keyingscreen.c

Modified: branches/soc-2011-tomato/extern/libmv/libmv/tracking/track_region.cc
===================================================================
--- branches/soc-2011-tomato/extern/libmv/libmv/tracking/track_region.cc	2012-06-09 10:12:01 UTC (rev 47637)
+++ branches/soc-2011-tomato/extern/libmv/libmv/tracking/track_region.cc	2012-06-09 11:14:36 UTC (rev 47638)
@@ -1252,7 +1252,8 @@
 bool SamplePlanarPatch(const FloatImage &image,
                        const double *xs, const double *ys,
                        int num_samples_x, int num_samples_y,
-                       FloatImage *patch) {
+                       FloatImage *patch,
+                       double *warped_position_x, double *warped_position_y) {
   // Bail early if the points are outside the image.
   if (!AllInBounds(image, xs, ys)) {
     LG << "Can't sample patch: out of bounds.";
@@ -1278,6 +1279,13 @@
                    &(*patch)(r, c, 0));
     }
   }
+
+  Vec3 warped_position = canonical_homography.inverse() * Vec3(xs[4], ys[4], 1);
+  warped_position /= warped_position(2);
+
+  *warped_position_x = warped_position(0);
+  *warped_position_y = warped_position(1);
+
   return true;
 }
 

Modified: branches/soc-2011-tomato/extern/libmv/libmv/tracking/track_region.h
===================================================================
--- branches/soc-2011-tomato/extern/libmv/libmv/tracking/track_region.h	2012-06-09 10:12:01 UTC (rev 47637)
+++ branches/soc-2011-tomato/extern/libmv/libmv/tracking/track_region.h	2012-06-09 11:14:36 UTC (rev 47638)
@@ -121,7 +121,8 @@
 bool SamplePlanarPatch(const FloatImage &image,
                        const double *xs, const double *ys,
                        int num_samples_x, int num_samples_y,
-                       FloatImage *patch);
+                       FloatImage *patch,
+                       double *warped_position_x, double *warped_position_y);
 
 }  // namespace libmv
 

Modified: branches/soc-2011-tomato/extern/libmv/libmv-capi.cpp
===================================================================
--- branches/soc-2011-tomato/extern/libmv/libmv-capi.cpp	2012-06-09 10:12:01 UTC (rev 47637)
+++ branches/soc-2011-tomato/extern/libmv/libmv-capi.cpp	2012-06-09 11:14:36 UTC (rev 47638)
@@ -163,19 +163,34 @@
 	return (libmv_RegionTracker *)brute_region_tracker;
 }
 
-static void floatBufToImage(const float *buf, int width, int height, libmv::FloatImage *image)
+static void floatBufToImage(const float *buf, int width, int height, int channels, libmv::FloatImage *image)
 {
-	int x, y, a = 0;
+	int x, y, k, a = 0;
 
-	image->resize(height, width);
+	image->Resize(height, width, channels);
 
 	for (y = 0; y < height; y++) {
 		for (x = 0; x < width; x++) {
-			(*image)(y, x, 0) = buf[a++];
+			for (k = 0; k < channels; k++) {
+				(*image)(y, x, k) = buf[a++];
+			}
 		}
 	}
 }
 
+static void imageToFloatBuf(const libmv::FloatImage *image, int channels, float *buf)
+{
+	int x, y, k, a = 0;
+
+	for (y = 0; y < image->Height(); y++) {
+		for (x = 0; x < image->Width(); x++) {
+			for (k = 0; k < channels; k++) {
+				buf[a++] = (*image)(y, x, k);
+			}
+		}
+	}
+}
+
 #if defined(DUMP_FAILURE) || defined (DUMP_ALWAYS)
 void savePNGImage(png_bytep *row_pointers, int width, int height, int depth, int color_type, char *file_name)
 {
@@ -307,8 +322,8 @@
 	libmv::RegionTracker *region_tracker = (libmv::RegionTracker *)libmv_tracker;
 	libmv::FloatImage old_patch, new_patch;
 
-	floatBufToImage(ima1, width, height, &old_patch);
-	floatBufToImage(ima2, width, height, &new_patch);
+	floatBufToImage(ima1, width, height, 1, &old_patch);
+	floatBufToImage(ima2, width, height, 1, &new_patch);
 
 #if !defined(DUMP_FAILURE) && !defined(DUMP_ALWAYS)
 	return region_tracker->Track(old_patch, new_patch, x1, y1, x2, y2);
@@ -385,8 +400,8 @@
 
 	/* Convert from raw float buffers to libmv's FloatImage. */
 	libmv::FloatImage old_patch, new_patch;
-	floatBufToImage(image1, width, height, &old_patch);
-	floatBufToImage(image2, width, height, &new_patch);
+	floatBufToImage(image1, width, height, 1, &old_patch);
+	floatBufToImage(image2, width, 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);
@@ -420,6 +435,21 @@
 	return tracking_result;
 }
 
+void libmv_samplePlanarPatch(const float *image, int width, int height,
+                             int channels, const double *xs, const double *ys,
+                             int num_samples_x, int num_samples_y, float *patch,
+                             double *warped_position_x, double *warped_position_y)
+{
+	libmv::FloatImage libmv_image, libmv_patch;
+
+	floatBufToImage(image, width, height, channels, &libmv_image);
+
+	libmv::SamplePlanarPatch(libmv_image, xs, ys, num_samples_x, num_samples_y,
+	                         &libmv_patch, warped_position_x, warped_position_y);
+
+	imageToFloatBuf(&libmv_patch, channels, patch);
+}
+
 /* ************ Tracks ************ */
 
 libmv_Tracks *libmv_tracksNew(void)

Modified: branches/soc-2011-tomato/extern/libmv/libmv-capi.h
===================================================================
--- branches/soc-2011-tomato/extern/libmv/libmv-capi.h	2012-06-09 10:12:01 UTC (rev 47637)
+++ branches/soc-2011-tomato/extern/libmv/libmv-capi.h	2012-06-09 11:14:36 UTC (rev 47638)
@@ -71,6 +71,11 @@
                       struct libmv_trackRegionResult *result,
                       double *x2, double *y2);
 
+void libmv_samplePlanarPatch(const float *image, int width, int height,
+                             int channels, const double *xs, const double *ys,
+                             int num_samples_x, int num_samples_y, float *patch,
+                             double *warped_position_x, double *warped_position_y);
+
 /* Tracks */
 struct libmv_Tracks *libmv_tracksNew(void);
 void libmv_tracksInsert(struct libmv_Tracks *libmv_tracks, int image, int track, double x, double y);

Modified: branches/soc-2011-tomato/source/blender/blenkernel/BKE_tracking.h
===================================================================
--- branches/soc-2011-tomato/source/blender/blenkernel/BKE_tracking.h	2012-06-09 10:12:01 UTC (rev 47637)
+++ branches/soc-2011-tomato/source/blender/blenkernel/BKE_tracking.h	2012-06-09 11:14:36 UTC (rev 47638)
@@ -71,13 +71,13 @@
 void BKE_tracking_join_tracks(struct MovieTrackingTrack *dst_track, struct MovieTrackingTrack *src_track);
 void BKE_tracking_free(struct MovieTracking *tracking);
 
+struct ImBuf *BKE_tracking_sample_pattern_imbuf(int frame_width, int frame_height,
+                                                struct ImBuf *struct_ibuf, struct MovieTrackingMarker *marker,
+                                                int num_samples_x, int num_samples_y, float pos[2]);
 struct ImBuf *BKE_tracking_get_pattern_imbuf(struct ImBuf *ibuf, struct MovieTrackingTrack *track,
-                                             struct MovieTrackingMarker *marker, int margin, int anchored,
-                                             float pos[2], int origin[2]);
-struct ImBuf *BKE_tracking_get_pattern_color_imbuf(struct ImBuf *ibuf, struct MovieTrackingTrack *track,
-                                                   struct MovieTrackingMarker *marker, int anchored);
+                                             struct MovieTrackingMarker *marker, int anchored, int disable_channels);
 struct ImBuf *BKE_tracking_get_search_imbuf(struct ImBuf *ibuf, struct MovieTrackingTrack *track,
-                                            struct MovieTrackingMarker *marker);
+                                            struct MovieTrackingMarker *marker, int anchored, int disable_channels);
 struct ImBuf *BKE_tracking_track_mask_get(struct MovieTracking *tracking, struct MovieTrackingTrack *track,
                                           struct MovieTrackingMarker *marker, int width, int height);
 

Modified: branches/soc-2011-tomato/source/blender/blenkernel/intern/movieclip.c
===================================================================
--- branches/soc-2011-tomato/source/blender/blenkernel/intern/movieclip.c	2012-06-09 10:12:01 UTC (rev 47637)
+++ branches/soc-2011-tomato/source/blender/blenkernel/intern/movieclip.c	2012-06-09 11:14:36 UTC (rev 47638)
@@ -1032,6 +1032,11 @@
 		scopes->track_preview = NULL;
 	}
 
+	if (scopes->track_search) {
+		IMB_freeImBuf(scopes->track_search);
+		scopes->track_search = NULL;
+	}
+
 	scopes->marker = NULL;
 	scopes->track = NULL;
 
@@ -1052,7 +1057,7 @@
 				scopes->track_disabled = FALSE;
 
 				if (ibuf && (ibuf->rect || ibuf->rect_float)) {
-					ImBuf *tmpibuf;
+					ImBuf *search_ibuf;
 					MovieTrackingMarker undist_marker = *marker;
 
 					if (user->render_flag & MCLIP_PROXY_RENDER_UNDISTORT) {
@@ -1070,17 +1075,18 @@
 						undist_marker.pos[1] /= height * aspy;
 					}
 
-					/* NOTE: margin should be kept in sync with value from ui_draw_but_TRACKPREVIEW */
-					tmpibuf = BKE_tracking_get_pattern_imbuf(ibuf, track, &undist_marker, 3 /* margin */,
-					                                         1 /* anchor */, scopes->track_pos, NULL);
+					search_ibuf = BKE_tracking_get_search_imbuf(ibuf, track, &undist_marker, TRUE, TRUE);
 
-					if (tmpibuf->rect_float)
-						IMB_rect_from_float(tmpibuf);
+					if (!search_ibuf->rect_float) {
+						/* sampling happens in float buffer */
+						IMB_float_from_rect(search_ibuf);
+					}
 
-					if (tmpibuf->rect)
-						scopes->track_preview = tmpibuf;
-					else
-						IMB_freeImBuf(tmpibuf);
+					scopes->undist_marker = undist_marker;
+					scopes->track_search = search_ibuf;
+
+					scopes->frame_width = ibuf->x;
+					scopes->frame_height = ibuf->y;
 				}
 
 				IMB_freeImBuf(ibuf);

Modified: branches/soc-2011-tomato/source/blender/blenkernel/intern/tracking.c
===================================================================
--- branches/soc-2011-tomato/source/blender/blenkernel/intern/tracking.c	2012-06-09 10:12:01 UTC (rev 47637)
+++ branches/soc-2011-tomato/source/blender/blenkernel/intern/tracking.c	2012-06-09 11:14:36 UTC (rev 47638)
@@ -84,10 +84,11 @@
  * window relative coordinates in pixels, and "frame_unified" are unified 0..1
  * coordinates relative to the entire frame.
  */
-static void unified_to_pixel(const ImBuf *ibuf, const float unified_coords[2], float pixel_coords[2])
+static void unified_to_pixel(int frame_width, int frame_height,

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list