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

Sergey Sharybin g.ulairi at gmail.com
Sat Oct 29 09:14:33 CEST 2011


Revision: 41356
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=41356
Author:   nazgul
Date:     2011-10-29 07:14:31 +0000 (Sat, 29 Oct 2011)
Log Message:
-----------
Camera tracking integration
===========================

DeBalie commit (main changes only):

- Code cleanup
- Selectable tracking graph curves and curve knots
- Graph curve and curve knots can be deleted now
- Fixed wrong write when linking libraries
  (error is caused by hardcoded cound of linkable ID blocks)
- Fixed for KLT tracker when using keyframe adjustment

Modified Paths:
--------------
    branches/soc-2011-tomato/extern/libmv/libmv-capi.cpp
    branches/soc-2011-tomato/source/blender/blenkernel/intern/DerivedMesh.c
    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/writefile.c
    branches/soc-2011-tomato/source/blender/editors/interface/resources.c
    branches/soc-2011-tomato/source/blender/editors/space_clip/CMakeLists.txt
    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/clip_ops.c
    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/makesdna/DNA_ID.h
    branches/soc-2011-tomato/source/blender/makesdna/DNA_tracking_types.h
    branches/soc-2011-tomato/source/blender/makesrna/intern/rna_tracking.c
    branches/soc-2011-tomato/source/blender/makesrna/intern/rna_userdef.c
    branches/soc-2011-tomato/source/blender/nodes/composite/nodes/node_composite_moviedistortion.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

Added Paths:
-----------
    branches/soc-2011-tomato/source/blender/editors/space_clip/clip_draw.c
    branches/soc-2011-tomato/source/blender/editors/space_clip/clip_graph_draw.c
    branches/soc-2011-tomato/source/blender/editors/space_clip/clip_graph_ops.c
    branches/soc-2011-tomato/source/blender/editors/space_clip/clip_utils.c

Removed Paths:
-------------
    branches/soc-2011-tomato/source/blender/editors/space_clip/clip_draw_graph.c
    branches/soc-2011-tomato/source/blender/editors/space_clip/clip_draw_main.c

Modified: branches/soc-2011-tomato/extern/libmv/libmv-capi.cpp
===================================================================
--- branches/soc-2011-tomato/extern/libmv/libmv-capi.cpp	2011-10-29 06:57:50 UTC (rev 41355)
+++ branches/soc-2011-tomato/extern/libmv/libmv-capi.cpp	2011-10-29 07:14:31 UTC (rev 41356)
@@ -198,7 +198,7 @@
 	fclose(fp);
 }
 
-static void saveImage(libmv::FloatImage image, int x0, int y0)
+static void saveImage(char *prefix, libmv::FloatImage image, int x0, int y0)
 {
 	int x, y;
 	png_bytep *row_pointers;
@@ -228,7 +228,7 @@
 	{
 		static int a= 0;
 		char buf[128];
-		snprintf(buf, sizeof(buf), "%02d.png", ++a);
+		snprintf(buf, sizeof(buf), "%s_%02d.png", prefix, ++a);
 		savePNGImage(row_pointers, image.Width(), image.Height(), 8, PNG_COLOR_TYPE_RGBA, buf);
 	}
 
@@ -238,7 +238,7 @@
 	free(row_pointers);
 }
 
-static void saveBytesImage(unsigned char *data, int width, int height)
+static void saveBytesImage(char *prefix, unsigned char *data, int width, int height)
 {
 	int x, y;
 	png_bytep *row_pointers;
@@ -260,7 +260,7 @@
 	{
 		static int a= 0;
 		char buf[128];
-		snprintf(buf, sizeof(buf), "%02d.png", ++a);
+		snprintf(buf, sizeof(buf), "%s_%02d.png", prefix, ++a);
 		savePNGImage(row_pointers, width, height, 8, PNG_COLOR_TYPE_RGBA, buf);
 	}
 
@@ -295,8 +295,8 @@
 		int result = region_tracker->Track(old_patch, new_patch, x1, y1, x2, y2);
 
 		if (!result) {
-			saveImage(old_patch, x1, y1);
-			saveImage(new_patch, sx2, sy2);
+			saveImage("old_patch", old_patch, x1, y1);
+			saveImage("new_patch", new_patch, sx2, sy2);
 		}
 
 		return result;

Modified: branches/soc-2011-tomato/source/blender/blenkernel/intern/DerivedMesh.c
===================================================================
--- branches/soc-2011-tomato/source/blender/blenkernel/intern/DerivedMesh.c	2011-10-29 06:57:50 UTC (rev 41355)
+++ branches/soc-2011-tomato/source/blender/blenkernel/intern/DerivedMesh.c	2011-10-29 07:14:31 UTC (rev 41356)
@@ -1190,6 +1190,7 @@
 
 	/* TODO what to do with vert_r->flag? */
 	vert_r->bweight = (unsigned char) (ev->bweight*255.0f);
+	vert_r->flag= ev->f;
 }
 
 static void emDM_getEdge(DerivedMesh *dm, int index, MEdge *edge_r)

Modified: branches/soc-2011-tomato/source/blender/blenkernel/intern/movieclip.c
===================================================================
--- branches/soc-2011-tomato/source/blender/blenkernel/intern/movieclip.c	2011-10-29 06:57:50 UTC (rev 41355)
+++ branches/soc-2011-tomato/source/blender/blenkernel/intern/movieclip.c	2011-10-29 07:14:31 UTC (rev 41356)
@@ -83,7 +83,7 @@
 {
 	char num[FILE_MAX]= {0};
 
-	BLI_strncpy(num, full_name+head_len, numlen);
+	BLI_strncpy(num, full_name+head_len, numlen+1);
 
 	return atoi(num);
 }
@@ -387,12 +387,12 @@
 	clip->tracking.settings.keyframe1= 1;
 	clip->tracking.settings.keyframe2= 30;
 	clip->tracking.settings.dist= 1;
-	clip->tracking.settings.corr= 0.75;
+	clip->tracking.settings.corr= 0.75f;
 
-	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->tracking.stabilization.scaleinf= 1.0f;
+	clip->tracking.stabilization.locinf= 1.0f;
+	clip->tracking.stabilization.rotinf= 1.0f;
+	clip->tracking.stabilization.maxscale= 2.0f;
 
 	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;
@@ -454,7 +454,7 @@
 		clip->tracking.camera.principal[0]= ((float)width)/2;
 		clip->tracking.camera.principal[1]= ((float)height)/2;
 
-		clip->tracking.camera.focal= 24.f*width/clip->tracking.camera.sensor_width;
+		clip->tracking.camera.focal= 24.0f*width/clip->tracking.camera.sensor_width;
 	}
 
 	return clip;
@@ -473,13 +473,13 @@
 				break;
 
 			case MCLIP_PROXY_RENDER_SIZE_50:
-				(*width)*= 2;
-				(*height)*= 2;
+				(*width)*= 2.0f;
+				(*height)*= 2.0f;
 				break;
 
 			case MCLIP_PROXY_RENDER_SIZE_75:
-				*width= ((float)*width)*4.f/3.f;
-				*height= ((float)*height)*4.f/3.f;
+				*width= ((float)*width)*4.0f/3.0f;
+				*height= ((float)*height)*4.0f/3.0f;
 				break;
 		}
 	}
@@ -535,9 +535,9 @@
 	imb_freerectfloatImBuf(ibuf);
 
 	if(distoriton)
-		undistibuf= BKE_tracking_distortion_exec(distoriton, &clip->tracking, ibuf, ibuf->x, ibuf->y, 0.f, 1);
+		undistibuf= BKE_tracking_distortion_exec(distoriton, &clip->tracking, ibuf, ibuf->x, ibuf->y, 0.0f, 1);
 	else
-		undistibuf= BKE_tracking_undistort(&clip->tracking, ibuf, ibuf->x, ibuf->y, 0.f);
+		undistibuf= BKE_tracking_undistort(&clip->tracking, ibuf, ibuf->x, ibuf->y, 0.0f);
 
 	if(undistibuf->userflags|= IB_RECT_INVALID) {
 		ibuf->userflags&= ~IB_RECT_INVALID;
@@ -645,7 +645,6 @@
 			cache_undistorted= 1;
 	}
 
-	/* cache is supposed to be threadsafe */
 	ibuf= get_imbuf_cache(clip, user, flag);
 
 	if(!ibuf) {
@@ -730,8 +729,8 @@
 		if(angle)	*angle= tangle;
 	} else {
 		if(loc)		zero_v2(loc);
-		if(scale)	*scale= 1.f;
-		if(angle)	*angle= 0.f;
+		if(scale)	*scale= 1.0f;
+		if(angle)	*angle= 0.0f;
 
 		stableibuf= ibuf;
 	}
@@ -895,7 +894,7 @@
 
 					if(user->render_flag&MCLIP_PROXY_RENDER_UNDISTORT) {
 						int width, height;
-						float aspy= 1.f/clip->tracking.camera.pixel_aspect;;
+						float aspy= 1.0f/clip->tracking.camera.pixel_aspect;;
 
 						BKE_movieclip_get_size(clip, user, &width, &height);
 
@@ -944,8 +943,8 @@
 
 	get_proxy_fname(clip, proxy_render_size, undistorted, cfra, name);
 
-	rectx= ibuf->x*size/100.f;
-	recty= ibuf->y*size/100.f;
+	rectx= ibuf->x*size/100.0f;
+	recty= ibuf->y*size/100.0f;
 
 	scaleibuf= IMB_dupImBuf(ibuf);
 

Modified: branches/soc-2011-tomato/source/blender/blenkernel/intern/tracking.c
===================================================================
--- branches/soc-2011-tomato/source/blender/blenkernel/intern/tracking.c	2011-10-29 06:57:50 UTC (rev 41355)
+++ branches/soc-2011-tomato/source/blender/blenkernel/intern/tracking.c	2011-10-29 07:14:31 UTC (rev 41356)
@@ -42,6 +42,7 @@
 
 #include "BLI_utildefines.h"
 #include "BLI_math.h"
+#include "BLI_math_base.h"
 #include "BLI_listbase.h"
 #include "BLI_ghash.h"
 #include "BLI_path_util.h"
@@ -131,8 +132,8 @@
 		sub_v2_v2v2(dim, track->pat_max, track->pat_min);
 
 		for(a= 0; a<2; a++) {
-			track->pat_min[a]= -dim[a]/2.f;
-			track->pat_max[a]= dim[a]/2.f;
+			track->pat_min[a]= -dim[a]/2.0f;
+			track->pat_max[a]= dim[a]/2.0f;
 		}
 	}
 }
@@ -163,11 +164,11 @@
 	/* 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;
+		pat[0]= 8.0f;
+		pat[1]= 8.0f;
 
-		search[0]= 32.f;
-		search[1]= 32.f;
+		search[0]= 32.0f;
+		search[1]= 32.0f;
 	}
 
 	pat[0] /= (float)width;
@@ -478,6 +479,8 @@
 	MovieTrackingTrack *track;
 
 #ifdef WITH_LIBMV
+	float keyframed_pos[2];
+
 	/* ** KLT tracker ** */
 	struct libmv_RegionTracker *region_tracker;
 	float *patch;			/* keyframed patch */
@@ -670,16 +673,12 @@
 	w= (x2-x1)|1;
 	h= (y2-y1)|1;
 
-	/* happens due to rounding issues */
-	if(x1+w<=x) x1++;
-	if(y1+h<=y) y1++;
-
 	tmpibuf= IMB_allocImBuf(w+margin*2, h+margin*2, 32, IB_rect);
 	IMB_rectcpy(tmpibuf, ibuf, 0, 0, x1-margin, y1-margin, w+margin*2, h+margin*2);
 
 	if(pos != NULL) {
-		pos[0]= x-x1+(mpos[0]*ibuf->x-x)+margin;
-		pos[1]= y-y1+(mpos[1]*ibuf->y-y)+margin;
+		pos[0]= mpos[0]*ibuf->x-x1+margin;
+		pos[1]= mpos[1]*ibuf->y-y1+margin;
 	}
 
 	if(origin != NULL) {
@@ -731,7 +730,7 @@
 
 				*fp= 0.2126*rrgbf[0] + 0.7152*rrgbf[1] + 0.0722*rrgbf[2];
 			} else {
-				char *rrgb= (char*)tmpibuf->rect + pixel*4;
+				unsigned char *rrgb= (unsigned char*)tmpibuf->rect + pixel*4;
 
 				*fp= (0.2126*rrgb[0] + 0.7152*rrgb[1] + 0.0722*rrgb[2])/255.0f;
 			}
@@ -986,7 +985,7 @@
 			double x1, y1, x2, y2;
 			ImBuf *ibuf= NULL;
 			MovieTrackingMarker marker_new, *marker_keyed;
-			int onbound= 0;
+			int onbound= 0, coords_correct= 0;
 
 			if(!context->settings.adjframes) need_readjust= context->first_time;
 			else need_readjust= context->frames%context->settings.adjframes == 0;
@@ -998,8 +997,8 @@
 			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]) {
+			if(marker->pos[0]<margin[0] || marker->pos[0]>1.0f-margin[0] ||
+			   marker->pos[1]<margin[1] || marker->pos[1]>1.0f-margin[1]) {
 				onbound= 1;
 			}
 			else if(context->settings.tracker==TRACKER_KLT) {
@@ -1013,18 +1012,18 @@
 					if(track_context->patch)
 						MEM_freeN(track_context->patch);
 
-					track_context->patch= get_search_floatbuf(ibuf, track, marker_keyed, &width, &height, pos, origin);
+					track_context->patch= get_search_floatbuf(ibuf, track, marker_keyed, &width, &height, track_context->keyframed_pos, origin);
 
 					IMB_freeImBuf(ibuf);
 				}
 
 				patch_new= get_search_floatbuf(ibuf_new, track, marker, &width, &height, pos, origin);
 
-				x1= pos[0];
-				y1= pos[1];
+				x1= track_context->keyframed_pos[0];
+				y1= track_context->keyframed_pos[1];
 
-				x2= x1;
-				y2= y1;
+				x2= pos[0];
+				y2= pos[1];
 
 				wndx= (int)((track->pat_max[0]-track->pat_min[0])*ibuf_new->x)/2;
 				wndy= (int)((track->pat_max[1]-track->pat_min[1])*ibuf_new->y)/2;
@@ -1100,7 +1099,8 @@
 				MEM_freeN(image_new);
 			}
 
-			if(tracked || !context->disable_failed) {
+			coords_correct= !isnan(x2) && !isnan(y2) && finite(x2) && finite(y2);
+			if(coords_correct && (tracked || !context->disable_failed)) {
 				if(context->first_time) {
 					int prevframe;
 
@@ -1113,6 +1113,7 @@
 						marker_new= *marker;
 						marker_new.framenr= prevframe;
 
+						marker_new.flag&= ~MARKER_GRAPH_SEL;
 						marker_new.flag|= MARKER_DISABLED;
 
 						#pragma omp critical
@@ -1201,7 +1202,7 @@
 	MovieTrackingTrack *track;
 	MovieTrackingReconstruction *reconstruction= &tracking->reconstruction;
 	MovieReconstructedCamera *reconstructed;
-	float origin[3]= {0.0f, 0.f, 0.0f};
+	float origin[3]= {0.0f, 0.0f, 0.0f};
 	int ok= 1;
 
 	track= tracking->tracks.first;
@@ -1295,7 +1296,7 @@
 #if WITH_LIBMV
 	{
 		MovieTrackingCamera *camera= &tracking->camera;
-		float aspy= 1.f/tracking->camera.pixel_aspect;
+		float aspy= 1.0f/tracking->camera.pixel_aspect;
 		struct libmv_Tracks *tracks= create_libmv_tracks(tracking, width, height*aspy);

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list