[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [39999] branches/soc-2011-tomato: Camera tracking integration

Sergey Sharybin g.ulairi at gmail.com
Wed Sep 7 10:09:50 CEST 2011


Revision: 39999
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=39999
Author:   nazgul
Date:     2011-09-07 08:09:50 +0000 (Wed, 07 Sep 2011)
Log Message:
-----------
Camera tracking integration
===========================

- Added python method MovieClip.tracking.tracs.add() to add new track.
  Marker for this track is getting created on position (0, 0) and it's
  keyframed to specified frame number.

- Implemented rotation 2D stabilization. It's supposed to be used in the
  following workflow:

  * Set tracks which defines location stabilization.
  * Choose one track which defines orientation.
  * Vector which connects median point of location and track used for
    rotation would have the same orientation along all frames.

  2D stabilization with rotation can be a bit slow.

- Some internal refactor and code clean-up.

Modified Paths:
--------------
    branches/soc-2011-tomato/release/scripts/startup/bl_ui/space_clip.py
    branches/soc-2011-tomato/source/blender/blenkernel/BKE_movieclip.h
    branches/soc-2011-tomato/source/blender/blenkernel/BKE_tracking.h
    branches/soc-2011-tomato/source/blender/blenkernel/intern/movieclip.c
    branches/soc-2011-tomato/source/blender/blenkernel/intern/tracking.c
    branches/soc-2011-tomato/source/blender/blenloader/intern/readfile.c
    branches/soc-2011-tomato/source/blender/editors/include/ED_clip.h
    branches/soc-2011-tomato/source/blender/editors/space_clip/clip_draw.c
    branches/soc-2011-tomato/source/blender/editors/space_clip/clip_editor.c
    branches/soc-2011-tomato/source/blender/editors/space_clip/clip_intern.h
    branches/soc-2011-tomato/source/blender/editors/space_clip/space_clip.c
    branches/soc-2011-tomato/source/blender/editors/space_clip/tracking_ops.c
    branches/soc-2011-tomato/source/blender/editors/transform/transform_conversions.c
    branches/soc-2011-tomato/source/blender/makesdna/DNA_space_types.h
    branches/soc-2011-tomato/source/blender/makesdna/DNA_tracking_types.h
    branches/soc-2011-tomato/source/blender/makesrna/intern/rna_movieclip.c
    branches/soc-2011-tomato/source/blender/makesrna/intern/rna_tracking.c
    branches/soc-2011-tomato/source/blender/nodes/composite/node_composite_util.h
    branches/soc-2011-tomato/source/blender/nodes/composite/nodes/node_composite_movieclip.c
    branches/soc-2011-tomato/source/blender/nodes/composite/nodes/node_composite_stabilize2d.c
    branches/soc-2011-tomato/source/blender/nodes/composite/nodes/node_composite_transform.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-09-07 08:09:06 UTC (rev 39998)
+++ branches/soc-2011-tomato/release/scripts/startup/bl_ui/space_clip.py	2011-09-07 08:09:50 UTC (rev 39999)
@@ -570,10 +570,25 @@
 
         layout.prop(stab, "influence_location")
 
+        layout.separator()
+
         layout.prop(stab, "use_autoscale")
+        col = layout.column()
+        col.active = stab.use_autoscale
+        col.prop(stab, "max_scale")
+        col.prop(stab, "influence_scale")
+
+        layout.separator()
+
+        layout.label(text="Rotation:")
+
+        row = layout.row(align=True)
+        row.prop_search(stab, "rotation_track", tracking, "tracks", text="")
+        row.operator("clip.stabilize_2d_set_rotation", text="", icon='ZOOMIN')
+
         row = layout.row()
-        row.active = stab.use_autoscale
-        row.prop(stab, "influence_scale")
+        row.active = stab.rotation_track is not None
+        row.prop(stab, "influence_rotation")
 
 
 class CLIP_PT_marker(Panel):

Modified: branches/soc-2011-tomato/source/blender/blenkernel/BKE_movieclip.h
===================================================================
--- branches/soc-2011-tomato/source/blender/blenkernel/BKE_movieclip.h	2011-09-07 08:09:06 UTC (rev 39998)
+++ branches/soc-2011-tomato/source/blender/blenkernel/BKE_movieclip.h	2011-09-07 08:09:50 UTC (rev 39999)
@@ -48,7 +48,7 @@
 void BKE_movieclip_reload(struct MovieClip *clip);
 
 struct ImBuf *BKE_movieclip_acquire_ibuf(struct MovieClip *clip, struct MovieClipUser *user);
-struct ImBuf *BKE_movieclip_acquire_stable_ibuf(struct MovieClip *clip, struct MovieClipUser *user, float loc[2], float *scale);
+struct ImBuf *BKE_movieclip_acquire_stable_ibuf(struct MovieClip *clip, struct MovieClipUser *user, float loc[2], float *scale, float *angle);
 struct ImBuf *BKE_movieclip_acquire_ibuf_flag(struct MovieClip *clip, struct MovieClipUser *user, int flag);
 void BKE_movieclip_acquire_size(struct MovieClip *clip, struct MovieClipUser *user, int *width, int *height);
 void BKE_movieclip_aspect(struct MovieClip *clip, float *aspx, float *aspy);

Modified: branches/soc-2011-tomato/source/blender/blenkernel/BKE_tracking.h
===================================================================
--- branches/soc-2011-tomato/source/blender/blenkernel/BKE_tracking.h	2011-09-07 08:09:06 UTC (rev 39998)
+++ branches/soc-2011-tomato/source/blender/blenkernel/BKE_tracking.h	2011-09-07 08:09:50 UTC (rev 39999)
@@ -88,11 +88,12 @@
 
 struct MovieTrackingTrack *BKE_tracking_indexed_bundle(struct MovieTracking *tracking, int bundlenr);
 
-void BKE_tracking_stabilization_data(struct MovieTracking *tracking, int framenr, int width, int height, float loc[2], float *scale);
-struct ImBuf *BKE_tracking_stabilize_shot(struct MovieTracking *tracking, int framenr, struct ImBuf *ibuf, float loc[2], float *scale);
-void BKE_tracking_stabdata_to_mat4(float loc[2], float scale, float mat[4][4]);
+void BKE_tracking_stabilization_data(struct MovieTracking *tracking, int framenr, int width, int height, float loc[2], float *scale, float *angle);
+struct ImBuf *BKE_tracking_stabilize(struct MovieTracking *tracking, int framenr, struct ImBuf *ibuf, float loc[2], float *scale, float *angle);
+void BKE_tracking_stabdata_to_mat4(int width, int height, float loc[2], float scale, float angle, float mat[4][4]);
 
 struct ImBuf *BKE_tracking_undistort(struct MovieTracking *tracking, struct ImBuf *ibuf);
+struct ImBuf *BKE_tracking_distort(struct MovieTracking *tracking, struct ImBuf *ibuf);
 
 #define TRACK_SELECTED(track)				((((track)->flag&TRACK_HIDDEN)==0) && ((track)->flag&SELECT || (track)->pat_flag&SELECT || (track)->search_flag&SELECT))
 #define TRACK_AREA_SELECTED(track, area)	((((track)->flag&TRACK_HIDDEN)==0) && ((area)==TRACK_AREA_POINT?(track)->flag&SELECT : ((area)==TRACK_AREA_PAT?(track)->pat_flag&SELECT:(track)->search_flag&SELECT)))

Modified: branches/soc-2011-tomato/source/blender/blenkernel/intern/movieclip.c
===================================================================
--- branches/soc-2011-tomato/source/blender/blenkernel/intern/movieclip.c	2011-09-07 08:09:06 UTC (rev 39998)
+++ branches/soc-2011-tomato/source/blender/blenkernel/intern/movieclip.c	2011-09-07 08:09:50 UTC (rev 39999)
@@ -255,7 +255,7 @@
 
 	/* cache for stable shot */
 	int stable_framenr;
-	float stable_loc[2], stable_scale;
+	float stable_loc[2], stable_scale, stable_angle;
 	ImBuf *stableibuf;
 } MovieClipCache;
 
@@ -352,6 +352,8 @@
 
 	clip->tracking.stabilization.scaleinf= 1.f;
 	clip->tracking.stabilization.locinf= 1.f;
+	clip->tracking.stabilization.rotinf= 1.f;
+	clip->tracking.stabilization.maxscale= 2.f;
 
 	clip->proxy.build_size_flags= IMB_PROXY_25;
 	clip->proxy.build_tc_flags= IMB_TC_RECORD_RUN|IMB_TC_FREE_RUN|IMB_TC_INTERPOLATED_REC_DATE_FREE_RUN;
@@ -511,7 +513,7 @@
 	return ibuf;
 }
 
-ImBuf *BKE_movieclip_acquire_stable_ibuf(MovieClip *clip, MovieClipUser *user, float loc[2], float *scale)
+ImBuf *BKE_movieclip_acquire_stable_ibuf(MovieClip *clip, MovieClipUser *user, float loc[2], float *scale, float *angle)
 {
 	ImBuf *ibuf, *stableibuf= NULL;
 	int framenr= user?user->framenr:clip->lastframe;
@@ -519,14 +521,14 @@
 	ibuf= BKE_movieclip_acquire_ibuf(clip, user);
 
 	if(clip->tracking.stabilization.flag&TRACKING_2D_STABILIZATION) {
-		float tloc[2], tscale;
+		float tloc[2], tscale, tangle;
 
 		if(clip->cache->stableibuf && clip->cache->stable_framenr==framenr) {
 			stableibuf= clip->cache->stableibuf;
 
-			BKE_tracking_stabilization_data(&clip->tracking, framenr, stableibuf->x, stableibuf->y, tloc, &tscale);
+			BKE_tracking_stabilization_data(&clip->tracking, framenr, stableibuf->x, stableibuf->y, tloc, &tscale, &tangle);
 
-			if(!equals_v2v2(tloc, clip->cache->stable_loc) || tscale!=clip->cache->stable_scale) {
+			if(!equals_v2v2(tloc, clip->cache->stable_loc) || tscale!=clip->cache->stable_scale || tangle!=clip->cache->stable_angle) {
 				stableibuf= NULL;
 			}
 		}
@@ -535,10 +537,11 @@
 			if(clip->cache->stableibuf)
 				IMB_freeImBuf(clip->cache->stableibuf);
 
-			stableibuf= BKE_tracking_stabilize_shot(&clip->tracking, framenr, ibuf, tloc, &tscale);
+			stableibuf= BKE_tracking_stabilize(&clip->tracking, framenr, ibuf, tloc, &tscale, &tangle);
 
 			copy_v2_v2(clip->cache->stable_loc, tloc);
 			clip->cache->stable_scale= tscale;
+			clip->cache->stable_angle= tangle;
 			clip->cache->stable_framenr= framenr;
 			clip->cache->stableibuf= stableibuf;
 		}
@@ -547,9 +550,11 @@
 
 		if(loc)		copy_v2_v2(loc, tloc);
 		if(scale)	*scale= tscale;
+		if(angle)	*angle= tangle;
 	} else {
 		if(loc)		zero_v2(loc);
 		if(scale)	*scale= 1.f;
+		if(angle)	*angle= 0.f;
 
 		stableibuf= ibuf;
 	}

Modified: branches/soc-2011-tomato/source/blender/blenkernel/intern/tracking.c
===================================================================
--- branches/soc-2011-tomato/source/blender/blenkernel/intern/tracking.c	2011-09-07 08:09:06 UTC (rev 39998)
+++ branches/soc-2011-tomato/source/blender/blenkernel/intern/tracking.c	2011-09-07 08:09:50 UTC (rev 39999)
@@ -842,6 +842,7 @@
 void BKE_tracking_sync(MovieTrackingContext *context)
 {
 	TrackContext *track_context;
+	MovieTracking *tracking= &context->clip->tracking;
 	MovieTrackingTrack *track;
 	ListBase tracks= {NULL, NULL}, new_tracks= {NULL, NULL};
 	ListBase *old_tracks= &context->clip->tracking.tracks;
@@ -870,7 +871,7 @@
 
 			/* original track was found, re-use flags and remove this track */
 			if(cur) {
-				if(cur==context->clip->tracking.act_track)
+				if(cur==tracking->act_track)
 					replace_sel= 1;
 
 				track->flag= cur->flag;
@@ -888,7 +889,7 @@
 		BLI_ghash_insert(context->hash, track, new_track);
 
 		if(replace_sel)		/* update current selection in clip */
-			context->clip->tracking.act_track= new_track;
+			tracking->act_track= new_track;
 
 		BLI_addtail(&tracks, new_track);
 	}
@@ -1572,8 +1573,49 @@
 	return ok;
 }
 
-static float stabilization_auto_scale_factor(MovieTracking *tracking)
+static void calculate_stabdata(MovieTracking *tracking, int framenr, float width, float height,
+			float firstmedian[2], float median[2], float loc[2], float *scale, float *angle)
 {
+	MovieTrackingStabilization *stab= &tracking->stabilization;
+
+	*scale= (stab->scale-1.f)*stab->scaleinf+1.f;
+	*angle= 0.f;
+
+	loc[0]= (firstmedian[0]-median[0])*width*(*scale);
+	loc[1]= (firstmedian[1]-median[1])*height*(*scale);
+
+	loc[0]-= (firstmedian[0]*(*scale)-firstmedian[0])*width;
+	loc[1]-= (firstmedian[1]*(*scale)-firstmedian[1])*height;
+
+	mul_v2_fl(loc, stab->locinf);
+
+	if(stab->rot_track && stab->rotinf) {
+		MovieTrackingMarker *marker;
+		float a[2], b[2];
+		float x0= (float)width/2.f, y0= (float)height/2.f;
+		float x= median[0]*width, y= median[1]*height;
+
+		marker= BKE_tracking_get_marker(stab->rot_track, 1);
+		sub_v2_v2v2(a, marker->pos, firstmedian);
+		a[0]*= width;
+		a[1]*= height;
+
+		marker= BKE_tracking_get_marker(stab->rot_track, framenr);
+		sub_v2_v2v2(b, marker->pos, median);
+		b[0]*= width;
+		b[1]*= height;
+
+		*angle= -atan2(a[0]*b[1]-a[1]*b[0], a[0]*b[0]+a[1]*b[1]);
+		*angle*= stab->rotinf;
+
+		/* convert to rotation around image center */
+		loc[0]-= (x0 + (x-x0)*cos(*angle)-(y-y0)*sin(*angle) - x);
+		loc[1]-= (y0 + (x-x0)*sin(*angle)+(y-y0)*cos(*angle) - y);
+	}
+}
+
+static float stabilization_auto_scale_factor(MovieTracking *tracking, int width, int height)
+{
 	float firstmedian[2];
 	MovieTrackingStabilization *stab= &tracking->stabilization;
 
@@ -1582,12 +1624,14 @@
 
 	if(stabilization_median_point(tracking, 1, firstmedian)) {
 		int sfra= INT_MAX, efra= INT_MIN, cfra;
-		float delta[2]= {0.f, 0.f}, scalex, scaley, near[2]={1.f, 1.f};
+		float delta[2]= {0.f, 0.f}, scalex= 1.f, scaley= 1.f;
 		MovieTrackingTrack *track;
 
+		stab->scale= 1.f;
+
 		track= tracking->tracks.first;
 		while(track) {
-			if(track->flag&TRACK_USE_2D_STAB) {
+			if(track->flag&TRACK_USE_2D_STAB || track==stab->rot_track) {
 				if(track->markersnr) {
 					sfra= MIN2(sfra, track->markers[0].framenr);
 					efra= MAX2(efra, track->markers[track->markersnr-1].framenr);
@@ -1598,28 +1642,69 @@
 		}
 
 		for(cfra=sfra; cfra<=efra; cfra++) {
-			float median[2], d[2];
+			float median[2], near[2];
+			float loc[2], scale, angle;
 

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list