Camera tracking integration
=========================== Stop SAD tracker when error becomes too high. Maximal allowed error value is controlled in Tracking Settings panel. I haven't been able to find value which will work for most of cases so it's now quite stupid value of 0. Currently values of 2-6 gives quite nice result, but it depends on footage. Upcoming changes from libmv side related on returning normalized SAD would help here. Until this, please set max_sad manually.
This commit is contained in:
5
extern/libmv/libmv-capi.cpp
vendored
5
extern/libmv/libmv-capi.cpp
vendored
@@ -327,14 +327,15 @@ void libmv_SADSamplePattern(unsigned char *image, int stride,
|
||||
int libmv_SADTrackerTrack(unsigned char *pattern, unsigned char *image, int stride,
|
||||
int width, int height, double *x, double *y)
|
||||
{
|
||||
int result;
|
||||
float x2, y2;
|
||||
|
||||
libmv::Track(pattern, image, stride, width, height, &x2, &y2);
|
||||
result = libmv::Track(pattern, image, stride, width, height, &x2, &y2);
|
||||
|
||||
*x= x2;
|
||||
*y= y2;
|
||||
|
||||
return 1;
|
||||
return result;
|
||||
}
|
||||
|
||||
/* ************ Tracks ************ */
|
||||
|
||||
@@ -519,6 +519,10 @@ class CLIP_PT_track_settings(Panel):
|
||||
settings = clip.tracking.settings
|
||||
|
||||
layout.prop(settings, "tracker")
|
||||
|
||||
if settings.tracker == "SAD":
|
||||
layout.prop(settings, "max_sad")
|
||||
|
||||
layout.prop(settings, "speed")
|
||||
layout.prop(settings, "frames_limit")
|
||||
|
||||
|
||||
@@ -156,6 +156,16 @@ MovieTrackingTrack *BKE_tracking_add_track(MovieTracking *tracking, float x, flo
|
||||
MovieTrackingMarker marker;
|
||||
float pat[2]= {5.5f, 5.5f}, search[2]= {80.5f, 80.5f}; /* TODO: move to default setting? */
|
||||
|
||||
/* XXX: not very nice to have such check here, but it will prevent
|
||||
complaints about bad default settings for new markers */
|
||||
if(tracking->settings.tracker==TRACKER_SAD) {
|
||||
pat[0]= 8.f;
|
||||
pat[1]= 8.f;
|
||||
|
||||
search[0]= 32.f;
|
||||
search[1]= 32.f;
|
||||
}
|
||||
|
||||
pat[0] /= (float)width;
|
||||
pat[1] /= (float)height;
|
||||
|
||||
@@ -466,6 +476,7 @@ typedef struct TrackContext {
|
||||
float *patch; /* keyframed patch */
|
||||
|
||||
/* ** SAD tracker ** */
|
||||
int patsize[2]; /* size of pattern (currently only 16x16 due to libmv side) */
|
||||
unsigned char *pattern; /* keyframed pattern */
|
||||
#endif
|
||||
} TrackContext;
|
||||
@@ -934,6 +945,7 @@ int BKE_tracking_next(MovieTrackingContext *context)
|
||||
}
|
||||
else if(context->settings.tracker==TRACKER_SAD) {
|
||||
unsigned char *image_new;
|
||||
int sad, error;
|
||||
|
||||
if(track_context->pattern==NULL) {
|
||||
unsigned char *image;
|
||||
@@ -948,7 +960,11 @@ int BKE_tracking_next(MovieTrackingContext *context)
|
||||
warp[0][2]= pos[0];
|
||||
warp[1][2]= pos[1];
|
||||
|
||||
track_context->pattern= MEM_callocN(sizeof(unsigned char)*16*16, "trackking pattern");
|
||||
/* pattern size is hardcoded to 16x16px in libmv */
|
||||
track_context->patsize[0]= 16;
|
||||
track_context->patsize[1]= 16;
|
||||
|
||||
track_context->pattern= MEM_callocN(sizeof(unsigned char)*track_context->patsize[0]*track_context->patsize[1], "trackking pattern");
|
||||
libmv_SADSamplePattern(image, width, warp, track_context->pattern);
|
||||
|
||||
MEM_freeN(image);
|
||||
@@ -957,7 +973,10 @@ int BKE_tracking_next(MovieTrackingContext *context)
|
||||
|
||||
image_new= acquire_search_bytebuf(ibuf_new, track, marker, &width, &height, pos, origin);
|
||||
|
||||
tracked= libmv_SADTrackerTrack(track_context->pattern, image_new, width, width, height, &x2, &y2);
|
||||
sad= libmv_SADTrackerTrack(track_context->pattern, image_new, width, width, height, &x2, &y2);
|
||||
error= sad/(track_context->patsize[0]*track_context->patsize[1]);
|
||||
|
||||
tracked= error<=context->settings.maxsad;
|
||||
|
||||
MEM_freeN(image_new);
|
||||
}
|
||||
|
||||
@@ -101,10 +101,15 @@ typedef struct MovieTrackingTrack {
|
||||
|
||||
typedef struct MovieTrackingSettings {
|
||||
short tracker; /* tracker to use */
|
||||
short pad;
|
||||
|
||||
/* ** 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) */
|
||||
|
||||
/* ** SAD tracker settings ** */
|
||||
short maxsad; /* max value of sad which is still treated as successful tracking */
|
||||
|
||||
/* ** reconstructionsettings ** */
|
||||
int keyframe1, keyframe2; /* two keyframes for reconstrution initialization */
|
||||
|
||||
/* ** tool settings ** */
|
||||
|
||||
@@ -245,6 +245,13 @@ static void rna_def_trackingSettings(BlenderRNA *brna)
|
||||
RNA_def_property_enum_items(prop, tracker_items);
|
||||
RNA_def_property_ui_text(prop, "tracker", "Tracking algorithm to use");
|
||||
|
||||
/* limit frames */
|
||||
prop= RNA_def_property(srna, "max_sad", PROP_INT, PROP_NONE);
|
||||
RNA_def_property_clear_flag(prop, PROP_ANIMATABLE);
|
||||
RNA_def_property_int_sdna(prop, NULL, "maxsad");
|
||||
RNA_def_property_range(prop, 0, 255);
|
||||
RNA_def_property_ui_text(prop, "Max SAD", "Maximum value of SAD whichis still treated as successful tracking");
|
||||
|
||||
/* speed */
|
||||
prop= RNA_def_property(srna, "speed", PROP_ENUM, PROP_NONE);
|
||||
RNA_def_property_clear_flag(prop, PROP_ANIMATABLE);
|
||||
|
||||
Reference in New Issue
Block a user