Camera tracking presets
authorSergey Sharybin <sergey.vfx@gmail.com>
Sat, 4 Aug 2012 10:47:31 +0000 (10:47 +0000)
committerSergey Sharybin <sergey.vfx@gmail.com>
Sat, 4 Aug 2012 10:47:31 +0000 (10:47 +0000)
- Fix for copy default settings from active track operator
- Add meaningful tracking presets

API changes:

- Added parameter exact to Marker.find_frame, so now it's
  possible to get estimated marker

- Added Marker.pattern_bound_box to get pattern's bound box

release/scripts/presets/tracking_settings/blurry_footage.py
release/scripts/presets/tracking_settings/blurry_movie.py [deleted file]
release/scripts/presets/tracking_settings/default.py
release/scripts/presets/tracking_settings/fast_motion.py
release/scripts/presets/tracking_settings/planar.py [new file with mode: 0644]
release/scripts/startup/bl_operators/clip.py
release/scripts/startup/bl_operators/presets.py
release/scripts/startup/bl_ui/space_clip.py
source/blender/makesrna/intern/rna_movieclip.c
source/blender/makesrna/intern/rna_tracking.c

index f2df4a15320ab756f0bd356472f9f5aceecc4aa7..0423f7662a2194a82106e1d12ed40d01a135f18e 100644 (file)
@@ -1,12 +1,17 @@
 import bpy
 settings = bpy.context.edit_movieclip.tracking.settings
 
-settings.default_correlation_min = 0.75
-settings.default_pattern_size = 21
-settings.default_search_size = 100
+
+settings.default_pattern_size = 31
+settings.default_search_size = 91
+settings.default_motion_model = 'Loc'
+settings.use_default_brute = True
+settings.use_default_normalization = False
+settings.use_default_mask = False
 settings.default_frames_limit = 0
 settings.default_pattern_match = 'PREV_FRAME'
 settings.default_margin = 0
 settings.use_default_red_channel = True
 settings.use_default_green_channel = True
 settings.use_default_blue_channel = True
+settings.default_correlation_min = 0.6
\ No newline at end of file
diff --git a/release/scripts/presets/tracking_settings/blurry_movie.py b/release/scripts/presets/tracking_settings/blurry_movie.py
deleted file mode 100644 (file)
index fe68f13..0000000
+++ /dev/null
@@ -1,9 +0,0 @@
-import bpy
-settings = bpy.context.edit_movieclip.tracking.settings
-
-settings.default_correlation_min = 0.75
-settings.default_pattern_size = 11
-settings.default_search_size = 202
-settings.default_frames_limit = 25
-settings.default_pattern_match = 'KEYFRAME'
-settings.default_margin = 0
index 0cc3a21c845f81cabe1a748f43d28e421b98f599..0aef22195e732239c58d47c9f5edb469625f4205 100644 (file)
@@ -1,12 +1,17 @@
 import bpy
 settings = bpy.context.edit_movieclip.tracking.settings
 
-settings.default_correlation_min = 0.75
-settings.default_pattern_size = 11
-settings.default_search_size = 61
+
+settings.default_pattern_size = 15
+settings.default_search_size = 51
+settings.default_motion_model = 'Loc'
+settings.use_default_brute = True
+settings.use_default_normalization = False
+settings.use_default_mask = False
 settings.default_frames_limit = 0
 settings.default_pattern_match = 'KEYFRAME'
 settings.default_margin = 0
 settings.use_default_red_channel = True
 settings.use_default_green_channel = True
 settings.use_default_blue_channel = True
+settings.default_correlation_min = 0.75
\ No newline at end of file
index 5e6e44e6a4204ed30149cb77243eea86d9074c2c..f7f6b37db74a5539c21fdebba5d91fd9753712dc 100644 (file)
@@ -1,12 +1,17 @@
 import bpy
 settings = bpy.context.edit_movieclip.tracking.settings
 
-settings.default_correlation_min = 0.7
+
 settings.default_pattern_size = 31
-settings.default_search_size = 300
+settings.default_search_size = 151
+settings.default_motion_model = 'LocRot'
+settings.use_default_brute = True
+settings.use_default_normalization = True
+settings.use_default_mask = False
 settings.default_frames_limit = 0
 settings.default_pattern_match = 'PREV_FRAME'
-settings.default_margin = 5
+settings.default_margin = 0
 settings.use_default_red_channel = True
 settings.use_default_green_channel = True
 settings.use_default_blue_channel = True
+settings.default_correlation_min = 0.6
\ No newline at end of file
diff --git a/release/scripts/presets/tracking_settings/planar.py b/release/scripts/presets/tracking_settings/planar.py
new file mode 100644 (file)
index 0000000..b25df1f
--- /dev/null
@@ -0,0 +1,17 @@
+import bpy
+settings = bpy.context.edit_movieclip.tracking.settings
+
+
+settings.default_pattern_size = 41
+settings.default_search_size = 91
+settings.default_motion_model = 'Perspective'
+settings.use_default_brute = False
+settings.use_default_normalization = False
+settings.use_default_mask = False
+settings.default_frames_limit = 0
+settings.default_pattern_match = 'KEYFRAME'
+settings.default_margin = 0
+settings.use_default_red_channel = True
+settings.use_default_green_channel = True
+settings.use_default_blue_channel = True
+settings.default_correlation_min = 0.75
\ No newline at end of file
index a30502b454e0398486400a743bac522c9bea5334..c45d2f2e7022e7801693a1691b76596008dcbd96 100644 (file)
@@ -90,14 +90,17 @@ def CLIP_track_view_selected(sc, track):
     return False
 
 
-def CLIP_default_settings_from_track(clip, track):
+def CLIP_default_settings_from_track(clip, track, framenr):
     settings = clip.tracking.settings
 
     width = clip.size[0]
     height = clip.size[1]
 
-    pattern = track.pattern_max - track.pattern_min
-    search = track.search_max - track.search_min
+    marker = track.markers.find_frame(framenr, False)
+    pattern_bb = marker.pattern_bound_box
+
+    pattern = Vector(pattern_bb[1]) - Vector(pattern_bb[0])
+    search = marker.search_max - marker.search_min
 
     pattern[0] = pattern[0] * width
     pattern[1] = pattern[1] * height
@@ -111,6 +114,10 @@ def CLIP_default_settings_from_track(clip, track):
     settings.default_frames_limit = track.frames_limit
     settings.default_pattern_match = track.pattern_match
     settings.default_margin = track.margin
+    settings.default_motion_model = track.motion_model
+    settings.use_default_brute = track.use_brute
+    settings.use_default_normalization = track.use_normalization
+    settings.use_default_mask = track.use_mask
     settings.use_default_red_channel = track.use_red_channel
     settings.use_default_green_channel = track.use_green_channel
     settings.use_default_blue_channel = track.use_blue_channel
@@ -862,6 +869,9 @@ class CLIP_OT_track_settings_as_default(Operator):
         sc = context.space_data
         clip = sc.clip
 
-        CLIP_default_settings_from_track(clip, clip.tracking.tracks.active)
+        track = clip.tracking.tracks.active
+        framenr = context.scene.frame_current - clip.frame_start + 1
+
+        CLIP_default_settings_from_track(clip, track, framenr)
 
         return {'FINISHED'}
index 05f76208a5f60eb49bd4670149f84e2071905e9b..db492450e28ee42b68f48b9dcca3fc09f605a7fe 100644 (file)
@@ -436,15 +436,19 @@ class AddPresetTrackingSettings(AddPresetBase, Operator):
     ]
 
     preset_values = [
-        "settings.default_correlation_min",
-        "settings.default_pattern_size",
-        "settings.default_search_size",
-        "settings.default_frames_limit",
-        "settings.default_pattern_match",
-        "settings.default_margin",
-        "settings.use_default_red_channel",
-        "settings.use_default_green_channel",
-        "settings.use_default_blue_channel"
+        "default_correlation_min",
+        "default_pattern_size",
+        "default_search_size",
+        "default_frames_limit",
+        "default_pattern_match",
+        "default_margin",
+        "default_motion_model",
+        "use_default_brute",
+        "use_default_normalization",
+        "use_default_mask",
+        "use_default_red_channel",
+        "use_default_green_channel",
+        "use_default_blue_channel"
     ]
 
     preset_subdir = "tracking_settings"
index 559cf7f93b713546605f283626f862a7f1d356a1..efac7a66086e3291973d5e21053253644607cae8 100644 (file)
@@ -232,9 +232,9 @@ class CLIP_PT_tools_marker(CLIP_PT_tracking_panel, Panel):
 
             col.label(text="Tracker:")
             col.prop(settings, "default_motion_model")
-            col.prop(settings, "default_use_brute")
-            col.prop(settings, "default_use_normalization")
-            col.prop(settings, "default_use_mask")
+            col.prop(settings, "use_default_brute")
+            col.prop(settings, "use_default_normalization")
+            col.prop(settings, "use_default_mask")
             col.prop(settings, "default_correlation_min")
 
             col.separator()
@@ -843,7 +843,7 @@ class CLIP_PT_footage(CLIP_PT_clip_view_panel, Panel):
 
         col = layout.column()
         col.template_movieclip(sc, "clip", compact=True)
-        col.prop(clip, "start_frame")
+        col.prop(clip, "frame_start")
         col.prop(clip, "frame_offset")
 
 
index 573e27b52c247f58526c47852138c3b23d0f6de4..8b2b741b83e9e13b82800ea04ce35935d7153dd4 100644 (file)
@@ -287,7 +287,7 @@ static void rna_def_movieclip(BlenderRNA *brna)
        RNA_def_property_update(prop, NC_MOVIECLIP | ND_DISPLAY, NULL);
 
        /* start_frame */
-       prop = RNA_def_property(srna, "start_frame", PROP_INT, PROP_NONE);
+       prop = RNA_def_property(srna, "frame_start", PROP_INT, PROP_NONE);
        RNA_def_property_int_sdna(prop, NULL, "start_frame");
        RNA_def_property_ui_text(prop, "Start Frame", "Global scene frame number at which this movie starts playing "
                                 "(affects all data associated with a clip)");
index 63e650d5867fc9d11ca91a937b1d5220675b068d..0898ba5608fc3f5c4968ac49c2a9e37a9fefc700 100644 (file)
@@ -382,6 +382,17 @@ static void rna_tracking_markerSearch_update(Main *UNUSED(bmain), Scene *UNUSED(
        BKE_tracking_marker_clamp(marker, CLAMP_SEARCH_DIM);
 }
 
+static void rna_tracking_markerPattern_boundbox_get(PointerRNA *ptr, float *values)
+{
+       MovieTrackingMarker *marker = (MovieTrackingMarker *)ptr->data;
+       float min[2], max[2];
+
+       BKE_tracking_marker_pattern_minmax(marker, min, max);
+
+       copy_v2_v2(values, min);
+       copy_v2_v2(values + 2, max);
+}
+
 static void rna_trackingDopesheet_tagUpdate(Main *UNUSED(bmain), Scene *scene, PointerRNA *ptr)
 {
        MovieClip *clip = (MovieClip *)ptr->id.data;
@@ -443,9 +454,12 @@ void rna_trackingObject_remove(MovieTracking *tracking, MovieTrackingObject *obj
        WM_main_add_notifier(NC_MOVIECLIP | NA_EDITED, NULL);
 }
 
-static MovieTrackingMarker *rna_trackingMarkers_find_frame(MovieTrackingTrack *track, int framenr)
+static MovieTrackingMarker *rna_trackingMarkers_find_frame(MovieTrackingTrack *track, int framenr, int exact)
 {
-       return BKE_tracking_marker_get_exact(track, framenr);
+       if (exact)
+               return BKE_tracking_marker_get_exact(track, framenr);
+       else
+               return BKE_tracking_marker_get(track, framenr);
 }
 
 static MovieTrackingMarker *rna_trackingMarkers_insert_frame(MovieTrackingTrack *track, int framenr, float *co)
@@ -646,19 +660,19 @@ static void rna_def_trackingSettings(BlenderRNA *brna)
        RNA_def_property_ui_text(prop, "Motion model", "Default motion model to use for tracking");
 
        /* default_use_brute */
-       prop = RNA_def_property(srna, "default_use_brute", PROP_BOOLEAN, PROP_NONE);
+       prop = RNA_def_property(srna, "use_default_brute", PROP_BOOLEAN, PROP_NONE);
        RNA_def_property_boolean_sdna(prop, NULL, "default_algorithm_flag", TRACK_ALGORITHM_FLAG_USE_BRUTE);
        RNA_def_property_ui_text(prop, "Prepass", "Use a brute-force translation-only initialization when tracking");
        RNA_def_property_update(prop, NC_MOVIECLIP | ND_DISPLAY, NULL);
 
        /* default_use_brute */
-       prop = RNA_def_property(srna, "default_use_mask", PROP_BOOLEAN, PROP_NONE);
+       prop = RNA_def_property(srna, "use_default_mask", PROP_BOOLEAN, PROP_NONE);
        RNA_def_property_boolean_sdna(prop, NULL, "default_algorithm_flag", TRACK_ALGORITHM_FLAG_USE_MASK);
        RNA_def_property_ui_text(prop, "Use Mask", "Use a grease pencil datablock as a mask to use only specified areas of pattern when tracking");
        RNA_def_property_update(prop, NC_MOVIECLIP | ND_DISPLAY, NULL);
 
        /* default_use_normalization */
-       prop = RNA_def_property(srna, "default_use_normalization", PROP_BOOLEAN, PROP_NONE);
+       prop = RNA_def_property(srna, "use_default_normalization", PROP_BOOLEAN, PROP_NONE);
        RNA_def_property_boolean_sdna(prop, NULL, "default_algorithm_flag", TRACK_ALGORITHM_FLAG_USE_NORMALIZATION);
        RNA_def_property_ui_text(prop, "Normalize", "Normalize light intensities while tracking (slower)");
        RNA_def_property_update(prop, NC_MOVIECLIP | ND_DISPLAY, NULL);
@@ -814,6 +828,8 @@ static void rna_def_trackingMarker(BlenderRNA *brna)
        StructRNA *srna;
        PropertyRNA *prop;
 
+       static int boundbox_dimsize[] = {2, 2};
+
        srna = RNA_def_struct(brna, "MovieTrackingMarker", NULL);
        RNA_def_struct_ui_text(srna, "Movie tracking marker data", "Match-moving marker data for tracking");
 
@@ -849,6 +865,12 @@ static void rna_def_trackingMarker(BlenderRNA *brna)
                                 "normalized coordinates relative to marker position");
        RNA_def_property_update(prop, NC_MOVIECLIP | NA_EDITED, "rna_tracking_markerPattern_update");
 
+       prop = RNA_def_property(srna, "pattern_bound_box", PROP_FLOAT, PROP_NONE);
+       RNA_def_property_multi_array(prop, 2, boundbox_dimsize);
+       RNA_def_property_clear_flag(prop, PROP_EDITABLE);
+       RNA_def_property_float_funcs(prop, "rna_tracking_markerPattern_boundbox_get", NULL, NULL);
+       RNA_def_property_ui_text(prop, "Pattern Bounding Box", "Pattern area bounding box in normalized coordinates");
+
        /* search */
        prop = RNA_def_property(srna, "search_min", PROP_FLOAT, PROP_TRANSLATION);
        RNA_def_property_array(prop, 2);
@@ -887,6 +909,8 @@ static void rna_def_trackingMarkers(BlenderRNA *brna, PropertyRNA *cprop)
        parm = RNA_def_int(func, "frame", 1, MINFRAME, MAXFRAME, "Frame",
                           "Frame number to find marker for", MINFRAME, MAXFRAME);
        RNA_def_property_flag(parm, PROP_REQUIRED);
+       parm = RNA_def_boolean(func, "exact", TRUE, "Exact",
+                       "Get marker at exact frame number rather than get estimated marker");
        parm = RNA_def_pointer(func, "marker", "MovieTrackingMarker", "", "Marker for specified frame");
        RNA_def_function_return(func, parm);