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

Sergey Sharybin g.ulairi at gmail.com
Wed Jun 22 16:54:53 CEST 2011


Revision: 37733
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=37733
Author:   nazgul
Date:     2011-06-22 14:54:53 +0000 (Wed, 22 Jun 2011)
Log Message:
-----------
Camera tracking integraiton
===========================

- Corrected copyrights in my new files header.
- Added debug option to dump as PNG image content of search
  areas tracking between which was failed.
- Removed internal tracking settings like pyramid level and
  tolerance. Weren't useful neither for me nor for artists.
- Fixed bug in BKE_tracking_get_marker which could lead
  to failure of getting marker for current frame when
  there's marker for requested frame.
- Fixed bug with disappearing markers after tracking for
  cases when marker was added at frame different from
  tracking start frame and tracking start frame is
  equal to tracking end frame.
- Stop tracking when no markers could be tracked.
- Changed marker selection rules:
  * If marker isn't selected, all it's areas are getting
    selected with mouse.
  * If marker is selected and selection type doesn't have
    "extend" mode (SHIFT isn't holded down) the nearest
    to mouse cursor area would be selected. All the reast areas
    would loose selection.
- Limit number of frames which would be used in "Track Markers"
  operator. So now you could easily track along 10/20/etc frames.
- Change scene current frame after "Track Markers" operator.
- Implemented speed limitors. Now tracking could happen:
  * As fast as possible
  * With reatime speed (scene FPS)
  * With half of realtime speed
  * With quarter of realtime speed.
- Got rid of orig_user in MovieTrackingContext and user
  in TrackMarkersJob. This prevents crashes when user
  joins some space to SpaceClip from which tracking was started.
- Made keyframes on path bigger and do not draw keyframes for
  non-selected markers.

TODO: need to get rid of storing main, scene and screen
      in TrackMarkersJob. This is needed to set scene's
      current frame after tracking (such behavior is comfortable
      for artists) but this could lead to crash if scene is
      getting removed when tracking job is running.

      Render animation operator also stores scene and main,
      so such solution could be fine for first time before
      we've got something smarter.

Modified Paths:
--------------
    branches/soc-2011-tomato/extern/libmv/CMakeLists.txt
    branches/soc-2011-tomato/extern/libmv/libmv/tracking/trklt_region_tracker.cc
    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_moviecache.h
    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/moviecache.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/readfile.c
    branches/soc-2011-tomato/source/blender/editors/space_clip/CMakeLists.txt
    branches/soc-2011-tomato/source/blender/editors/space_clip/clip_buttons.c
    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_header.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_movieclip_types.h
    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/extern/libmv/CMakeLists.txt
===================================================================
--- branches/soc-2011-tomato/extern/libmv/CMakeLists.txt	2011-06-22 14:44:54 UTC (rev 37732)
+++ branches/soc-2011-tomato/extern/libmv/CMakeLists.txt	2011-06-22 14:54:53 UTC (rev 37733)
@@ -15,7 +15,7 @@
 # along with this program; if not, write to the Free Software Foundation,
 # Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 #
-# The Original Code is Copyright (C) 2006, Blender Foundation
+# The Original Code is Copyright (C) 2011 Blender Foundation.
 # All rights reserved.
 #
 # Contributor(s): Blender Foundation,

Modified: branches/soc-2011-tomato/extern/libmv/libmv/tracking/trklt_region_tracker.cc
===================================================================
--- branches/soc-2011-tomato/extern/libmv/libmv/tracking/trklt_region_tracker.cc	2011-06-22 14:44:54 UTC (rev 37732)
+++ branches/soc-2011-tomato/extern/libmv/libmv/tracking/trklt_region_tracker.cc	2011-06-22 14:54:53 UTC (rev 37733)
@@ -84,7 +84,7 @@
                                   float min_determinant,
                                   Vec2f *d) {
   float det = U.determinant();
-  if (det < min_determinant) {
+  if (fabsf(det) < min_determinant) {
     d->setZero();
     return false;
   }

Modified: branches/soc-2011-tomato/extern/libmv/libmv-capi.cpp
===================================================================
--- branches/soc-2011-tomato/extern/libmv/libmv-capi.cpp	2011-06-22 14:44:54 UTC (rev 37732)
+++ branches/soc-2011-tomato/extern/libmv/libmv-capi.cpp	2011-06-22 14:54:53 UTC (rev 37733)
@@ -17,7 +17,7 @@
  * along with this program; if not, write to the Free Software Foundation,
  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  *
- * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
+ * The Original Code is Copyright (C) 2011 Blender Foundation.
  * All rights reserved.
  *
  * Contributor(s): Blender Foundation,
@@ -26,6 +26,10 @@
  * ***** END GPL LICENSE BLOCK *****
  */
 
+/* define this to generate PNg images with content of search areas
+  tracking between which failed */
+#undef DUMP_FAILURE
+
 #include "libmv-capi.h"
 
 #include "libmv/tracking/klt_region_tracker.h"
@@ -35,6 +39,10 @@
 
 #include <stdlib.h>
 
+#ifdef DUMP_FAILURE
+#  include <png.h>
+#endif
+
 #define DEFAULT_WINDOW_HALFSIZE	5
 
 typedef struct ConfiguredRegionTracker {
@@ -72,14 +80,107 @@
 
 	for (y = 0; y < height; y++) {
 		for (x = 0; x < width; x++) {
-		  (*image)(y, x, 0) = buf[a++];
+			(*image)(y, x, 0) = buf[a++];
 		}
 	}
 }
 
+#ifdef DUMP_FAILURE
+void savePNGImage(png_bytep *row_pointers, int width, int height, int depth, int color_type, char *file_name)
+{
+	png_infop info_ptr;
+	png_structp png_ptr;
+	FILE *fp = fopen(file_name, "wb");
+
+	if (!fp)
+		return;
+
+	/* Initialize stuff */
+	png_ptr = png_create_write_struct(PNG_LIBPNG_VER_STRING, NULL, NULL, NULL);
+	info_ptr = png_create_info_struct(png_ptr);
+
+	if (setjmp(png_jmpbuf(png_ptr))) {
+		fclose(fp);
+		return;
+	}
+
+	png_init_io(png_ptr, fp);
+
+	/* write header */
+	if (setjmp(png_jmpbuf(png_ptr))) {
+		fclose(fp);
+		return;
+	}
+
+	png_set_IHDR(png_ptr, info_ptr, width, height,
+		depth, color_type, PNG_INTERLACE_NONE,
+		PNG_COMPRESSION_TYPE_BASE, PNG_FILTER_TYPE_BASE);
+
+	png_write_info(png_ptr, info_ptr);
+
+	/* write bytes */
+	if (setjmp(png_jmpbuf(png_ptr))) {
+		fclose(fp);
+		return;
+	}
+
+	png_write_image(png_ptr, row_pointers);
+
+	/* end write */
+	if (setjmp(png_jmpbuf(png_ptr))) {
+		fclose(fp);
+		return;
+	}
+
+	png_write_end(png_ptr, NULL);
+
+	fclose(fp);
+}
+
+static void saveImage(libmv::FloatImage image, int x0, int y0)
+{
+	int x, y;
+	png_bytep *row_pointers;
+
+	row_pointers= (png_bytep*)malloc(sizeof(png_bytep)*image.Height());
+
+	for (y = 0; y < image.Height(); y++) {
+		row_pointers[y]= (png_bytep)malloc(sizeof(png_byte)*4*image.Width());
+
+		for (x = 0; x < image.Width(); x++) {
+			if (x0 == x && y0 == y) {
+				row_pointers[y][x*4+0]= 255;
+				row_pointers[y][x*4+1]= 0;
+				row_pointers[y][x*4+2]= 0;
+				row_pointers[y][x*4+3]= 255;
+			}
+			else {
+				float pixel = image(y, x, 0);
+				row_pointers[y][x*4+0]= pixel*255;
+				row_pointers[y][x*4+1]= pixel*255;
+				row_pointers[y][x*4+2]= pixel*255;
+				row_pointers[y][x*4+3]= 255;
+			}
+		}
+	}
+
+	{
+		static int a= 0;
+		char buf[128];
+		snprintf(buf, sizeof(buf), "%02d.png", ++a);
+		savePNGImage(row_pointers, image.Width(), image.Height(), 8, PNG_COLOR_TYPE_RGBA, buf);
+	}
+
+	for (y = 0; y < image.Height(); y++) {
+		free(row_pointers[y]);
+	}
+	free(row_pointers);
+}
+#endif
+
 int libmv_regionTrackerTrack(libmv_regionTrackerHandle tracker, const float *ima1, const float *ima2,
 			 int width, int height, int half_window_size,
-			 double  x1, double  y1, double *x2, double *y2)
+			 double x1, double y1, double *x2, double *y2)
 {
 	ConfiguredRegionTracker *configured_region_tracker;
 	libmv::RegionTracker *region_tracker;
@@ -95,7 +196,21 @@
 	floatBufToImage(ima1, width, height, &old_patch);
 	floatBufToImage(ima2, width, height, &new_patch);
 
+#ifndef DUMP_FAILURE
 	return region_tracker->Track(old_patch, new_patch, x1, y1, x2, y2);
+#else
+	{
+		double sx2 = *x2, sy2 = *y2;
+		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);
+		}
+
+		return result;
+	}
+#endif
 }
 
 void libmv_regionTrackerDestroy(libmv_regionTrackerHandle tracker)

Modified: branches/soc-2011-tomato/extern/libmv/libmv-capi.h
===================================================================
--- branches/soc-2011-tomato/extern/libmv/libmv-capi.h	2011-06-22 14:44:54 UTC (rev 37732)
+++ branches/soc-2011-tomato/extern/libmv/libmv-capi.h	2011-06-22 14:54:53 UTC (rev 37733)
@@ -17,7 +17,7 @@
  * along with this program; if not, write to the Free Software Foundation,
  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  *
- * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
+ * The Original Code is Copyright (C) 2011 Blender Foundation.
  * All rights reserved.
  *
  * Contributor(s): Blender Foundation,

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-06-22 14:44:54 UTC (rev 37732)
+++ branches/soc-2011-tomato/release/scripts/startup/bl_ui/space_clip.py	2011-06-22 14:54:53 UTC (rev 37733)
@@ -110,12 +110,12 @@
         clip = context.space_data.clip
         settings = clip.tracking.settings
 
-        layout.prop(settings, "max_iterations")
-        layout.prop(settings, "pyramid_level")
-        layout.prop(settings, "tolerance")
+        layout.prop(settings, "speed")
+        layout.prop(settings, "use_frames_limit")
 
-        layout.operator("clip.reset_tracking_settings", \
-            text="Reset To Defaults")
+        row = layout.row()
+        row.active = settings.use_frames_limit
+        row.prop(settings, "frames_limit")
 
 
 class CLIP_PT_tracking_camera(bpy.types.Panel):

Modified: branches/soc-2011-tomato/source/blender/blenkernel/BKE_moviecache.h
===================================================================
--- branches/soc-2011-tomato/source/blender/blenkernel/BKE_moviecache.h	2011-06-22 14:44:54 UTC (rev 37732)
+++ branches/soc-2011-tomato/source/blender/blenkernel/BKE_moviecache.h	2011-06-22 14:54:53 UTC (rev 37733)
@@ -17,7 +17,7 @@
  * along with this program; if not, write to the Free Software Foundation,
  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  *
- * The Original Code is Copyright (C) Blender Foundation.
+ * The Original Code is Copyright (C) 2011 Blender Foundation.
  * All rights reserved.
  *
  * Contributor(s): Blender Foundation,

Modified: branches/soc-2011-tomato/source/blender/blenkernel/BKE_movieclip.h
===================================================================
--- branches/soc-2011-tomato/source/blender/blenkernel/BKE_movieclip.h	2011-06-22 14:44:54 UTC (rev 37732)
+++ branches/soc-2011-tomato/source/blender/blenkernel/BKE_movieclip.h	2011-06-22 14:54:53 UTC (rev 37733)
@@ -17,7 +17,7 @@
  * along with this program; if not, write to the Free Software Foundation,
  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  *
- * The Original Code is Copyright (C) Blender Foundation.
+  * The Original Code is Copyright (C) 2011 Blender Foundation.
  * All rights reserved.
  *
  * Contributor(s): Blender Foundation,

Modified: branches/soc-2011-tomato/source/blender/blenkernel/BKE_tracking.h
===================================================================
--- branches/soc-2011-tomato/source/blender/blenkernel/BKE_tracking.h	2011-06-22 14:44:54 UTC (rev 37732)
+++ branches/soc-2011-tomato/source/blender/blenkernel/BKE_tracking.h	2011-06-22 14:54:53 UTC (rev 37733)
@@ -17,7 +17,7 @@
  * along with this program; if not, write to the Free Software Foundation,
  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  *
- * The Original Code is Copyright (C) Blender Foundation.
+ * The Original Code is Copyright (C) 2011 Blender Foundation.
  * All rights reserved.
  *
  * Contributor(s): Blender Foundation,
@@ -58,10 +58,9 @@
 struct MovieTrackingContext *BKE_tracking_context_new(struct MovieClip *clip, struct MovieClipUser *user, int backwards);
 void BKE_tracking_context_free(struct MovieTrackingContext *context);
 void BKE_tracking_sync(struct MovieTrackingContext *context);
+void BKE_tracking_sync_user(struct MovieClipUser *user, struct MovieTrackingContext *context);
 int BKE_tracking_next(struct MovieTrackingContext *context);
 
-void BKE_tracking_reset_settings(struct MovieTracking *tracking);
-
 #define TRACK_SELECTED(track) ((track)->flag&SELECT || (track)->pat_flag&SELECT || (track)->search_flag&SELECT)
 #define TRACK_AREA_SELECTED(track, area) ((area)==TRACK_AREA_POINT?(track)->flag&SELECT : ((area)==TRACK_AREA_PAT?(track)->pat_flag&SELECT:(track)->search_flag&SELECT))
 
@@ -70,7 +69,7 @@
 #define CLAMP_SEARCH_DIM	3
 #define CLAMP_SEARCH_POS	4
 
-#define TRACK_AREA_NONE	-	1
+#define TRACK_AREA_NONE		-1
 #define TRACK_AREA_POINT	1
 #define TRACK_AREA_PAT		2
 #define TRACK_AREA_SEARCH	4

Modified: branches/soc-2011-tomato/source/blender/blenkernel/intern/moviecache.c

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list