[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [45624] branches/soc-2011-tomato: Camera tracking: support of tripod motion solving

Sergey Sharybin sergey.vfx at gmail.com
Sat Apr 14 14:02:47 CEST 2012


Revision: 45624
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=45624
Author:   nazgul
Date:     2012-04-14 12:02:47 +0000 (Sat, 14 Apr 2012)
Log Message:
-----------
Camera tracking: support of tripod motion solving

Expose option into interface to use modal solver which currently
supports only tripod motion.

This solver requires two tracks at least to reconstruct motion.
Using more tracks aren't improving solution in general, just adds
instability into solution and slows down things a lot.

Refirement of camera intrinsics is supported by this solver.

To use this solver just activate "Tripod Motion" checkbox in
solver panel.

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/intern/tracking.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/extern/libmv/libmv-capi.cpp
===================================================================
--- branches/soc-2011-tomato/extern/libmv/libmv-capi.cpp	2012-04-14 12:02:39 UTC (rev 45623)
+++ branches/soc-2011-tomato/extern/libmv/libmv-capi.cpp	2012-04-14 12:02:47 UTC (rev 45624)
@@ -54,6 +54,7 @@
 #include "libmv/simple_pipeline/pipeline.h"
 #include "libmv/simple_pipeline/camera_intrinsics.h"
 #include "libmv/simple_pipeline/rigid_registration.h"
+#include "libmv/simple_pipeline/modal_solver.h"
 
 #include <stdlib.h>
 #include <assert.h>
@@ -384,7 +385,32 @@
 	                       LIBMV_REFINE_RADIAL_DISTORTION_K1));
 }
 
+void libmv_solveRefineIntrinsics(libmv::Tracks *tracks, libmv::CameraIntrinsics *intrinsics,
+			libmv::EuclideanReconstruction *reconstruction, int refine_intrinsics,
+			reconstruct_progress_update_cb progress_update_callback, void *callback_customdata)
+{
+	/* only a few combinations are supported but trust the caller */
+	int libmv_refine_flags = 0;
 
+	if (refine_intrinsics & LIBMV_REFINE_FOCAL_LENGTH) {
+		libmv_refine_flags |= libmv::BUNDLE_FOCAL_LENGTH;
+	}
+	if (refine_intrinsics & LIBMV_REFINE_PRINCIPAL_POINT) {
+		libmv_refine_flags |= libmv::BUNDLE_PRINCIPAL_POINT;
+	}
+	if (refine_intrinsics & LIBMV_REFINE_RADIAL_DISTORTION_K1) {
+		libmv_refine_flags |= libmv::BUNDLE_RADIAL_K1;
+	}
+	if (refine_intrinsics & LIBMV_REFINE_RADIAL_DISTORTION_K2) {
+		libmv_refine_flags |= libmv::BUNDLE_RADIAL_K2;
+	}
+
+	progress_update_callback(callback_customdata, 1.0, "Refining solution");
+
+	libmv::EuclideanBundleCommonIntrinsics(*(libmv::Tracks *)tracks, libmv_refine_flags,
+		reconstruction, intrinsics);
+}
+
 libmv_Reconstruction *libmv_solveReconstruction(libmv_Tracks *tracks, int keyframe1, int keyframe2,
 			int refine_intrinsics, double focal_length, double principal_x, double principal_y, double k1, double k2, double k3,
 			reconstruct_progress_update_cb progress_update_callback, void *callback_customdata)
@@ -423,26 +449,50 @@
 	libmv::EuclideanCompleteReconstruction(normalized_tracks, reconstruction, &update_callback);
 
 	if (refine_intrinsics) {
-		/* only a few combinations are supported but trust the caller */
-		int libmv_refine_flags = 0;
-		if (refine_intrinsics & LIBMV_REFINE_FOCAL_LENGTH) {
-			libmv_refine_flags |= libmv::BUNDLE_FOCAL_LENGTH;
-		}
-		if (refine_intrinsics & LIBMV_REFINE_PRINCIPAL_POINT) {
-			libmv_refine_flags |= libmv::BUNDLE_PRINCIPAL_POINT;
-		}
-		if (refine_intrinsics & LIBMV_REFINE_RADIAL_DISTORTION_K1) {
-			libmv_refine_flags |= libmv::BUNDLE_RADIAL_K1;
-		}
-		if (refine_intrinsics & LIBMV_REFINE_RADIAL_DISTORTION_K2) {
-			libmv_refine_flags |= libmv::BUNDLE_RADIAL_K2;
-		}
+		libmv_solveRefineIntrinsics((libmv::Tracks *)tracks, intrinsics, reconstruction,
+			refine_intrinsics, progress_update_callback, callback_customdata);
+	}
 
-		progress_update_callback(callback_customdata, 1.0, "Refining solution");
-		libmv::EuclideanBundleCommonIntrinsics(*(libmv::Tracks *)tracks, libmv_refine_flags,
-			reconstruction, intrinsics);
+	progress_update_callback(callback_customdata, 1.0, "Finishing solution");
+	libmv_reconstruction->tracks = *(libmv::Tracks *)tracks;
+	libmv_reconstruction->error = libmv::EuclideanReprojectionError(*(libmv::Tracks *)tracks, *reconstruction, *intrinsics);
+
+	return (libmv_Reconstruction *)libmv_reconstruction;
+}
+
+struct libmv_Reconstruction *libmv_solveModal(struct libmv_Tracks *tracks, int refine_intrinsics, double focal_length,
+			double principal_x, double principal_y, double k1, double k2, double k3,
+			reconstruct_progress_update_cb progress_update_callback, void *callback_customdata)
+{
+	/* Invert the camera intrinsics. */
+	libmv::vector<libmv::Marker> markers = ((libmv::Tracks*)tracks)->AllMarkers();
+	libmv_Reconstruction *libmv_reconstruction = new libmv_Reconstruction();
+	libmv::EuclideanReconstruction *reconstruction = &libmv_reconstruction->reconstruction;
+	libmv::CameraIntrinsics *intrinsics = &libmv_reconstruction->intrinsics;
+
+	ReconstructUpdateCallback update_callback =
+		ReconstructUpdateCallback(progress_update_callback, callback_customdata);
+
+	intrinsics->SetFocalLength(focal_length, focal_length);
+	intrinsics->SetPrincipalPoint(principal_x, principal_y);
+	intrinsics->SetRadialDistortion(k1, k2, k3);
+
+	for (int i = 0; i < markers.size(); ++i) {
+		intrinsics->InvertIntrinsics(markers[i].x,
+			markers[i].y,
+			&(markers[i].x),
+			&(markers[i].y));
 	}
 
+	libmv::Tracks normalized_tracks(markers);
+
+	libmv::ModalSolver(normalized_tracks, reconstruction, &update_callback);
+
+	if (refine_intrinsics) {
+		libmv_solveRefineIntrinsics((libmv::Tracks *)tracks, intrinsics, reconstruction,
+			refine_intrinsics, progress_update_callback, callback_customdata);
+	}
+
 	progress_update_callback(callback_customdata, 1.0, "Finishing solution");
 	libmv_reconstruction->tracks = *(libmv::Tracks *)tracks;
 	libmv_reconstruction->error = libmv::EuclideanReprojectionError(*(libmv::Tracks *)tracks, *reconstruction, *intrinsics);

Modified: branches/soc-2011-tomato/extern/libmv/libmv-capi.h
===================================================================
--- branches/soc-2011-tomato/extern/libmv/libmv-capi.h	2012-04-14 12:02:39 UTC (rev 45623)
+++ branches/soc-2011-tomato/extern/libmv/libmv-capi.h	2012-04-14 12:02:47 UTC (rev 45624)
@@ -68,6 +68,9 @@
 struct libmv_Reconstruction *libmv_solveReconstruction(struct libmv_Tracks *tracks, int keyframe1, int keyframe2,
 			int refine_intrinsics, double focal_length, double principal_x, double principal_y, double k1, double k2, double k3,
 			reconstruct_progress_update_cb progress_update_callback, void *callback_customdata);
+struct libmv_Reconstruction *libmv_solveModal(struct libmv_Tracks *tracks, int refine_intrinsics, double focal_length,
+			double principal_x, double principal_y, double k1, double k2, double k3,
+			reconstruct_progress_update_cb progress_update_callback, void *callback_customdata);
 int libmv_reporojectionPointForTrack(struct libmv_Reconstruction *libmv_reconstruction, int track, double pos[3]);
 double libmv_reporojectionErrorForTrack(struct libmv_Reconstruction *libmv_reconstruction, int track);
 double libmv_reporojectionErrorForImage(struct libmv_Reconstruction *libmv_reconstruction, int image);

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	2012-04-14 12:02:39 UTC (rev 45623)
+++ branches/soc-2011-tomato/release/scripts/startup/bl_ui/space_clip.py	2012-04-14 12:02:47 UTC (rev 45624)
@@ -227,7 +227,11 @@
                      else "Object Motion")
         col.operator("clip.clear_solution")
 
+        col = layout.column()
+        col.prop(settings, "use_tripod_solver")
+
         col = layout.column(align=True)
+        col.active = not settings.use_tripod_solver
         col.prop(settings, "keyframe_a")
         col.prop(settings, "keyframe_b")
 

Modified: branches/soc-2011-tomato/source/blender/blenkernel/intern/tracking.c
===================================================================
--- branches/soc-2011-tomato/source/blender/blenkernel/intern/tracking.c	2012-04-14 12:02:39 UTC (rev 45623)
+++ branches/soc-2011-tomato/source/blender/blenkernel/intern/tracking.c	2012-04-14 12:02:47 UTC (rev 45624)
@@ -1523,6 +1523,7 @@
 #endif
 	char object_name[MAX_NAME];
 	int is_camera;
+	short motion_flag;
 
 	float focal_length;
 	float principal_point[2];
@@ -1752,7 +1753,11 @@
 #if WITH_LIBMV
 	ListBase *tracksbase = BKE_tracking_object_tracks(tracking, object);
 
-	if (count_tracks_on_both_keyframes(tracking, tracksbase)<8) {
+	if (tracking->settings.motion_flag & TRACKING_MOTION_MODAL) {
+		/* TODO: check for number of tracks? */
+		return TRUE;
+	}
+	else if (count_tracks_on_both_keyframes(tracking, tracksbase) < 8) {
 		BLI_strncpy(error_msg, "At least 8 common tracks on both of keyframes are needed for reconstruction", error_size);
 
 		return FALSE;
@@ -1781,7 +1786,8 @@
 	MovieTrackingTrack *track;
 
 	BLI_strncpy(context->object_name, object->name, sizeof(context->object_name));
-	context->is_camera = object->flag&TRACKING_OBJECT_CAMERA;
+	context->is_camera = object->flag & TRACKING_OBJECT_CAMERA;
+	context->motion_flag = tracking->settings.motion_flag;
 
 	context->tracks_map = tracks_map_new(context->object_name, context->is_camera, num_tracks, 0);
 
@@ -1894,13 +1900,23 @@
 	progressdata.stats_message = stats_message;
 	progressdata.message_size = message_size;
 
-	context->reconstruction = libmv_solveReconstruction(context->tracks,
-		context->keyframe1, context->keyframe2,
-		context->refine_flags,
-		context->focal_length,
-		context->principal_point[0], context->principal_point[1],
-		context->k1, context->k2, context->k3,
-		solve_reconstruction_update_cb, &progressdata);
+	if (context->motion_flag & TRACKING_MOTION_MODAL) {
+		context->reconstruction = libmv_solveModal(context->tracks,
+			context->refine_flags,
+			context->focal_length,
+			context->principal_point[0], context->principal_point[1],
+			context->k1, context->k2, context->k3,
+			solve_reconstruction_update_cb, &progressdata);
+	}
+	else {
+		context->reconstruction = libmv_solveReconstruction(context->tracks,
+			context->keyframe1, context->keyframe2,
+			context->refine_flags,
+			context->focal_length,
+			context->principal_point[0], context->principal_point[1],
+			context->k1, context->k2, context->k3,
+			solve_reconstruction_update_cb, &progressdata);
+	}
 
 	error = libmv_reprojectionError(context->reconstruction);
 

Modified: branches/soc-2011-tomato/source/blender/makesdna/DNA_tracking_types.h
===================================================================
--- branches/soc-2011-tomato/source/blender/makesdna/DNA_tracking_types.h	2012-04-14 12:02:39 UTC (rev 45623)
+++ branches/soc-2011-tomato/source/blender/makesdna/DNA_tracking_types.h	2012-04-14 12:02:47 UTC (rev 45624)
@@ -123,7 +123,7 @@
 	short default_pattern_match;		/* re-adjust every N frames */
 	short default_flag;					/* default flags like color channels used by default */
 
-	short pod;
+	short motion_flag;		/* flags describes motion type */
 
 	/* ** common tracker settings ** */
 	short speed;			/* speed of tracking */
@@ -131,8 +131,8 @@
 	/* ** reconstruction settings ** */

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list