[Bf-blender-cvs] [b167720] master: Rework 2D stabilizator

Ichthyostega noreply at git.blender.org
Tue Aug 16 13:52:20 CEST 2016


Commit: b1677201f9af7a3e5f5254817179f12384fbdc44
Author: Ichthyostega
Date:   Tue Aug 16 10:32:55 2016 +0200
Branches: master
https://developer.blender.org/rBb1677201f9af7a3e5f5254817179f12384fbdc44

Rework 2D stabilizator

See this page for motivation and description of concepts:
https://github.com/Ichthyostega/blender/wiki

See this video for UI explanation and demonstration of usage
http://vimeo.com/blenderHack/stabilizerdemo

This proposal attempts to improve usability of Blender's image stabilization
feature for real-world footage esp. with moving and panning camera. It builds
upon the feature tracking to get a measurement of 2D image movement.

  - Use a weighted average of movement contributions (instead of a median).
  - Allow for rotation compensation and zoom (image scale) compensation.
  - Allow to pick a different set of tracks for translation and for
    rotation/zoom.
  - Treat translation / rotation / zoom contributions systematically in a
    similar way.
  - Improve handling of partial tracking data with gaps and varying
    start / end points.
  - Have a user definable anchor frame and interpolate / extrapolate data to
    avoid jumping back to "neutral" position when no tracking data is available.
  - Support for travelling and panning shots by including an //intended//
    position/rotation/zoom ("target position"). The idea is for these parameters
    to be //animated// by the user, in order to supply an smooth, intended
    camera movement. This way, we can keep the image content roughly in frame
    even when moving completely away from the initial view.

A known shortcoming is that the pivot point for rotation compensation is set to
the translation compensated image center. This can produce spurious rotation on
travelling shots, which needs to be compensated manually (by animating the
target rotation parameter). There are several possible ways to address that
problem, yet all of them are considered beyond the scope of this improvement
proposal for now.

Own modifications:

- Restrict line length, it's really handy for split-view editing
- In motion tracking we prefer fully human-readable comments, meaning we
  don't use doxygen with it's weird markup and comments are supposed to
  start with capital and end with a full stop,
- Add explicit comparison of pointer to NULL.

Reviewers: sergey

Subscribers: kusi, kdawg, forest-house, mardy, Samoth, plasmasolutions, willolis, sebastian_k, hype, enetheru, sunboy, jta, leon_cheung

Maniphest Tasks: T49036

Differential Revision: https://developer.blender.org/D583

===================================================================

M	release/scripts/startup/bl_ui/space_clip.py
M	source/blender/blenkernel/BKE_tracking.h
M	source/blender/blenkernel/intern/movieclip.c
M	source/blender/blenkernel/intern/tracking.c
M	source/blender/blenkernel/intern/tracking_stabilize.c
M	source/blender/blenloader/intern/readfile.c
M	source/blender/blenloader/intern/versioning_270.c
M	source/blender/compositor/nodes/COM_MovieClipNode.cpp
M	source/blender/compositor/operations/COM_MovieClipAttributeOperation.cpp
M	source/blender/editors/space_clip/clip_intern.h
M	source/blender/editors/space_clip/clip_utils.c
M	source/blender/editors/space_clip/space_clip.c
M	source/blender/editors/space_clip/tracking_ops.c
M	source/blender/editors/space_clip/tracking_ops_stabilize.c
M	source/blender/makesdna/DNA_tracking_types.h
M	source/blender/makesrna/RNA_access.h
M	source/blender/makesrna/intern/rna_tracking.c

===================================================================

diff --git a/release/scripts/startup/bl_ui/space_clip.py b/release/scripts/startup/bl_ui/space_clip.py
index 799f1e2..9b1c0a1 100644
--- a/release/scripts/startup/bl_ui/space_clip.py
+++ b/release/scripts/startup/bl_ui/space_clip.py
@@ -621,6 +621,7 @@ class CLIP_PT_track(CLIP_PT_tracking_panel, Panel):
                  text="", toggle=True, icon='IMAGE_ALPHA')
 
         layout.prop(act_track, "weight")
+        layout.prop(act_track, "weight_stab")
 
         if act_track.has_bundle:
             label_text = "Average Error: %.4f" % (act_track.average_error)
@@ -907,44 +908,80 @@ class CLIP_PT_stabilization(CLIP_PT_reconstruction_panel, Panel):
         self.layout.prop(stab, "use_2d_stabilization", text="")
 
     def draw(self, context):
-        layout = self.layout
-
         tracking = context.space_data.clip.tracking
         stab = tracking.stabilization
 
+        layout = self.layout
         layout.active = stab.use_2d_stabilization
 
-        row = layout.row()
-        row.template_list("UI_UL_list", "stabilization_tracks", stab, "tracks",
-                          stab, "active_track_index", rows=2)
+        layout.prop(stab, "anchor_frame")
 
-        sub = row.column(align=True)
+        box = layout.box()
+        row = box.row(align=True)
+        row.prop(stab, "show_tracks_expanded", text="", emboss=False)
+
+        if not stab.show_tracks_expanded:
+            row.label(text="Tracks For Stabilization")
+        else:
+            row.label(text="Tracks For Location")
+            row = box.row()
+            row.template_list("UI_UL_list", "stabilization_tracks", stab, "tracks",
+                              stab, "active_track_index", rows=2)
 
-        sub.operator("clip.stabilize_2d_add", icon='ZOOMIN', text="")
-        sub.operator("clip.stabilize_2d_remove", icon='ZOOMOUT', text="")
+            sub = row.column(align=True)
 
-        sub.menu('CLIP_MT_stabilize_2d_specials', text="",
-                 icon='DOWNARROW_HLT')
+            sub.operator("clip.stabilize_2d_add", icon='ZOOMIN', text="")
+            sub.operator("clip.stabilize_2d_remove", icon='ZOOMOUT', text="")
 
-        layout.prop(stab, "influence_location")
+            sub.menu('CLIP_MT_stabilize_2d_specials', text="",
+                     icon='DOWNARROW_HLT')
 
-        layout.prop(stab, "use_autoscale")
-        col = layout.column()
-        col.active = stab.use_autoscale
-        col.prop(stab, "scale_max")
-        col.prop(stab, "influence_scale")
+            row = box.row()
+            row.label(text="Tracks For Rotation / Scale")
+            row = box.row()
+            row.active = stab.use_stabilize_rotation
+            row.template_list("UI_UL_list", "stabilization_rotation_tracks", stab, "rotation_tracks",
+                              stab, "active_rotation_track_index", rows=2)
+
+            sub = row.column(align=True)
+
+            sub.operator("clip.stabilize_2d_rotation_add", icon='ZOOMIN', text="")
+            sub.operator("clip.stabilize_2d_rotation_remove", icon='ZOOMOUT', text="")
+
+            sub.menu('CLIP_MT_stabilize_2d_rotation_specials', text="",
+                     icon='DOWNARROW_HLT')
 
         layout.prop(stab, "use_stabilize_rotation")
-        col = layout.column()
-        col.active = stab.use_stabilize_rotation
+        row = layout.row()
+        row.active = stab.use_stabilize_rotation
+        row.prop(stab, "use_stabilize_scale")
+        if stab.use_autoscale:
+            row = layout.row(align=True)
+            row.prop(stab, "use_autoscale")
+            row.prop(stab, "scale_max", text="Max")
+        else:
+            layout.prop(stab, "use_autoscale")
 
-        row = col.row(align=True)
-        row.prop_search(stab, "rotation_track", tracking, "tracks", text="")
-        row.operator("clip.stabilize_2d_set_rotation", text="", icon='ZOOMIN')
+        layout.separator()
+        layout.label(text="Expected Position")
+        layout.prop(stab, "target_pos", text="")
+        layout.prop(stab, "target_rot")
+        if stab.use_autoscale:
+            layout.label(text="Auto Scale Factor: %5.3f" % (1.0 / stab.target_zoom))
+        else:
+            layout.prop(stab, "target_zoom")
 
+        layout.separator()
+        row = layout.row()
+        row.active = 0 < len(stab.tracks.values())
+        row.prop(stab, "influence_location")
+
+        col = layout.column()
+        col.active = stab.use_stabilize_rotation and 0 < len(stab.rotation_tracks.values())
         row = col.row()
-        row.active = stab.rotation_track is not None
         row.prop(stab, "influence_rotation")
+        row = col.row()
+        row.prop(stab, "influence_scale")
 
         layout.prop(stab, "filter_type")
 
@@ -1434,7 +1471,7 @@ class CLIP_MT_track_color_specials(Menu):
 
 
 class CLIP_MT_stabilize_2d_specials(Menu):
-    bl_label = "Track Color Specials"
+    bl_label = "Translation Track Specials"
 
     def draw(self, context):
         layout = self.layout
@@ -1442,5 +1479,14 @@ class CLIP_MT_stabilize_2d_specials(Menu):
         layout.operator("clip.stabilize_2d_select")
 
 
+class CLIP_MT_stabilize_2d_rotation_specials(Menu):
+    bl_label = "Rotation Track Specials"
+
+    def draw(self, context):
+        layout = self.layout
+
+        layout.operator("clip.stabilize_2d_rotation_select")
+
+
 if __name__ == "__main__":  # only for live edit.
     bpy.utils.register_module(__name__)
diff --git a/source/blender/blenkernel/BKE_tracking.h b/source/blender/blenkernel/BKE_tracking.h
index 1938bb0..3087356 100644
--- a/source/blender/blenkernel/BKE_tracking.h
+++ b/source/blender/blenkernel/BKE_tracking.h
@@ -277,9 +277,9 @@ void BKE_tracking_detect_harris(struct MovieTracking *tracking, struct ListBase
                                 bool place_outside_layer);
 
 /* **** 2D stabilization **** */
-void BKE_tracking_stabilization_data_get(struct MovieTracking *tracking, int framenr, int width, int height,
+void BKE_tracking_stabilization_data_get(struct MovieClip *clip, int framenr, int width, int height,
                                          float translation[2], float *scale, float *angle);
-struct ImBuf *BKE_tracking_stabilize_frame(struct MovieTracking *tracking, int framenr, struct ImBuf *ibuf,
+struct ImBuf *BKE_tracking_stabilize_frame(struct MovieClip *clip, int framenr, struct ImBuf *ibuf,
                                            float translation[2], float *scale, float *angle);
 void BKE_tracking_stabilization_data_to_mat4(int width, int height, float aspect, float translation[2],
                                              float scale, float angle, float mat[4][4]);
diff --git a/source/blender/blenkernel/intern/movieclip.c b/source/blender/blenkernel/intern/movieclip.c
index 0d36208..482015d 100644
--- a/source/blender/blenkernel/intern/movieclip.c
+++ b/source/blender/blenkernel/intern/movieclip.c
@@ -1033,7 +1033,7 @@ static ImBuf *get_stable_cached_frame(MovieClip *clip, MovieClipUser *user, ImBu
 
 	stableibuf = cache->stabilized.ibuf;
 
-	BKE_tracking_stabilization_data_get(&clip->tracking, clip_framenr, stableibuf->x, stableibuf->y, tloc, &tscale, &tangle);
+	BKE_tracking_stabilization_data_get(clip, clip_framenr, stableibuf->x, stableibuf->y, tloc, &tscale, &tangle);
 
 	/* check for stabilization parameters */
 	if (tscale != cache->stabilized.scale ||
@@ -1057,7 +1057,7 @@ static ImBuf *put_stabilized_frame_to_cache(MovieClip *clip, MovieClipUser *user
 	float tloc[2], tscale, tangle;
 	int clip_framenr = BKE_movieclip_remap_scene_to_clip_frame(clip, framenr);
 
-	stableibuf = BKE_tracking_stabilize_frame(&clip->tracking, clip_framenr, ibuf, tloc, &tscale, &tangle);
+	stableibuf = BKE_tracking_stabilize_frame(clip, clip_framenr, ibuf, tloc, &tscale, &tangle);
 
 	copy_v2_v2(cache->stabilized.loc, tloc);
 
@@ -1270,8 +1270,6 @@ void BKE_movieclip_reload(MovieClip *clip)
 	/* clear cache */
 	free_buffers(clip);
 
-	clip->tracking.stabilization.ok = false;
-
 	/* update clip source */
 	detect_clip_source(clip);
 
diff --git a/source/blender/blenkernel/intern/tracking.c b/source/blender/blenkernel/intern/tracking.c
index a56fc0f..d5d3384 100644
--- a/source/blender/blenkernel/intern/tracking.c
+++ b/source/blender/blenkernel/intern/tracking.c
@@ -241,13 +241,9 @@ static void tracking_reconstruction_copy(
 
 /* Copy stabilization structure. */
 static void tracking_stabilization_copy(
-        MovieTrackingStabilization *stabilization_dst, MovieTrackingStabilization *stabilization_src,
-        GHash *tracks_mapping)
+        MovieTrackingStabilization *stabilization_dst, MovieTrackingStabilization *stabilization_src)
 {
 	*stabilization_dst = *stabilization_src;
-	if (stabilization_src->rot_track) {
-		stabilization_dst->rot_track = BLI_ghash_lookup(tracks_mapping, stabilization_src->rot_track);
-	}
 }
 
 /* Copy tracking object. */
@@ -284,7 +280,7 @@ void BKE_tracking_copy(MovieTracking *tracking_dst, MovieTracking *tracking_src)
 	tracking_tracks_copy(&tracking_dst->tracks, &tracking_src->tracks, tracks_mapping);
 	tracking_plane_tracks_copy(&tracking_dst->plane_tracks, &tracking_src->plane_tracks, tracks_mapping);
 	tracking_reconstruction_copy(&tracking_dst->reconstruction, &tracking_src->reconstruction);
-	tracking_stabilization_copy(&tracking_dst->stabilization, &tracking_src->stabilization, tracks_mapping);
+	tracking_stabilization_copy(&tracking_dst->stabilization, &tracking_src->stabilization);
 	if (tracking_src->act_track) {
 		tracking_dst->act_track = BLI_ghash_lookup(tracks_mapping, tracking_src->act_track);
 	}
@@ -316,7 +312,7 @@ void BKE_tracking_copy(MovieTracking *tracking_dst, MovieTracking *tracking_src)
 }
 
 /* Initialize motion tracking settings to default values,
- * used when new movie clip datablock is creating.
+ * used when new movie clip datablock is created.
  */
 void BKE_tracking_settings_init(MovieTracking *tracking)
 {
@@ -334,10 +330,22 @@ void BKE_tracking_settings_init(MovieTracking *tracking)
 	tracking->settings.object_distance = 1;
 
 	tracking->stabilization.scaleinf = 1.0f;
+	tracking->stabilization.anchor_frame = MINFRAME;
+	zero_v2(tracking->stabilization.target_pos);
+	tracking->stabilization.target_rot = 0.0f;
+	tra

@@ Diff output truncated at 10240 characters. @@




More information about the Bf-blender-cvs mailing list