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

Sergey Sharybin g.ulairi at gmail.com
Wed Jul 20 22:31:26 CEST 2011


Revision: 38546
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=38546
Author:   nazgul
Date:     2011-07-20 20:31:25 +0000 (Wed, 20 Jul 2011)
Log Message:
-----------
Camera tracking integration
===========================

- Fixed crash when holding down S and R keys.
- Fixed deleting of first marker.
- Tracking should now work fine with float buffers.
- Added option to show distortion grid. It's most probably
  temporary solution until [auto]calibration tools aren't
  merged.
  This grid defines straight lines on the image.

Modified Paths:
--------------
    branches/soc-2011-tomato/extern/libmv/libmv-capi.cpp
    branches/soc-2011-tomato/extern/libmv/libmv-capi.h
    branches/soc-2011-tomato/release/scripts/startup/bl_ui/space_clip.py
    branches/soc-2011-tomato/source/blender/blenkernel/BKE_tracking.h
    branches/soc-2011-tomato/source/blender/blenkernel/intern/tracking.c
    branches/soc-2011-tomato/source/blender/editors/include/ED_transform.h
    branches/soc-2011-tomato/source/blender/editors/space_clip/clip_draw.c
    branches/soc-2011-tomato/source/blender/editors/transform/transform.c
    branches/soc-2011-tomato/source/blender/makesdna/DNA_space_types.h
    branches/soc-2011-tomato/source/blender/makesrna/intern/rna_space.c

Modified: branches/soc-2011-tomato/extern/libmv/libmv-capi.cpp
===================================================================
--- branches/soc-2011-tomato/extern/libmv/libmv-capi.cpp	2011-07-20 15:58:04 UTC (rev 38545)
+++ branches/soc-2011-tomato/extern/libmv/libmv-capi.cpp	2011-07-20 20:31:25 UTC (rev 38546)
@@ -450,3 +450,19 @@
 		intrinsics.ApplyIntrinsics(x, y, x1, y1);
 	}
 }
+
+void libmv_InvertIntrinsics(double focal_length, double principal_x, double principal_y, double k1, double k2, double k3,
+			double x, double y, double *x1, double *y1)
+{
+	libmv::CameraIntrinsics intrinsics;
+
+	intrinsics.SetFocalLength(focal_length, focal_length);
+	intrinsics.SetPrincipalPoint(principal_x, principal_y);
+	intrinsics.SetRadialDistortion(k1, k2, k3);
+
+	if(focal_length) {
+		/* do a lens distortion if focal length is non-zero only */
+
+		intrinsics.InvertIntrinsics(x, y, x1, y1);
+	}
+}

Modified: branches/soc-2011-tomato/extern/libmv/libmv-capi.h
===================================================================
--- branches/soc-2011-tomato/extern/libmv/libmv-capi.h	2011-07-20 15:58:04 UTC (rev 38545)
+++ branches/soc-2011-tomato/extern/libmv/libmv-capi.h	2011-07-20 20:31:25 UTC (rev 38546)
@@ -72,6 +72,8 @@
 /* utils */
 void libmv_applyCameraIntrinsics(double focal_length, double principal_x, double principal_y, double k1, double k2, double k3,
 			double x, double y, double *x1, double *y1);
+void libmv_InvertIntrinsics(double focal_length, double principal_x, double principal_y, double k1, double k2, double k3,
+			double x, double y, double *x1, double *y1);
 
 #ifdef __cplusplus
 }

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-07-20 15:58:04 UTC (rev 38545)
+++ branches/soc-2011-tomato/release/scripts/startup/bl_ui/space_clip.py	2011-07-20 20:31:25 UTC (rev 38546)
@@ -332,7 +332,10 @@
         row.prop(sc, "show_disabled", text="Disabled")
         row.prop(sc, "show_bundles", text="Bundles")
 
-        layout.prop(sc, "show_names", text="Names")
+        row = layout.row()
+        row.prop(sc, "show_names", text="Names")
+        row.prop(sc, "show_grid", text="Grid")
+
         layout.prop(sc, "show_tiny_markers", text="Tiny Markers")
 
         layout.prop(sc, "lock_selection")

Modified: branches/soc-2011-tomato/source/blender/blenkernel/BKE_tracking.h
===================================================================
--- branches/soc-2011-tomato/source/blender/blenkernel/BKE_tracking.h	2011-07-20 15:58:04 UTC (rev 38545)
+++ branches/soc-2011-tomato/source/blender/blenkernel/BKE_tracking.h	2011-07-20 20:31:25 UTC (rev 38546)
@@ -79,6 +79,7 @@
 void BKE_get_tracking_mat(struct Scene *scene, float mat[4][4]);
 void BKE_tracking_projection_matrix(struct MovieTracking *tracking, int framenr, int winx, int winy, float mat[4][4]);
 void BKE_tracking_apply_intrinsics(struct MovieTracking *tracking, float co[2], float width, float height, float nco[2]);
+void BKE_tracking_invert_intrinsics(struct MovieTracking *tracking, float co[2], float width, float height, float nco[2]);
 
 void BKE_tracking_detect(struct MovieTracking *tracking, struct ImBuf *imbuf, int framenr);
 

Modified: branches/soc-2011-tomato/source/blender/blenkernel/intern/tracking.c
===================================================================
--- branches/soc-2011-tomato/source/blender/blenkernel/intern/tracking.c	2011-07-20 15:58:04 UTC (rev 38545)
+++ branches/soc-2011-tomato/source/blender/blenkernel/intern/tracking.c	2011-07-20 20:31:25 UTC (rev 38546)
@@ -216,7 +216,7 @@
 
 void BKE_tracking_delete_marker(MovieTrackingTrack *track, int framenr)
 {
-	int a= 1;
+	int a= 0;
 
 	while(a<track->markersnr) {
 		if(track->markers[a].framenr==framenr) {
@@ -234,7 +234,8 @@
 		}
 
 		a++;
-	}}
+	}
+}
 
 MovieTrackingMarker *BKE_tracking_get_marker(MovieTrackingTrack *track, int framenr)
 {
@@ -472,11 +473,20 @@
 	for(y= 0; y<ibuf->y; y++) {
 		for (x= 0; x<ibuf->x; x++) {
 			int pixel= ibuf->x*y + x;
-			char *rrgb= (char*)ibuf->rect + pixel*4;
 
-			if(track->flag&TRACK_DISABLE_RED)	rrgb[0]= 0;
-			if(track->flag&TRACK_DISABLE_GREEN)	rrgb[1]= 0;
-			if(track->flag&TRACK_DISABLE_BLUE)	rrgb[2]= 0;
+			if(ibuf->rect_float) {
+				float *rrgbf= ibuf->rect_float + pixel*4;
+
+				if(track->flag&TRACK_DISABLE_RED)	rrgbf[0]= 0;
+				if(track->flag&TRACK_DISABLE_GREEN)	rrgbf[1]= 0;
+				if(track->flag&TRACK_DISABLE_BLUE)	rrgbf[2]= 0;
+			} else {
+				char *rrgb= (char*)ibuf->rect + pixel*4;
+
+				if(track->flag&TRACK_DISABLE_RED)	rrgb[0]= 0;
+				if(track->flag&TRACK_DISABLE_GREEN)	rrgb[1]= 0;
+				if(track->flag&TRACK_DISABLE_BLUE)	rrgb[2]= 0;
+			}
 		}
 	}
 }
@@ -554,9 +564,17 @@
 	for(y= 0; y<(int)height; y++) {
 		for (x= 0; x<(int)width; x++) {
 			int pixel= tmpibuf->x*y + x;
-			char *rrgb= (char*)tmpibuf->rect + pixel*4;
 
-			*fp= (0.2126*rrgb[0] + 0.7152*rrgb[1] + 0.0722*rrgb[2])/255;
+			if(tmpibuf->rect_float) {
+				float *rrgbf= ibuf->rect_float + pixel*4;
+
+				*fp= (0.2126*rrgbf[0] + 0.7152*rrgbf[1] + 0.0722*rrgbf[2])/255;
+			} else {
+				char *rrgb= (char*)tmpibuf->rect + pixel*4;
+
+				*fp= (0.2126*rrgb[0] + 0.7152*rrgb[1] + 0.0722*rrgb[2])/255;
+			}
+
 			fp++;
 		}
 	}
@@ -964,7 +982,7 @@
 	MovieTrackingCamera *camera= &tracking->camera;
 
 #ifdef WITH_LIBMV
-	double x= nco[0], y= nco[1];
+	double x, y;
 
 	/* normalize coords */
 	x= (co[0]-camera->principal[0]) / camera->focal;
@@ -979,7 +997,22 @@
 #endif
 }
 
+void BKE_tracking_invert_intrinsics(MovieTracking *tracking, float co[2], float width, float height, float nco[2])
+{
+	MovieTrackingCamera *camera= &tracking->camera;
+
 #ifdef WITH_LIBMV
+	double x= co[0], y= co[1];
+
+	libmv_InvertIntrinsics(camera->focal, camera->principal[0], camera->principal[1],
+				camera->k1, camera->k2, camera->k3, x, y, &x, &y);
+
+	nco[0]= x * camera->focal + camera->principal[0];
+	nco[1]= y * camera->focal + camera->principal[1];
+#endif
+}
+
+#ifdef WITH_LIBMV
 /* flips upside-down */
 static unsigned char *acquire_ucharbuf(ImBuf *ibuf)
 {
@@ -990,11 +1023,19 @@
 	for(y= 0; y<ibuf->y; y++) {
 		for (x= 0; x<ibuf->x; x++) {
 			int pixel= ibuf->x*(ibuf->y-y-1) + x;
-			char *rrgb= (char*)ibuf->rect + pixel*4;
 
-			//*fp= 0.2126f*rrgb[0] + 0.7152f*rrgb[1] + 0.0722f*rrgb[2];
-			*fp= (11*rrgb[0]+16*rrgb[1]+5*rrgb[2])/32;
+			if(ibuf->rect_float) {
+				float *rrgbf= ibuf->rect_float + pixel*4;
 
+				//*fp= 0.2126f*rrgbf[0] + 0.7152f*rrgbf[1] + 0.0722f*rrgbf[2];
+				*fp= (11*rrgbf[0]+16*rrgbf[1]+5*rrgbf[2])/32;
+			} else {
+				char *rrgb= (char*)ibuf->rect + pixel*4;
+
+				//*fp= 0.2126f*rrgb[0] + 0.7152f*rrgb[1] + 0.0722f*rrgb[2];
+				*fp= (11*rrgb[0]+16*rrgb[1]+5*rrgb[2])/32;
+			}
+
 			fp++;
 		}
 	}

Modified: branches/soc-2011-tomato/source/blender/editors/include/ED_transform.h
===================================================================
--- branches/soc-2011-tomato/source/blender/editors/include/ED_transform.h	2011-07-20 15:58:04 UTC (rev 38545)
+++ branches/soc-2011-tomato/source/blender/editors/include/ED_transform.h	2011-07-20 20:31:25 UTC (rev 38546)
@@ -96,7 +96,7 @@
 #define CTX_AUTOCONFIRM		32
 #define CTX_BMESH			64
 #define CTX_NDOF			128
-#define CTX_VIDEOCLIP		256
+#define CTX_MOVIECLIP		256
 
 /* Standalone call to get the transformation center corresponding to the current situation
  * returns 1 if successful, 0 otherwise (usually means there's no selection)

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-07-20 15:58:04 UTC (rev 38545)
+++ branches/soc-2011-tomato/source/blender/editors/space_clip/clip_draw.c	2011-07-20 20:31:25 UTC (rev 38546)
@@ -579,6 +579,51 @@
 	*regiony= v2d->mask.ymin + y*(v2d->mask.ymax-v2d->mask.ymin);
 }
 
+static void draw_distorion_grid(MovieTracking *tracking, int width, int height)
+{
+	const int n= 9;
+	int x, y;
+	float pos[2], grid[10][10][2];
+	float dx= (float)width/n, dy= (float)height/n;
+
+	if(!tracking->camera.focal)
+		return;
+
+	zero_v2(pos);
+
+	for(y= 0; y<=n; y++) {
+		for(x= 0; x<=n; x++) {
+			BKE_tracking_invert_intrinsics(tracking, pos, width, height, grid[y][x]);
+
+			grid[y][x][0]/= width;
+			grid[y][x][1]/= height;
+
+			pos[0]+= dx;
+		}
+
+		pos[0]= 0.f;
+		pos[1]+= dy;
+	}
+
+	glColor3f(1.f, 0.f, 0.f);
+
+	for(y= 0; y<=n; y++) {
+		glBegin(GL_LINE_STRIP);
+			for(x= 0; x<=n; x++) {
+				glVertex2fv(grid[y][x]);
+			}
+		glEnd();
+	}
+
+	for(x= 0; x<=n; x++) {
+		glBegin(GL_LINE_STRIP);
+			for(y= 0; y<=n; y++) {
+				glVertex2fv(grid[y][x]);
+			}
+		glEnd();
+	}
+}
+
 static void draw_tracking_tracks(SpaceClip *sc, ARegion *ar, MovieClip *clip,
 			int width, int height, float zoomx, float zoomy)
 {
@@ -709,6 +754,9 @@
 		glDisable(GL_POINT_SMOOTH);
 	}
 
+	if(sc->flag&SC_SHOW_GRID)
+		draw_distorion_grid(tracking, width, height);
+
 	glPopMatrix();
 
 	if(sc->flag&SC_SHOW_NAMES) {

Modified: branches/soc-2011-tomato/source/blender/editors/transform/transform.c
===================================================================
--- branches/soc-2011-tomato/source/blender/editors/transform/transform.c	2011-07-20 15:58:04 UTC (rev 38545)
+++ branches/soc-2011-tomato/source/blender/editors/transform/transform.c	2011-07-20 20:31:25 UTC (rev 38546)
@@ -628,7 +628,7 @@
 				break;
 			case TFM_MODAL_ROTATE:
 				/* only switch when... */
-				if(!(t->options & CTX_TEXTURE) && !(t->options & CTX_VIDEOCLIP)) {
+				if(!(t->options & CTX_TEXTURE) && !(t->options & CTX_MOVIECLIP)) {
 					if( ELEM4(t->mode, TFM_ROTATION, TFM_RESIZE, TFM_TRACKBALL, TFM_TRANSLATION) ) {
 						
 						resetTransRestrictions(t);
@@ -883,7 +883,7 @@
 			break;
 		case RKEY:
 			/* only switch when... */
-			if(!(t->options & CTX_TEXTURE)) {
+			if(!(t->options & CTX_TEXTURE) && !(t->options & CTX_MOVIECLIP)) {
 				if( ELEM4(t->mode, TFM_ROTATION, TFM_RESIZE, TFM_TRACKBALL, TFM_TRANSLATION) ) {
 
 					resetTransRestrictions(t);
@@ -1587,7 +1587,7 @@
 	else if(t->spacetype == SPACE_CLIP) {
 		unit_m3(t->spacemtx);
 		t->draw_handle_view = ED_region_draw_cb_activate(t->ar->type, drawTransformView, t, REGION_DRAW_POST_VIEW);
-		t->options |= CTX_VIDEOCLIP;
+		t->options |= CTX_MOVIECLIP;
 	}
 	else
 		unit_m3(t->spacemtx);


@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list