[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [41725] branches/soc-2011-tomato: Camera tracking integration: cleanup and finish some parts of recent commit

Sergey Sharybin g.ulairi at gmail.com
Thu Nov 10 12:16:34 CET 2011


Revision: 41725
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=41725
Author:   nazgul
Date:     2011-11-10 11:16:33 +0000 (Thu, 10 Nov 2011)
Log Message:
-----------
Camera tracking integration: cleanup and finish some parts of recent commit

- Replace set of booleans with menu, so now you'll simply be unable to choose
  unsupported refine combination
- Some internal code cleanup and minor refactor

Modified Paths:
--------------
    branches/soc-2011-tomato/extern/libmv/libmv-capi.cpp
    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/space_clip/tracking_ops.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	2011-11-10 10:34:26 UTC (rev 41724)
+++ branches/soc-2011-tomato/extern/libmv/libmv-capi.cpp	2011-11-10 11:16:33 UTC (rev 41725)
@@ -397,10 +397,10 @@
 
 	libmv::Tracks normalized_tracks(markers);
 
-	printf("frames to init from: %d, %d\n", keyframe1, keyframe2);
+	// printf("frames to init from: %d, %d\n", keyframe1, keyframe2);
 	libmv::vector<libmv::Marker> keyframe_markers =
 		normalized_tracks.MarkersForTracksInBothImages(keyframe1, keyframe2);
-	printf("number of markers for init: %d\n", keyframe_markers.size());
+	// printf("number of markers for init: %d\n", keyframe_markers.size());
 
 	libmv::EuclideanReconstructTwoFrames(keyframe_markers, reconstruction);
 	libmv::EuclideanBundle(normalized_tracks, reconstruction);

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-11-10 10:34:26 UTC (rev 41724)
+++ branches/soc-2011-tomato/release/scripts/startup/bl_ui/space_clip.py	2011-11-10 11:16:33 UTC (rev 41725)
@@ -157,16 +157,15 @@
         col.operator("clip.solve_camera")
         col.operator("clip.clear_solution")
 
-        layout.prop(settings, "refine_focal_length")
-        layout.prop(settings, "refine_principal_point")
-        layout.prop(settings, "refine_radial_distortion_k1")
-        layout.prop(settings, "refine_radial_distortion_k2")
-
         col = layout.column(align=True)
         col.prop(settings, "keyframe_a")
         col.prop(settings, "keyframe_b")
 
+        col = layout.column(align=True)
+        col.label(text="Refine:")
+        col.prop(settings, "refine_intrinsics", text="")
 
+
 class CLIP_PT_tools_cleanup(Panel):
     bl_space_type = 'CLIP_EDITOR'
     bl_region_type = 'TOOLS'

Modified: branches/soc-2011-tomato/source/blender/blenkernel/BKE_tracking.h
===================================================================
--- branches/soc-2011-tomato/source/blender/blenkernel/BKE_tracking.h	2011-11-10 10:34:26 UTC (rev 41724)
+++ branches/soc-2011-tomato/source/blender/blenkernel/BKE_tracking.h	2011-11-10 11:16:33 UTC (rev 41725)
@@ -91,6 +91,8 @@
 int BKE_tracking_next(struct MovieTrackingContext *context);
 
 /* Camera solving */
+int BKE_tracking_can_solve(struct MovieTracking *tracking, char *error_msg, int error_size);
+
 float BKE_tracking_solve_reconstruction(struct MovieTracking *tracking, int width, int height);
 
 struct MovieReconstructedCamera *BKE_tracking_get_reconstructed_camera(struct MovieTracking *tracking, int framenr);

Modified: branches/soc-2011-tomato/source/blender/blenkernel/intern/tracking.c
===================================================================
--- branches/soc-2011-tomato/source/blender/blenkernel/intern/tracking.c	2011-11-10 10:34:26 UTC (rev 41724)
+++ branches/soc-2011-tomato/source/blender/blenkernel/intern/tracking.c	2011-11-10 11:16:33 UTC (rev 41725)
@@ -47,6 +47,7 @@
 #include "BLI_listbase.h"
 #include "BLI_ghash.h"
 #include "BLI_path_util.h"
+#include "BLI_string.h"
 
 #include "BKE_global.h"
 #include "BKE_tracking.h"
@@ -1257,8 +1258,29 @@
 	return tracks;
 }
 
-static int retrieve_libmv_reconstruct(MovieTracking *tracking, struct libmv_Reconstruction *libmv_reconstruction)
+static void retrieve_libmv_reconstruct_intrinscis(MovieTracking *tracking, struct libmv_Reconstruction *libmv_reconstruction)
 {
+	struct libmv_CameraIntrinsics *libmv_intrinsics = libmv_ReconstructionExtractIntrinsics(libmv_reconstruction);
+
+	float aspy= 1.0f/tracking->camera.pixel_aspect;
+
+	double focal_length, principal_x, principal_y, k1, k2, k3;
+	int width, height;
+
+	libmv_CameraIntrinsicsExtract(libmv_intrinsics, &focal_length, &principal_x, &principal_y,
+			&k1, &k2, &k3, &width, &height);
+
+	tracking->camera.focal= focal_length;
+	tracking->camera.principal[0]= principal_x;
+
+	/* todo: verify divide by aspy is correct */
+	tracking->camera.principal[1]= principal_y / aspy;
+	tracking->camera.k1= k1;
+	tracking->camera.k2= k2;
+}
+
+static int retrieve_libmv_reconstruct_tracks(MovieTracking *tracking, struct libmv_Reconstruction *libmv_reconstruction)
+{
 	int tracknr= 0;
 	int sfra= INT_MAX, efra= INT_MIN, a, origin_set= 0;
 	MovieTrackingTrack *track;
@@ -1267,24 +1289,6 @@
 	float origin[3]= {0.0f, 0.0f, 0.0f};
 	int ok= 1;
 
-	/* take the intrinscis back from libmv */
-	{
-		struct libmv_CameraIntrinsics *libmv_intrinsics = libmv_ReconstructionExtractIntrinsics(libmv_reconstruction);
-
-		float aspy= 1.0f/tracking->camera.pixel_aspect;
-
-		double focal_length, principal_x, principal_y, k1, k2, k3;
-		int width, height;
-		libmv_CameraIntrinsicsExtract(libmv_intrinsics, &focal_length, &principal_x, &principal_y,
-				&k1, &k2, &k3, &width, &height);
-		tracking->camera.focal = focal_length;
-		tracking->camera.principal[0] = principal_x;
-		/* todo: verify divide by aspy is correct */
-		tracking->camera.principal[1] = principal_y / aspy; 
-		tracking->camera.k1 = k1;
-		tracking->camera.k2 = k2;
-	}
-
 	track= tracking->tracks.first;
 	while(track) {
 		double pos[3];
@@ -1369,19 +1373,79 @@
 	return ok;
 }
 
+static int retrieve_libmv_reconstruct(MovieTracking *tracking, struct libmv_Reconstruction *libmv_reconstruction)
+{
+	/* take the intrinscis back from libmv */
+	retrieve_libmv_reconstruct_intrinscis(tracking, libmv_reconstruction);
+
+	return retrieve_libmv_reconstruct_tracks(tracking, libmv_reconstruction);
+}
+
+static int get_refine_intrinsics_flags(MovieTracking *tracking)
+{
+	int refine= tracking->settings.refine_camera_intrinsics;
+	int flags= 0;
+
+	if(refine&REFINE_FOCAL_LENGTH)
+		flags|= LIBMV_REFINE_FOCAL_LENGTH;
+
+	if(refine&REFINE_PRINCIPAL_POINT)
+		flags|= LIBMV_REFINE_PRINCIPAL_POINT;
+
+	if(refine&REFINE_RADIAL_DISTORTION_K1)
+		flags|= REFINE_RADIAL_DISTORTION_K1;
+
+	if(refine&REFINE_RADIAL_DISTORTION_K2)
+		flags|= REFINE_RADIAL_DISTORTION_K2;
+
+	return flags;
+}
+
+static int count_tracks_on_both_keyframes(MovieTracking *tracking)
+{
+	int tot= 0;
+	int frame1= tracking->settings.keyframe1, frame2= tracking->settings.keyframe2;
+	MovieTrackingTrack *track;
+
+	track= tracking->tracks.first;
+	while(track) {
+		if(BKE_tracking_has_marker(track, frame1))
+			if(BKE_tracking_has_marker(track, frame2))
+				tot++;
+
+		track= track->next;
+	}
+
+	return tot;
+}
 #endif
 
+int BKE_tracking_can_solve(MovieTracking *tracking, char *error_msg, int error_size)
+{
+#if WITH_LIBMV
+	if(count_tracks_on_both_keyframes(tracking)<8) {
+		BLI_strncpy(error_msg, "At least 8 tracks on both of keyframes are needed for reconstruction", error_size);
+		return 0;
+	}
+
+	return 1;
+#else
+	BLI_strncpy(error_msg, "Blender is compiled without motion tracking library", error_size);
+
+	return 0;
+#endif
+}
+
 float BKE_tracking_solve_reconstruction(MovieTracking *tracking, int width, int height)
 {
 #if WITH_LIBMV
 	{
 		MovieTrackingCamera *camera= &tracking->camera;
 		float aspy= 1.0f/tracking->camera.pixel_aspect;
-		
 		struct libmv_Tracks *tracks= create_libmv_tracks(tracking, width, height*aspy);
 		struct libmv_Reconstruction *reconstruction = libmv_solveReconstruction(tracks,
 		        tracking->settings.keyframe1, tracking->settings.keyframe2,
-		        tracking->settings.refine_camera_intrinsics,
+		        get_refine_intrinsics_flags(tracking),
 		        camera->focal,
 		        camera->principal[0], camera->principal[1]*aspy,
 		        camera->k1, camera->k2, camera->k3);

Modified: branches/soc-2011-tomato/source/blender/editors/space_clip/tracking_ops.c
===================================================================
--- branches/soc-2011-tomato/source/blender/editors/space_clip/tracking_ops.c	2011-11-10 10:34:26 UTC (rev 41724)
+++ branches/soc-2011-tomato/source/blender/editors/space_clip/tracking_ops.c	2011-11-10 11:16:33 UTC (rev 41725)
@@ -1504,24 +1504,6 @@
 
 /********************** solve camera operator *********************/
 
-static int check_solve_track_count(MovieTracking *tracking)
-{
-	int tot= 0;
-	int frame1= tracking->settings.keyframe1, frame2= tracking->settings.keyframe2;
-	MovieTrackingTrack *track;
-
-	track= tracking->tracks.first;
-	while(track) {
-		if(BKE_tracking_has_marker(track, frame1))
-			if(BKE_tracking_has_marker(track, frame2))
-				tot++;
-
-		track= track->next;
-	}
-
-	return tot>=8;
-}
-
 static int solve_camera_exec(bContext *C, wmOperator *op)
 {
 	SpaceClip *sc= CTX_wm_space_clip(C);
@@ -1530,18 +1512,13 @@
 	MovieTracking *tracking= &clip->tracking;
 	int width, height;
 	float error;
+	char error_msg[255];
 
-	if(!check_solve_track_count(tracking)) {
-		BKE_report(op->reports, RPT_ERROR, "At least 8 tracks on both of keyframes are needed for reconstruction");
+	if(!BKE_tracking_can_solve(tracking, error_msg, sizeof(error_msg))) {
+		BKE_report(op->reports, RPT_ERROR, error_msg);
+
 		return OPERATOR_CANCELLED;
 	}
-        /* XXX sergey, please fix this. it's not obvious to me that it is not
-         * an encapsulation violation to call the libmv c api from here. */
-        /*
-	if(!libmv_refineParametersAreValid(tracking->settings.refine_camera_intrinsics)) {
-		BKE_report(op->reports, RPT_ERROR, "Invalid combination for intrinsic refinement");
-		return OPERATOR_CANCELLED;
-	}*/
 
 	/* could fail if footage uses images with different sizes */
 	BKE_movieclip_get_size(clip, NULL, &width, &height);

Modified: branches/soc-2011-tomato/source/blender/makesdna/DNA_tracking_types.h
===================================================================
--- branches/soc-2011-tomato/source/blender/makesdna/DNA_tracking_types.h	2011-11-10 10:34:26 UTC (rev 41724)
+++ branches/soc-2011-tomato/source/blender/makesdna/DNA_tracking_types.h	2011-11-10 11:16:33 UTC (rev 41725)
@@ -124,9 +124,10 @@
 	int keyframe1, keyframe2;	/* two keyframes for reconstrution initialization */
 
 	/* ** which camera intrinsics to refine. uses on the REFINE_* flags */
-	int refine_camera_intrinsics;
-	char pad2[4];
+	short refine_camera_intrinsics;
 
+	char pad2[6];
+
 	/* ** tool settings ** */
 
 	/* set scale */
@@ -186,12 +187,6 @@
 #define MARKER_TRACKED	(1<<1)
 #define MARKER_GRAPH_SEL (1<<2)
 
-/* MovieTrackingSettings->refine_camera_intrinsics */
-#define REFINE_FOCAL_LENGTH	(1<<0)
-#define REFINE_PRINCIPAL_POINT	(1<<1)

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list