diff options
author | Sergey Sharybin <sergey.vfx@gmail.com> | 2011-11-27 01:09:29 +0400 |
---|---|---|
committer | Sergey Sharybin <sergey.vfx@gmail.com> | 2011-11-27 01:09:29 +0400 |
commit | f5f4348e10774fb1f90aaf718f144240137f4281 (patch) | |
tree | 859e03c620ba10bf6d16dd8d1fa85847a7a19a46 /source | |
parent | 804ec83185d88150908fa0afddd15ccfc1f583f8 (diff) |
Camera tracking: presets for default tracking settings
Internal changes are almost finished, changes in the interface need to be discussed.
Diffstat (limited to 'source')
-rw-r--r-- | source/blender/blenkernel/BKE_tracking.h | 1 | ||||
-rw-r--r-- | source/blender/blenkernel/intern/movieclip.c | 14 | ||||
-rw-r--r-- | source/blender/blenkernel/intern/tracking.c | 50 | ||||
-rw-r--r-- | source/blender/blenloader/intern/readfile.c | 14 | ||||
-rw-r--r-- | source/blender/makesdna/DNA_tracking_types.h | 23 | ||||
-rw-r--r-- | source/blender/makesrna/intern/rna_tracking.c | 96 |
6 files changed, 161 insertions, 37 deletions
diff --git a/source/blender/blenkernel/BKE_tracking.h b/source/blender/blenkernel/BKE_tracking.h index 4a3b5053345..e55d40ebfe5 100644 --- a/source/blender/blenkernel/BKE_tracking.h +++ b/source/blender/blenkernel/BKE_tracking.h @@ -45,6 +45,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); diff --git a/source/blender/blenkernel/intern/movieclip.c b/source/blender/blenkernel/intern/movieclip.c index 382e1d70387..75d8ec584e8 100644 --- a/source/blender/blenkernel/intern/movieclip.c +++ b/source/blender/blenkernel/intern/movieclip.c @@ -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; diff --git a/source/blender/blenkernel/intern/tracking.c b/source/blender/blenkernel/intern/tracking.c index 65ca0a87602..449832fd456 100644 --- a/source/blender/blenkernel/intern/tracking.c +++ b/source/blender/blenkernel/intern/tracking.c @@ -70,14 +70,38 @@ 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.frames_limit= 0; + 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 +170,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 +214,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; + track->tracker = settings->default_tracker; + track->pyramid_levels = settings->default_pyramid_levels; /* set SAD defaults even though it's not selected by default */ - track->minimum_correlation= 0.75f; + track->minimum_correlation= settings->default_minimum_correlation; memset(&marker, 0, sizeof(marker)); marker.pos[0]= x; @@ -223,6 +249,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); diff --git a/source/blender/blenloader/intern/readfile.c b/source/blender/blenloader/intern/readfile.c index 1912973bc24..3db36a075d7 100644 --- a/source/blender/blenloader/intern/readfile.c +++ b/source/blender/blenloader/intern/readfile.c @@ -12607,11 +12607,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! */ diff --git a/source/blender/makesdna/DNA_tracking_types.h b/source/blender/makesdna/DNA_tracking_types.h index 88173e6cac3..635be805d1b 100644 --- a/source/blender/makesdna/DNA_tracking_types.h +++ b/source/blender/makesdna/DNA_tracking_types.h @@ -107,16 +107,25 @@ typedef struct MovieTrackingTrack { float minimum_correlation; /* minimal correlation which is still treated as successful tracking */ /* ** KLT tracker settings ** */ - int pyramid_levels; /* number of pyramid levels to use for KLT tracking */ - char pad5[4]; + short pyramid_levels; /* number of pyramid levels to use for KLT tracking */ + char pad5[6]; } MovieTrackingTrack; typedef struct MovieTrackingSettings { + /* ** 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 */ + /* ** 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]; + + short pad; + int flag; int adjframes; /* re-adjust every N frames */ @@ -125,8 +134,7 @@ typedef struct MovieTrackingSettings { /* ** which camera intrinsics to refine. uses on the REFINE_* flags */ short refine_camera_intrinsics; - - char pad2[6]; + short pad2; /* ** tool settings ** */ @@ -172,8 +180,6 @@ typedef struct MovieTrackingStats { typedef struct MovieTracking { MovieTrackingSettings settings; /* different tracking-related settings */ - char pad2[4]; - MovieTrackingCamera camera; /* camera intrinsics */ ListBase tracks; /* all tracks */ MovieTrackingReconstruction reconstruction; /* reconstruction data */ @@ -204,6 +210,9 @@ enum { #define TRACK_CUSTOMCOLOR (1<<7) #define TRACK_USE_2D_STAB (1<<8) +/* MovieTrackingSettings->flag */ +#define TRACKING_SETTINGS_SHOW_DEFAULT_EXPANDED (1<<0) + /* MovieTrackingSettings->tracker */ #define TRACKER_KLT 0 #define TRACKER_SAD 1 diff --git a/source/blender/makesrna/intern/rna_tracking.c b/source/blender/makesrna/intern/rna_tracking.c index eb3512083aa..8d20aeafa54 100644 --- a/source/blender/makesrna/intern/rna_tracking.c +++ b/source/blender/makesrna/intern/rna_tracking.c @@ -53,6 +53,40 @@ #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,11 @@ 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 int rna_matrix_dimsize_4x4[]= {4, 4}; static void rna_def_trackingSettings(BlenderRNA *brna) @@ -348,6 +387,56 @@ 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); + + /* 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", "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 +554,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); @@ -535,7 +619,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); |