Revision: 39718
          
http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=39718
Author:   nazgul
Date:     2011-08-26 20:14:29 +0000 (Fri, 26 Aug 2011)
Log Message:
-----------
Camera tracking integration
===========================

- Stop tracking when marker is too close to the frame boundary.
- Added marker margin to tracking settings.
- Added option to use auto-adoptation each N frames.
- Highlight keyframed frames on cache line with brighter yellow.

Modified Paths:
--------------
    branches/soc-2011-tomato/release/scripts/startup/bl_ui/space_clip.py
    branches/soc-2011-tomato/source/blender/blenkernel/intern/tracking.c
    branches/soc-2011-tomato/source/blender/editors/space_clip/clip_draw.c
    branches/soc-2011-tomato/source/blender/editors/space_clip/tracking_ops.c
    branches/soc-2011-tomato/source/blender/makesdna/DNA_tracking_types.h
    branches/soc-2011-tomato/source/blender/makesrna/intern/rna_tracking.c

Modified: branches/soc-2011-tomato/release/scripts/startup/bl_ui/space_clip.py
===================================================================
--- branches/soc-2011-tomato/release/scripts/startup/bl_ui/space_clip.py        
2011-08-26 20:12:54 UTC (rev 39717)
+++ branches/soc-2011-tomato/release/scripts/startup/bl_ui/space_clip.py        
2011-08-26 20:14:29 UTC (rev 39718)
@@ -520,11 +520,14 @@
 
         layout.prop(settings, "tracker")
 
+        layout.prop(settings, "adjust_frames")
+
         if settings.tracker == "SAD":
             layout.prop(settings, "min_correlation")
 
         layout.prop(settings, "speed")
         layout.prop(settings, "frames_limit")
+        layout.prop(settings, "margin")
 
 
 class CLIP_PT_stabilization(Panel):

Modified: branches/soc-2011-tomato/source/blender/blenkernel/intern/tracking.c
===================================================================
--- branches/soc-2011-tomato/source/blender/blenkernel/intern/tracking.c        
2011-08-26 20:12:54 UTC (rev 39717)
+++ branches/soc-2011-tomato/source/blender/blenkernel/intern/tracking.c        
2011-08-26 20:14:29 UTC (rev 39718)
@@ -486,7 +486,7 @@
        MovieClipUser user;
        MovieClip *clip;
 
-       int first_time;
+       int first_time, frames;
 
        TrackContext *track_context;
        int num_tracks;
@@ -772,12 +772,25 @@
        return pixels;
 }
 
+static ImBuf *acquire_frame_ibuf(MovieTrackingContext *context, int framenr)
+{
+       ImBuf *ibuf;
+       int framenr_old= context->user.framenr;
+
+       context->user.framenr= framenr;
+
+       ibuf= BKE_movieclip_acquire_ibuf_flag(context->clip, &context->user, 0);
+
+       context->user.framenr= framenr_old;
+
+       return ibuf;
+}
+
 static ImBuf *acquire_keyframed_ibuf(MovieTrackingContext *context, 
MovieTrackingTrack *track,
                        MovieTrackingMarker *marker, MovieTrackingMarker 
**marker_keyed)
 {
-       int framenr_old= context->user.framenr, framenr= marker->framenr;
+       int framenr= marker->framenr;
        int a= marker-track->markers;
-       ImBuf *ibuf;
 
        *marker_keyed= marker;
 
@@ -792,26 +805,23 @@
                else a--;
        }
 
-       context->user.framenr= framenr;
-
-       ibuf= BKE_movieclip_acquire_ibuf_flag(context->clip, &context->user, 0);
-
-       context->user.framenr= framenr_old;
-
-       return ibuf;
+       return acquire_frame_ibuf(context, framenr);
 }
 
-static ImBuf *acquire_frame_ibuf(MovieTrackingContext *context, int framenr)
+static ImBuf *acquire_adjust_ibuf(MovieTrackingContext *context, 
MovieTrackingTrack *track, MovieTrackingMarker *marker,
+                       int curfra, MovieTrackingMarker **marker_keyed)
 {
-       ImBuf *ibuf;
-       int framenr_old= context->user.framenr;
+       ImBuf *ibuf= NULL;
 
-       context->user.framenr= framenr;
+       if(context->settings.adjframes == 0) {
+               ibuf= acquire_keyframed_ibuf(context, track, marker, 
marker_keyed);
+       } else {
+               ibuf= acquire_frame_ibuf(context, curfra);
 
-       ibuf= BKE_movieclip_acquire_ibuf_flag(context->clip, &context->user, 0);
+               /* use current marker as keyframed position */
+               *marker_keyed= marker;
+       }
 
-       context->user.framenr= framenr_old;
-
        return ibuf;
 }
 
@@ -947,19 +957,36 @@
 
                if(marker && (marker->flag&MARKER_DISABLED)==0 && 
marker->framenr==curfra) {
 #ifdef WITH_LIBMV
-                       int width, height, origin[2], tracked= 0;
-                       float pos[2];
+                       int width, height, origin[2], tracked= 0, 
need_readjust= 0;
+                       float pos[2], margin[2];
                        double x1, y1, x2, y2;
                        ImBuf *ibuf= NULL;
                        MovieTrackingMarker marker_new, *marker_keyed;
 
-                       if(context->settings.tracker==TRACKER_KLT) {
+                       if(!context->settings.adjframes) need_readjust= 
context->first_time;
+                       else need_readjust= 
context->frames%context->settings.adjframes == 0;
+
+                       /* 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);
+
+                       /* do not track markers which are too close to boundary 
*/
+                       if(marker->pos[0]<margin[0] || 
marker->pos[0]>1.f-margin[0] ||
+                          marker->pos[1]<margin[1] || 
marker->pos[1]>1.f-margin[1]) {
+                       }
+                       else if(context->settings.tracker==TRACKER_KLT) {
                                int wndx, wndy;
                                float *patch_new;
 
-                               if(!track_context->patch) {
+                               if(need_readjust) {
                                        /* calculate patch for keyframed 
position */
-                                       ibuf= acquire_keyframed_ibuf(context, 
track, marker, &marker_keyed);
+                                       ibuf= acquire_adjust_ibuf(context, 
track, marker, curfra, &marker_keyed);
+
+                                       if(track_context->patch)
+                                               MEM_freeN(track_context->patch);
+
                                        track_context->patch= 
acquire_search_floatbuf(ibuf, track, marker_keyed, &width, &height, pos, 
origin);
 
                                        IMB_freeImBuf(ibuf);
@@ -986,12 +1013,12 @@
                                float corr;
                                float warp[3][2]={{0}};
 
-                               if(track_context->pattern==NULL) {
+                               if(need_readjust) {
                                        unsigned char *image;
 
                                        /* calculate pattern for keyframed 
position */
+                                       ibuf= acquire_adjust_ibuf(context, 
track, marker, curfra, &marker_keyed);
 
-                                       ibuf= acquire_keyframed_ibuf(context, 
track, marker, &marker_keyed);
                                        image= acquire_search_bytebuf(ibuf, 
track, marker_keyed, &width, &height, pos, origin);
 
                                        memset(warp, 0, sizeof(warp));
@@ -1003,7 +1030,9 @@
                                        /* pattern size is hardcoded to 16x16px 
in libmv */
                                        track_context->patsize= 16;
 
-                                       track_context->pattern= 
MEM_callocN(sizeof(unsigned 
char)*track_context->patsize*track_context->patsize, "trackking pattern");
+                                       if(!track_context->pattern)
+                                               track_context->pattern= 
MEM_callocN(sizeof(unsigned 
char)*track_context->patsize*track_context->patsize, "trackking pattern");
+
                                        libmv_SADSamplePattern(image, width, 
warp, track_context->pattern);
 
                                        MEM_freeN(image);
@@ -1100,7 +1129,9 @@
        }
 
        IMB_freeImBuf(ibuf_new);
+
        context->first_time= 0;
+       context->frames++;
 
        return ok;
 }

Modified: branches/soc-2011-tomato/source/blender/editors/space_clip/clip_draw.c
===================================================================
--- branches/soc-2011-tomato/source/blender/editors/space_clip/clip_draw.c      
2011-08-26 20:12:54 UTC (rev 39717)
+++ branches/soc-2011-tomato/source/blender/editors/space_clip/clip_draw.c      
2011-08-26 20:14:29 UTC (rev 39718)
@@ -127,6 +127,7 @@
                                framenr= marker->framenr;
 
                                if(framenr!=i) glColor4ub(128, 128, 0, 96);
+                               else if((marker->flag&MARKER_TRACKED)==0) 
glColor4ub(255, 255, 0, 196);
                                else glColor4ub(255, 255, 0, 96);
 
                                glRecti((i-sfra)*framelen, 0, 
(i-sfra+1)*framelen, 4);

Modified: 
branches/soc-2011-tomato/source/blender/editors/space_clip/tracking_ops.c
===================================================================
--- branches/soc-2011-tomato/source/blender/editors/space_clip/tracking_ops.c   
2011-08-26 20:12:54 UTC (rev 39717)
+++ branches/soc-2011-tomato/source/blender/editors/space_clip/tracking_ops.c   
2011-08-26 20:14:29 UTC (rev 39718)
@@ -1235,6 +1235,7 @@
 
                if(settings->speed==TRACKING_SPEED_HALF) tmj->delay*= 2;
                else if(settings->speed==TRACKING_SPEED_QUARTER) tmj->delay*= 4;
+               else if(settings->speed==TRACKING_SPEED_DOUBLE) tmj->delay/= 2;
        }
 
        track_init_markers(sc, clip);

Modified: branches/soc-2011-tomato/source/blender/makesdna/DNA_tracking_types.h
===================================================================
--- branches/soc-2011-tomato/source/blender/makesdna/DNA_tracking_types.h       
2011-08-26 20:12:54 UTC (rev 39717)
+++ branches/soc-2011-tomato/source/blender/makesdna/DNA_tracking_types.h       
2011-08-26 20:14:29 UTC (rev 39718)
@@ -103,11 +103,13 @@
        short tracker;  /* tracker to use */
 
        /* ** common tracker settings ** */
-       short speed;    /* speed of tracking */
-       short frames_limit, pad;        /* number of frames to be tarcked 
during single tracking session (if TRACKING_FRAMES_LIMIT is set) */
+       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 */
+       int adjframes;                  /* re-adjust every N frames */
 
        /* ** SAD tracker settings ** */
-       float corr, pad2;                       /* minimal correlation which is 
still treated as successful tracking */
+       float corr;                                     /* minimal correlation 
which is still treated as successful tracking */
 
        /* ** reconstructionsettings ** */
        int keyframe1, keyframe2;       /* two keyframes for reconstrution 
initialization */
@@ -184,6 +186,7 @@
 #define TRACKING_SPEED_REALTIME                1
 #define TRACKING_SPEED_HALF                    2
 #define TRACKING_SPEED_QUARTER         4
+#define TRACKING_SPEED_DOUBLE          5
 
 /* MovieTrackingStrabilization->flag */
 #define TRACKING_2D_STABILIZATION      (1<<0)

Modified: branches/soc-2011-tomato/source/blender/makesrna/intern/rna_tracking.c
===================================================================
--- branches/soc-2011-tomato/source/blender/makesrna/intern/rna_tracking.c      
2011-08-26 20:12:54 UTC (rev 39717)
+++ branches/soc-2011-tomato/source/blender/makesrna/intern/rna_tracking.c      
2011-08-26 20:14:29 UTC (rev 39718)
@@ -224,6 +224,7 @@
 
        static EnumPropertyItem speed_items[] = {
                {0, "FASTEST", 0, "Fastest", "Track as fast as it's possible"},
+           {TRACKING_SPEED_DOUBLE, "DOUBLE", 0, "Double", "Track with double 
speed"},
                {TRACKING_SPEED_REALTIME, "REALTIME", 0, "Realtime", "Track 
with realtime speed"},
                {TRACKING_SPEED_HALF, "HALF", 0, "Half", "Track with half of 
realtime speed"},
                {TRACKING_SPEED_QUARTER, "QUARTER", 0, "Quarter", "Track with 
quarter of realtime speed"},
@@ -245,14 +246,6 @@
        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, "min_correlation", PROP_FLOAT, PROP_NONE);
-       RNA_def_property_clear_flag(prop, PROP_ANIMATABLE);
-       RNA_def_property_float_sdna(prop, NULL, "corr");
-       RNA_def_property_range(prop, -1.0f, 1.0f);
-       RNA_def_property_ui_range(prop, -1.f, 1.f, .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");
-
        /* speed */
        prop= RNA_def_property(srna, "speed", PROP_ENUM, PROP_NONE);
        RNA_def_property_clear_flag(prop, PROP_ANIMATABLE);
@@ -266,6 +259,20 @@
        RNA_def_property_range(prop, 0, INT_MAX);
        RNA_def_property_ui_text(prop, "Frames Limit", "Amount of frames to be 
tracked during single tracking operation");
 
+       /* adjust frames */
+       prop= RNA_def_property(srna, "adjust_frames", PROP_INT, PROP_NONE);
+       RNA_def_property_clear_flag(prop, PROP_ANIMATABLE);

@@ Diff output truncated at 10240 characters. @@
_______________________________________________
Bf-blender-cvs mailing list
[email protected]
http://lists.blender.org/mailman/listinfo/bf-blender-cvs

Reply via email to