Camera tracking: merging tracking presets stuff from tomato branch
authorSergey Sharybin <sergey.vfx@gmail.com>
Mon, 28 Nov 2011 13:26:46 +0000 (13:26 +0000)
committerSergey Sharybin <sergey.vfx@gmail.com>
Mon, 28 Nov 2011 13:26:46 +0000 (13:26 +0000)
This commit implements:

- Configurable settings for newly creating tracks
  Now it's possible to set tracking algorithm and it's settings for
  all newly creating tracks including manual tracks creation and
  tracks creation by "Detect Features" operator.
- Moves margin, frames limit and adjust frame inside per-track
  settings.
  Was request from Francois for this.
- Adjust Frames replaced with menu called Pattern Match where it's
  possible to choose between matching pattern from keyframe frame
  or from previously tracked frame.
  Didn't see somebody used adjust frames values differ from 0 and 1,
  and this menu should make things more clear here/

release/scripts/startup/bl_operators/presets.py
release/scripts/startup/bl_ui/space_clip.py
source/blender/blenkernel/BKE_tracking.h
source/blender/blenkernel/intern/movieclip.c
source/blender/blenkernel/intern/tracking.c
source/blender/blenloader/intern/readfile.c
source/blender/editors/space_clip/tracking_ops.c
source/blender/makesdna/DNA_tracking_types.h
source/blender/makesrna/intern/rna_tracking.c

index 100b21fc303e05b5cd2a8c006d6f2da40511ed23..a5c8c280616469a059c7046aa39547e743d3e497 100644 (file)
@@ -360,6 +360,30 @@ class AddPresetTrackingTrackColor(AddPresetBase, Operator):
     preset_subdir = "tracking_track_color"
 
 
+class AddPresetTrackingSettings(AddPresetBase, Operator):
+    '''Add a motion tracking settings preset'''
+    bl_idname = "clip.tracking_settings_preset_add"
+    bl_label = "Add Tracking Settings Preset"
+    preset_menu = "CLIP_MT_tracking_settings_presets"
+
+    preset_defines = [
+        "settings = bpy.context.edit_movieclip.tracking.settings"
+    ]
+
+    preset_values = [
+        "settings.default_tracker",
+        "settings.default_pyramid_levels",
+        "settings.default_correlation_min",
+        "settings.default_pattern_size",
+        "settings.default_search_size",
+        "settings.default_frames_limit",
+        "settings.default_pattern_match",
+        "settings.default_margin"
+    ]
+
+    preset_subdir = "tracking_settings"
+
+
 class AddPresetKeyconfig(AddPresetBase, Operator):
     '''Add a Keyconfig Preset'''
     bl_idname = "wm.keyconfig_preset_add"
index b04d81b6b2a6aeaab2b24bb3e239796a30ac8a7e..22d44ed47936344f3b6d61566b6154b059347213 100644 (file)
@@ -92,6 +92,9 @@ class CLIP_PT_tools_marker(Panel):
         return clip and sc.mode == 'TRACKING'
 
     def draw(self, context):
+        sc = context.space_data
+        clip = sc.clip
+        settings = clip.tracking.settings
         layout = self.layout
 
         col = layout.column(align=True)
@@ -99,6 +102,45 @@ class CLIP_PT_tools_marker(Panel):
         col.operator("clip.detect_features")
         col.operator("clip.delete_track")
 
+        box = layout.box()
+        row = box.row(align=True)
+        row.prop(settings, "show_default_expanded", text="", emboss=False)
+        row.label(text="Default Settings")
+
+        if settings.show_default_expanded:
+            col = box.column()
+            row = col.row(align=True)
+            label = bpy.types.CLIP_MT_tracking_settings_presets.bl_label
+            row.menu('CLIP_MT_tracking_settings_presets', text=label)
+            row.operator("clip.tracking_settings_preset_add",
+                         text="", icon='ZOOMIN')
+            props = row.operator("clip.track_color_preset_add",
+                                 text="", icon='ZOOMOUT')
+            props.remove_active = True
+
+            col.separator()
+
+            col2 = col.column(align=True)
+            col2.prop(settings, "default_pattern_size")
+            col2.prop(settings, "default_search_size")
+
+            col.label(text="Tracker:")
+            col.prop(settings, "default_tracker", text="")
+
+            if settings.default_tracker == 'KLT':
+                col.prop(settings, "default_pyramid_levels")
+            else:
+                col.prop(settings, "default_correlation_min")
+
+            col.separator()
+
+            col2 = col.column(align=True)
+            col2.prop(settings, "default_frames_limit")
+            col2.prop(settings, "default_margin")
+
+            col.label(text="Match:")
+            col.prop(settings, "default_pattern_match", text="")
+
 
 class CLIP_PT_tools_tracking(Panel):
     bl_space_type = 'CLIP_EDITOR'
@@ -447,18 +489,23 @@ class CLIP_PT_track_settings(Panel):
         clip = context.space_data.clip
         settings = clip.tracking.settings
 
+        col = layout.column()
+
         active = clip.tracking.tracks.active
         if active:
-            layout.prop(active, "tracker")
+            col.prop(active, "tracker")
+
             if active.tracker == 'KLT':
-                layout.prop(active, "pyramid_levels")
+                col.prop(active, "pyramid_levels")
             elif active.tracker == 'SAD':
-                layout.prop(active, "correlation_min")
+                col.prop(active, "correlation_min")
 
-        layout.prop(settings, "frames_adjust")
-        layout.prop(settings, "speed")
-        layout.prop(settings, "frames_limit")
-        layout.prop(settings, "margin")
+            col.separator()
+            col.prop(active, "frames_limit")
+            col.prop(active, "margin")
+            col.prop(active, "pattern_match", text="Match")
+
+        col.prop(settings, "speed")
 
 
 class CLIP_PT_stabilization(Panel):
@@ -866,6 +913,14 @@ class CLIP_MT_track_color_presets(Menu):
     draw = bpy.types.Menu.draw_preset
 
 
+class CLIP_MT_tracking_settings_presets(Menu):
+    """Predefined tracking settings"""
+    bl_label = "Tracking Presets"
+    preset_subdir = "tracking_settings"
+    preset_operator = "script.execute_preset"
+    draw = bpy.types.Menu.draw_preset
+
+
 class CLIP_MT_track_color_specials(Menu):
     bl_label = "Track Color Specials"
 
index 1c25547b146cbf65d9bef08a79760dfe7d8de8d7..530d8c7a1dbba2a26e1d28985038509b33689e93 100644 (file)
@@ -44,6 +44,7 @@ struct Camera;
 struct Object;
 struct Scene;
 
+void BKE_tracking_init_settings(struct MovieTracking *tracking);
 void BKE_tracking_clamp_track(struct MovieTrackingTrack *track, int event);
 void BKE_tracking_track_flag(struct MovieTrackingTrack *track, int area, int flag, int clear);
 
index 382e1d7038723cb2ebb75fb485aa2b6462fe115f..75d8ec584e85ddfeac56380258a89603b3b0ea40 100644 (file)
@@ -369,19 +369,7 @@ static MovieClip *movieclip_alloc(const char *name)
 
        clip->aspx= clip->aspy= 1.0f;
 
-       clip->tracking.camera.sensor_width= 35.0f;
-       clip->tracking.camera.pixel_aspect= 1.0f;
-       clip->tracking.camera.units= CAMERA_UNITS_MM;
-
-       clip->tracking.settings.frames_limit= 0;
-       clip->tracking.settings.keyframe1= 1;
-       clip->tracking.settings.keyframe2= 30;
-       clip->tracking.settings.dist= 1;
-
-       clip->tracking.stabilization.scaleinf= 1.0f;
-       clip->tracking.stabilization.locinf= 1.0f;
-       clip->tracking.stabilization.rotinf= 1.0f;
-       clip->tracking.stabilization.maxscale= 2.0f;
+       BKE_tracking_init_settings(&clip->tracking);
 
        clip->proxy.build_size_flag= IMB_PROXY_25;
        clip->proxy.build_tc_flag= IMB_TC_RECORD_RUN|IMB_TC_FREE_RUN|IMB_TC_INTERPOLATED_REC_DATE_FREE_RUN;
index 45e708a8233cf57e53c0ff5d4436d4da0db4542a..be20e36dfbe336299d010346e76797378dac861e 100644 (file)
@@ -70,14 +70,37 @@ typedef struct MovieDistortion {
 
 /*********************** common functions *************************/
 
+void BKE_tracking_init_settings(MovieTracking *tracking)
+{
+       tracking->camera.sensor_width= 35.0f;
+       tracking->camera.pixel_aspect= 1.0f;
+       tracking->camera.units= CAMERA_UNITS_MM;
+
+       tracking->settings.default_tracker= TRACKER_KLT;
+       tracking->settings.default_pyramid_levels= 2;
+       tracking->settings.default_minimum_correlation= 0.75;
+       tracking->settings.default_pattern_size= 11;
+       tracking->settings.default_search_size= 51;
+       tracking->settings.default_pyramid_levels= 2;
+       tracking->settings.keyframe1= 1;
+       tracking->settings.keyframe2= 30;
+       tracking->settings.dist= 1;
+
+       tracking->stabilization.scaleinf= 1.0f;
+       tracking->stabilization.locinf= 1.0f;
+       tracking->stabilization.rotinf= 1.0f;
+       tracking->stabilization.maxscale= 2.0f;
+}
+
 void BKE_tracking_clamp_track(MovieTrackingTrack *track, int event)
 {
        int a;
        float pat_min[2];
        float pat_max[2];
        float max_pyramid_level_factor = 1.0;
+
        if (track->tracker == TRACKER_KLT) {
-               max_pyramid_level_factor = 1 << (track->pyramid_levels - 1);
+               max_pyramid_level_factor= 1 << (track->pyramid_levels - 1);
        }
 
        /* sort */
@@ -146,7 +169,7 @@ void BKE_tracking_clamp_track(MovieTrackingTrack *track, int event)
                float dim[2];
                sub_v2_v2v2(dim, track->pat_max, track->pat_min);
                {
-                       float search_ratio = 2.3f * max_pyramid_level_factor;
+                       float search_ratio= 2.3f * max_pyramid_level_factor;
 
                        /* resize the search area to something sensible based
                         * on the number of pyramid levels */
@@ -190,25 +213,27 @@ MovieTrackingTrack *BKE_tracking_add_track(MovieTracking *tracking, float x, flo
 {
        MovieTrackingTrack *track;
        MovieTrackingMarker marker;
+       MovieTrackingSettings *settings= &tracking->settings;
 
-       /* pick reasonable defaults */
-       float pat[2]= {5.5f, 5.5f}, search[2]= {25.5f, 25.5f}; /* TODO: move to default setting? */
+       float half_pattern= (float)settings->default_pattern_size/2.0f;
+       float half_search= (float)settings->default_search_size/2.0f;
+       float pat[2], search[2];
 
-       pat[0] /= (float)width;
-       pat[1] /= (float)height;
+       pat[0]= half_pattern/(float)width;
+       pat[1]= half_pattern/(float)height;
 
-       search[0] /= (float)width;
-       search[1] /= (float)height;
+       search[0]= half_search/(float)width;
+       search[1]= half_search/(float)height;
 
        track= MEM_callocN(sizeof(MovieTrackingTrack), "add_marker_exec track");
        strcpy(track->name, "Track");
 
-       /* default to KLT tracker */
-       track->tracker = TRACKER_KLT;
-       track->pyramid_levels = 2;
-
-       /* set SAD defaults even though it's not selected by default */
-       track->minimum_correlation= 0.75f;
+       track->tracker= settings->default_tracker;
+       track->pyramid_levels= settings->default_pyramid_levels;
+       track->minimum_correlation= settings->default_minimum_correlation;
+       track->margin= settings->default_margin;
+       track->pattern_match= settings->default_pattern_match;
+       track->frames_limit= settings->default_frames_limit;
 
        memset(&marker, 0, sizeof(marker));
        marker.pos[0]= x;
@@ -223,6 +248,8 @@ MovieTrackingTrack *BKE_tracking_add_track(MovieTracking *tracking, float x, flo
 
        BKE_tracking_insert_marker(track, &marker);
 
+       BKE_tracking_clamp_track(track, CLAMP_PYRAMID_LEVELS);
+
        BLI_addtail(&tracking->tracks, track);
        BKE_track_unique_name(tracking, track);
 
@@ -1050,7 +1077,7 @@ static ImBuf *get_adjust_ibuf(MovieTrackingContext *context, MovieTrackingTrack
 {
        ImBuf *ibuf= NULL;
 
-       if(context->settings.adjframes == 0) {
+       if(track->pattern_match == TRACK_MATCH_KEYFRAME) {
                ibuf= get_keyframed_ibuf(context, track, marker, marker_keyed);
        } else {
                ibuf= get_frame_ibuf(context, curfra);
@@ -1133,8 +1160,10 @@ int BKE_tracking_next(MovieTrackingContext *context)
                        int onbound= 0, coords_correct= 0;
                        int nextfra;
 
-                       if(!context->settings.adjframes) need_readjust= context->first_time;
-                       else need_readjust= context->frames%context->settings.adjframes == 0;
+                       if(track->pattern_match==TRACK_MATCH_KEYFRAME)
+                               need_readjust= context->first_time;
+                       else
+                               need_readjust= 1;
 
                        if(context->backwards) nextfra= curfra-1;
                        else nextfra= curfra+1;
@@ -1142,8 +1171,8 @@ int BKE_tracking_next(MovieTrackingContext *context)
                        /* margin from frame boundaries */
                        sub_v2_v2v2(margin, track->pat_max, track->pat_min);
 
-                       margin[0]= MAX2(margin[0], (float)context->settings.margin / ibuf_new->x);
-                       margin[1]= MAX2(margin[1], (float)context->settings.margin / ibuf_new->y);
+                       margin[0]= MAX2(margin[0], (float)track->margin / ibuf_new->x);
+                       margin[1]= MAX2(margin[1], (float)track->margin / ibuf_new->y);
 
                        /* do not track markers which are too close to boundary */
                        if(marker->pos[0]<margin[0] || marker->pos[0]>1.0f-margin[0] ||
index e69823886e566500fbcbc7e366c7180df32cd29f..e38e62aa6910c4bbc034ce7f786f58d54046cbc4 100644 (file)
@@ -12606,11 +12606,25 @@ static void do_versions(FileData *fd, Library *lib, Main *main)
        /* put compatibility code here until next subversion bump */
        {
                Scene *sce;
+               MovieClip *clip;
+
                for(sce = main->scene.first; sce; sce = sce->id.next) {
                        if (sce->r.im_format.depth == 0) {
                                do_versions_image_settings_2_60(sce);
                        }
                }
+
+               for (clip= main->movieclip.first; clip; clip= clip->id.next) {
+                       MovieTrackingSettings *settings= &clip->tracking.settings;
+
+                       if(settings->default_pyramid_levels==0) {
+                               settings->default_tracker= TRACKER_KLT;
+                               settings->default_pyramid_levels= 2;
+                               settings->default_minimum_correlation= 0.75;
+                               settings->default_pattern_size= 11;
+                               settings->default_search_size= 51;
+                       }
+               }
        }
 
        /* WATCH IT!!!: pointers from libdata have not been converted yet here! */
index 695de548ec2b7cb3ac7e715c08aa52f0401001bb..6057cacbcce144e0f4e3d8bffeb84a32756d43cf 100644 (file)
@@ -1221,10 +1221,11 @@ static int track_count_markers(SpaceClip *sc, MovieClip *clip)
        return tot;
 }
 
-static void track_init_markers(SpaceClip *sc, MovieClip *clip)
+static void track_init_markers(SpaceClip *sc, MovieClip *clip, int *frames_limit_r)
 {
        MovieTrackingTrack *track;
        int framenr= sc->user.framenr, hidden= 0;
+       int frames_limit= 0;
 
        if((sc->flag&SC_SHOW_MARKER_PATTERN)==0) hidden|= TRACK_AREA_PAT;
        if((sc->flag&SC_SHOW_MARKER_SEARCH)==0) hidden|= TRACK_AREA_SEARCH;
@@ -1235,12 +1236,22 @@ static void track_init_markers(SpaceClip *sc, MovieClip *clip)
                        BKE_tracking_track_flag(track, hidden, SELECT, 1);
 
                if(TRACK_SELECTED(track)) {
-                       if((track->flag&TRACK_HIDDEN)==0 && (track->flag&TRACK_LOCKED)==0)
+                       if((track->flag&TRACK_HIDDEN)==0 && (track->flag&TRACK_LOCKED)==0) {
                                BKE_tracking_ensure_marker(track, framenr);
+
+                               if(track->frames_limit) {
+                                       if(frames_limit==0)
+                                               frames_limit= track->frames_limit;
+                                       else
+                                               frames_limit= MIN2(frames_limit, track->frames_limit);
+                               }
+                       }
                }
 
                track= track->next;
        }
+
+       *frames_limit_r= frames_limit;
 }
 
 static int track_markers_check_direction(int backwards, int curfra, int efra)
@@ -1261,6 +1272,9 @@ static int track_markers_initjob(bContext *C, TrackMarkersJob *tmj, int backward
        MovieClip *clip= ED_space_clip(sc);
        Scene *scene= CTX_data_scene(C);
        MovieTrackingSettings *settings= &clip->tracking.settings;
+       int frames_limit;
+
+       track_init_markers(sc, clip, &frames_limit);
 
        tmj->sfra= sc->user.framenr;
        tmj->clip= clip;
@@ -1270,9 +1284,9 @@ static int track_markers_initjob(bContext *C, TrackMarkersJob *tmj, int backward
        else tmj->efra= EFRA;
 
        /* limit frames to be tracked by user setting */
-       if(settings->frames_limit) {
-               if(backwards) tmj->efra= MAX2(tmj->efra, tmj->sfra-settings->frames_limit);
-               else tmj->efra= MIN2(tmj->efra, tmj->sfra+settings->frames_limit);
+       if(frames_limit) {
+               if(backwards) tmj->efra= MAX2(tmj->efra, tmj->sfra-frames_limit);
+               else tmj->efra= MIN2(tmj->efra, tmj->sfra+frames_limit);
        }
 
        if(settings->speed!=TRACKING_SPEED_FASTEST) {
@@ -1283,8 +1297,6 @@ static int track_markers_initjob(bContext *C, TrackMarkersJob *tmj, int backward
                else if(settings->speed==TRACKING_SPEED_DOUBLE) tmj->delay/= 2;
        }
 
-       track_init_markers(sc, clip);
-
        tmj->context= BKE_tracking_context_new(clip, &sc->user, backwards, 1);
 
        clip->tracking_context= tmj->context;
@@ -1376,25 +1388,25 @@ static int track_markers_exec(bContext *C, wmOperator *op)
        int sfra= framenr, efra;
        int backwards= RNA_boolean_get(op->ptr, "backwards");
        int sequence= RNA_boolean_get(op->ptr, "sequence");
-       MovieTrackingSettings *settings= &clip->tracking.settings;
+       int frames_limit;
 
        if(track_count_markers(sc, clip)==0)
                return OPERATOR_CANCELLED;
 
+       track_init_markers(sc, clip, &frames_limit);
+
        if(backwards) efra= SFRA;
        else efra= EFRA;
 
        /* limit frames to be tracked by user setting */
-       if(settings->frames_limit) {
-               if(backwards) efra= MAX2(efra, sfra-settings->frames_limit);
-               else efra= MIN2(efra, sfra+settings->frames_limit);
+       if(frames_limit) {
+               if(backwards) efra= MAX2(efra, sfra-frames_limit);
+               else efra= MIN2(efra, sfra+frames_limit);
        }
 
        if(!track_markers_check_direction(backwards, framenr, efra))
                return OPERATOR_CANCELLED;
 
-       track_init_markers(sc, clip);
-
        /* do not disable tracks due to threshold when tracking frame-by-frame */
        context= BKE_tracking_context_new(clip, &sc->user, backwards, sequence);
 
index cbac3721ac38df2316234b153382b79bb46bfc08..c795cea88fb6118abc5d82151ae333f4b4d1a9f6 100644 (file)
@@ -100,33 +100,40 @@ typedef struct MovieTrackingTrack {
        float color[3];                                         /* custom color for track */
 
        /* tracking algorithm to use; can be KLT or SAD */
-       short tracker;
-       char pad4[2];
+       short frames_limit;             /* number of frames to be tarcked during single tracking session (if TRACKING_FRAMES_LIMIT is set) */
+       short margin;                   /* margin from frame boundaries */
+       short pattern_match;    /* re-adjust every N frames */
 
-       /* ** SAD tracker settings ** */
-       float minimum_correlation;                      /* minimal correlation which is still treated as successful tracking */
+       short tracker;                  /* tracking algorithm used for this track */
 
        /* ** KLT tracker settings ** */
-       int pyramid_levels;             /* number of pyramid levels to use for KLT tracking */
-       char pad5[4];
+       short pyramid_levels, pad2;             /* number of pyramid levels to use for KLT tracking */
+
+       /* ** SAD tracker settings ** */
+       float minimum_correlation;                      /* minimal correlation which is still treated as successful tracking */
 } MovieTrackingTrack;
 
 typedef struct MovieTrackingSettings {
+       int flag;
+
+       /* ** default tracker settings */
+       short default_tracker;                          /* tracking algorithm used by default */
+       short default_pyramid_levels;           /* number of pyramid levels to use for KLT tracking */
+       float default_minimum_correlation;      /* minimal correlation which is still treated as successful tracking */
+       short default_pattern_size;                     /* size of pattern area for new tracks */
+       short default_search_size;                      /* size of search area for new tracks */
+       short default_frames_limit;                     /* number of frames to be tarcked during single tracking session (if TRACKING_FRAMES_LIMIT is set) */
+       short default_margin;                           /* margin from frame boundaries */
+       short default_pattern_match;            /* re-adjust every N frames */
+
        /* ** common tracker settings ** */
        short speed;                    /* speed of tracking */
-       short frames_limit;             /* number of frames to be tarcked during single tracking session (if TRACKING_FRAMES_LIMIT is set) */
-       short margin;                   /* margin from frame boundaries */
-       char pad[2];
-
-       int adjframes;                  /* re-adjust every N frames */
 
        /* ** reconstruction settings ** */
        int keyframe1, keyframe2;       /* two keyframes for reconstrution initialization */
 
        /* ** which camera intrinsics to refine. uses on the REFINE_* flags */
-       short refine_camera_intrinsics;
-
-       char pad2[6];
+       short refine_camera_intrinsics, pad2;
 
        /* ** tool settings ** */
 
@@ -135,7 +142,7 @@ typedef struct MovieTrackingSettings {
 
        /* cleanup */
        int clean_frames, clean_action;
-       float clean_error;
+       float clean_error, pad;
 } MovieTrackingSettings;
 
 typedef struct MovieTrackingStabilization {
@@ -167,8 +174,6 @@ typedef struct MovieTrackingReconstruction {
 
 typedef struct MovieTracking {
        MovieTrackingSettings settings; /* different tracking-related settings */
-       char pad2[4];
-
        MovieTrackingCamera camera;             /* camera intrinsics */
        ListBase tracks;                                /* all tracks */
        MovieTrackingReconstruction reconstruction;     /* reconstruction data */
@@ -197,10 +202,17 @@ enum {
 #define TRACK_CUSTOMCOLOR      (1<<7)
 #define TRACK_USE_2D_STAB      (1<<8)
 
-/* MovieTrackingSettings->tracker */
+/* MovieTrackingTrack->tracker */
 #define TRACKER_KLT            0
 #define TRACKER_SAD            1
 
+/* MovieTrackingTrack->adjframes */
+#define TRACK_MATCH_KEYFRAME           0
+#define TRACK_MATCH_PREVFRAME          1
+
+/* MovieTrackingSettings->flag */
+#define TRACKING_SETTINGS_SHOW_DEFAULT_EXPANDED        (1<<0)
+
 /* MovieTrackingSettings->speed */
 #define TRACKING_SPEED_FASTEST         0
 #define TRACKING_SPEED_REALTIME                1
index eb3512083aa03a56e38f19df5a79dde91e970a93..a3d043ab6ec739618edb5133e875acc0e8c20473 100644 (file)
 
 #include "WM_api.h"
 
+static void rna_tracking_defaultSettings_levelsUpdate(Main *UNUSED(bmain), Scene *scene, PointerRNA *ptr)
+{
+       MovieClip *clip= (MovieClip*)ptr->id.data;
+       MovieTracking *tracking= &clip->tracking;
+       MovieTrackingSettings *settings= &tracking->settings;
+
+       if(settings->default_tracker==TRACKER_KLT) {
+               int max_pyramid_level_factor= 1 << (settings->default_pyramid_levels - 1);
+               float search_ratio= 2.3f * max_pyramid_level_factor;
+
+               settings->default_search_size= settings->default_pattern_size*search_ratio;
+       }
+}
+
+static void rna_tracking_defaultSettings_patternUpdate(Main *UNUSED(bmain), Scene *scene, PointerRNA *ptr)
+{
+       MovieClip *clip= (MovieClip*)ptr->id.data;
+       MovieTracking *tracking= &clip->tracking;
+       MovieTrackingSettings *settings= &tracking->settings;
+
+       if(settings->default_search_size<settings->default_pattern_size)
+               settings->default_search_size= settings->default_pattern_size;
+}
+
+static void rna_tracking_defaultSettings_searchUpdate(Main *UNUSED(bmain), Scene *scene, PointerRNA *ptr)
+{
+       MovieClip *clip= (MovieClip*)ptr->id.data;
+       MovieTracking *tracking= &clip->tracking;
+       MovieTrackingSettings *settings= &tracking->settings;
+
+       if(settings->default_pattern_size>settings->default_search_size)
+               settings->default_pattern_size= settings->default_search_size;
+}
+
 static void rna_tracking_tracks_begin(CollectionPropertyIterator *iter, PointerRNA *ptr)
 {
        MovieClip *clip= (MovieClip*)ptr->id.data;
@@ -232,6 +266,16 @@ static MovieTrackingMarker *rna_trackingTrack_marker_find_frame(MovieTrackingTra
 
 #else
 
+static EnumPropertyItem tracker_items[] = {
+       {TRACKER_KLT, "KLT", 0, "KLT", "Kanade–Lucas–Tomasi tracker which works with most of video clips, a bit slower than SAD"},
+       {TRACKER_SAD, "SAD", 0, "SAD", "Sum of Absolute Differences tracker which can be used when MLT tracker fails"},
+       {0, NULL, 0, NULL, NULL}};
+
+static EnumPropertyItem pattern_match_items[] = {
+       {TRACK_MATCH_KEYFRAME, "KEYFRAME", 0, "Keyframe", "Track pattern from keyframe to next frame"},
+       {TRACK_MATCH_PREVFRAME, "PREV_FRAME", 0, "Previous frame", "Track pattern from current frame to next frame"},
+       {0, NULL, 0, NULL, NULL}};
+
 static int rna_matrix_dimsize_4x4[]= {4, 4};
 
 static void rna_def_trackingSettings(BlenderRNA *brna)
@@ -280,27 +324,6 @@ static void rna_def_trackingSettings(BlenderRNA *brna)
        RNA_def_property_enum_items(prop, speed_items);
        RNA_def_property_ui_text(prop, "Speed", "Limit speed of tracking to make visual feedback easier (this does not affect the tracking quality)");
 
-       /* limit frames */
-       prop= RNA_def_property(srna, "frames_limit", PROP_INT, PROP_NONE);
-       RNA_def_property_clear_flag(prop, PROP_ANIMATABLE);
-       RNA_def_property_int_sdna(prop, NULL, "frames_limit");
-       RNA_def_property_range(prop, 0, SHRT_MAX);
-       RNA_def_property_ui_text(prop, "Frames Limit", "Every tracking cycle, this amount of frames are tracked");
-
-       /* adjust frames */
-       prop= RNA_def_property(srna, "frames_adjust", PROP_INT, PROP_NONE);
-       RNA_def_property_clear_flag(prop, PROP_ANIMATABLE);
-       RNA_def_property_int_sdna(prop, NULL, "adjframes");
-       RNA_def_property_range(prop, 0, INT_MAX);
-       RNA_def_property_ui_text(prop, "Adjust Frames", "Automatically re-adjust marker position using position on each N frames. 0 means only keyframed position is used");
-
-       /* margin */
-       prop= RNA_def_property(srna, "margin", PROP_INT, PROP_NONE);
-       RNA_def_property_clear_flag(prop, PROP_ANIMATABLE);
-       RNA_def_property_int_sdna(prop, NULL, "margin");
-       RNA_def_property_range(prop, 0, 300);
-       RNA_def_property_ui_text(prop, "Margin", "Distance from image boudary at which marker stops tracking");
-
        /* keyframe_a */
        prop= RNA_def_property(srna, "keyframe_a", PROP_INT, PROP_NONE);
        RNA_def_property_clear_flag(prop, PROP_ANIMATABLE);
@@ -348,6 +371,76 @@ static void rna_def_trackingSettings(BlenderRNA *brna)
        RNA_def_property_clear_flag(prop, PROP_ANIMATABLE);
        RNA_def_property_enum_items(prop, cleanup_items);
        RNA_def_property_ui_text(prop, "Action", "Cleanup action to execute");
+
+       /* ** default tracker settings ** */
+       prop= RNA_def_property(srna, "show_default_expanded", PROP_BOOLEAN, PROP_NONE);
+       RNA_def_property_clear_flag(prop, PROP_ANIMATABLE);
+       RNA_def_property_boolean_sdna(prop, NULL, "flag", TRACKING_SETTINGS_SHOW_DEFAULT_EXPANDED);
+       RNA_def_property_ui_text(prop, "Show Expanded", "Show the expanded in the user interface");
+       RNA_def_property_ui_icon(prop, ICON_TRIA_RIGHT, 1);
+
+       /* limit frames */
+       prop= RNA_def_property(srna, "default_frames_limit", PROP_INT, PROP_NONE);
+       RNA_def_property_clear_flag(prop, PROP_ANIMATABLE);
+       RNA_def_property_int_sdna(prop, NULL, "default_frames_limit");
+       RNA_def_property_range(prop, 0, SHRT_MAX);
+       RNA_def_property_ui_text(prop, "Frames Limit", "Every tracking cycle, this amount of frames are tracked");
+
+       /* pattern match */
+       prop= RNA_def_property(srna, "default_pattern_match", PROP_ENUM, PROP_NONE);
+       RNA_def_property_clear_flag(prop, PROP_ANIMATABLE);
+       RNA_def_property_enum_sdna(prop, NULL, "default_pattern_match");
+       RNA_def_property_enum_items(prop, pattern_match_items);
+       RNA_def_property_ui_text(prop, "Pattern Match", "Track pattern from given frame when tracking marker to next frame");
+
+       /* margin */
+       prop= RNA_def_property(srna, "default_margin", PROP_INT, PROP_NONE);
+       RNA_def_property_clear_flag(prop, PROP_ANIMATABLE);
+       RNA_def_property_int_sdna(prop, NULL, "default_margin");
+       RNA_def_property_range(prop, 0, 300);
+       RNA_def_property_ui_text(prop, "Margin", "Default distance from image boudary at which marker stops tracking");
+
+       /* tracking algorithm */
+       prop= RNA_def_property(srna, "default_tracker", PROP_ENUM, PROP_NONE);
+       RNA_def_property_clear_flag(prop, PROP_ANIMATABLE);
+       RNA_def_property_clear_flag(prop, PROP_ANIMATABLE);
+       RNA_def_property_enum_items(prop, tracker_items);
+       RNA_def_property_update(prop, 0, "rna_tracking_defaultSettings_levelsUpdate");
+       RNA_def_property_ui_text(prop, "Tracker", "Default tracking algorithm to use");
+
+       /* pyramid level for pyramid klt tracking */
+       prop= RNA_def_property(srna, "default_pyramid_levels", PROP_INT, PROP_NONE);
+       RNA_def_property_clear_flag(prop, PROP_ANIMATABLE);
+       RNA_def_property_clear_flag(prop, PROP_ANIMATABLE);
+       RNA_def_property_int_sdna(prop, NULL, "default_pyramid_levels");
+       RNA_def_property_range(prop, 1, 16);
+       RNA_def_property_update(prop, 0, "rna_tracking_defaultSettings_levelsUpdate");
+       RNA_def_property_ui_text(prop, "Pyramid levels", "Default number of pyramid levels (increase on blurry footage)");
+
+       /* minmal correlation - only used for SAD tracker */
+       prop= RNA_def_property(srna, "default_correlation_min", PROP_FLOAT, PROP_NONE);
+       RNA_def_property_clear_flag(prop, PROP_ANIMATABLE);
+       RNA_def_property_clear_flag(prop, PROP_ANIMATABLE);
+       RNA_def_property_float_sdna(prop, NULL, "default_minimum_correlation");
+       RNA_def_property_range(prop, -1.0f, 1.0f);
+       RNA_def_property_ui_range(prop, -1.0f, 1.0f, 0.1, 3);
+       RNA_def_property_ui_text(prop, "Correlation", "Default minimal value of correlation between matched pattern and reference which is still treated as successful tracking");
+
+       /* default pattern size */
+       prop= RNA_def_property(srna, "default_pattern_size", PROP_INT, PROP_NONE);
+       RNA_def_property_clear_flag(prop, PROP_ANIMATABLE);
+       RNA_def_property_int_sdna(prop, NULL, "default_pattern_size");
+       RNA_def_property_range(prop, 5, 1000);
+       RNA_def_property_update(prop, 0, "rna_tracking_defaultSettings_patternUpdate");
+       RNA_def_property_ui_text(prop, "Pattern Size", "Size of pattern area for newly creating tracks");
+
+       /* default search size */
+       prop= RNA_def_property(srna, "default_search_size", PROP_INT, PROP_NONE);
+       RNA_def_property_clear_flag(prop, PROP_ANIMATABLE);
+       RNA_def_property_int_sdna(prop, NULL, "default_search_size");
+       RNA_def_property_range(prop, 5, 1000);
+       RNA_def_property_update(prop, 0, "rna_tracking_defaultSettings_searchUpdate");
+       RNA_def_property_ui_text(prop, "Search Size", "Size of search area for newly creating tracks");
 }
 
 static void rna_def_trackingCamera(BlenderRNA *brna)
@@ -465,11 +558,6 @@ static void rna_def_trackingTrack(BlenderRNA *brna)
        FunctionRNA *func;
        PropertyRNA *parm;
 
-       static EnumPropertyItem tracker_items[] = {
-               {TRACKER_KLT, "KLT", 0, "KLT", "Kanade–Lucas–Tomasi tracker which works with most of video clips, a bit slower than SAD"},
-               {TRACKER_SAD, "SAD", 0, "SAD", "Sum of Absolute Differences tracker which can be used when MLT tracker fails"},
-               {0, NULL, 0, NULL, NULL}};
-
        rna_def_trackingMarker(brna);
 
        srna= RNA_def_struct(brna, "MovieTrackingTrack", NULL);
@@ -514,6 +602,27 @@ static void rna_def_trackingTrack(BlenderRNA *brna)
        RNA_def_property_ui_text(prop, "Search Max", "Right-bottom corner of search area in normalized coordinates relative to marker position");
        RNA_def_property_update(prop, NC_MOVIECLIP|NA_EDITED, "rna_tracking_trackerSearch_update");
 
+       /* limit frames */
+       prop= RNA_def_property(srna, "frames_limit", PROP_INT, PROP_NONE);
+       RNA_def_property_clear_flag(prop, PROP_ANIMATABLE);
+       RNA_def_property_int_sdna(prop, NULL, "frames_limit");
+       RNA_def_property_range(prop, 0, SHRT_MAX);
+       RNA_def_property_ui_text(prop, "Frames Limit", "Every tracking cycle, this amount of frames are tracked");
+
+       /* pattern match */
+       prop= RNA_def_property(srna, "pattern_match", PROP_ENUM, PROP_NONE);
+       RNA_def_property_clear_flag(prop, PROP_ANIMATABLE);
+       RNA_def_property_enum_sdna(prop, NULL, "pattern_match");
+       RNA_def_property_enum_items(prop, pattern_match_items);
+       RNA_def_property_ui_text(prop, "Pattern Match", "Track pattern from given frame when tracking marker to next frame");
+
+       /* margin */
+       prop= RNA_def_property(srna, "margin", PROP_INT, PROP_NONE);
+       RNA_def_property_clear_flag(prop, PROP_ANIMATABLE);
+       RNA_def_property_int_sdna(prop, NULL, "margin");
+       RNA_def_property_range(prop, 0, 300);
+       RNA_def_property_ui_text(prop, "Margin", "Distance from image boudary at which marker stops tracking");
+
        /* tracking algorithm */
        prop= RNA_def_property(srna, "tracker", PROP_ENUM, PROP_NONE);
        RNA_def_property_clear_flag(prop, PROP_ANIMATABLE);
@@ -535,7 +644,7 @@ static void rna_def_trackingTrack(BlenderRNA *brna)
        RNA_def_property_float_sdna(prop, NULL, "minimum_correlation");
        RNA_def_property_range(prop, -1.0f, 1.0f);
        RNA_def_property_ui_range(prop, -1.0f, 1.0f, 0.1, 3);
-       RNA_def_property_ui_text(prop, "Correlation", "Minimal value of correlation between mathed pattern and reference which is still treated as successful tracking");
+       RNA_def_property_ui_text(prop, "Correlation", "Minimal value of correlation between matched pattern and reference which is still treated as successful tracking");
 
        /* markers */
        prop= RNA_def_property(srna, "markers", PROP_COLLECTION, PROP_NONE);