Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSergey Sharybin <sergey.vfx@gmail.com>2011-11-14 10:41:23 +0400
committerSergey Sharybin <sergey.vfx@gmail.com>2011-11-14 10:41:23 +0400
commit6fbc4186fd947d5dd408fccea1ba4990be738880 (patch)
tree4bec14f6df0110253ef796dc45f02ff92968cf53 /source/blender/blenkernel
parente058110b700d556710509d20deac778a6b4d566f (diff)
Assorted camera tracker improvements
- Add support for refining the camera's intrinsic parameters during a solve. Currently, refining supports only the following combinations of intrinsic parameters: f f, cx, cy f, cx, cy, k1, k2 f, k1 f, k1, k2 This is not the same as autocalibration, since the user must still make a reasonable initial guess about the focal length and other parameters, whereas true autocalibration would eliminate the need for the user specify intrinsic parameters at all. However, the solver works well with only rough guesses for the focal length, so perhaps full autocalibation is not that important. Adding support for the last two combinations, (f, k1) and (f, k1, k2) required changes to the library libmv depends on for bundle adjustment, SSBA. These changes should get ported upstream not just to libmv but to SSBA as well. - Improved the region of convergence for bundle adjustment by increasing the number of Levenberg-Marquardt iterations from 50 to 500. This way, the solver is able to crawl out of the bad local minima it gets stuck in when changing from, for example, bundling k1 and k2 to just k1 and resetting k2 to 0. - Add several new region tracker implementations. A region tracker is a libmv concept, which refers to tracking a template image pattern through frames. The impact to end users is that tracking should "just work better". I am reserving a more detailed writeup, and maybe a paper, for later. - Other libmv tweaks, such as detecting that a tracker is headed outside of the image bounds. This includes several changes made directly to the libmv extern code rather expecting to get those changes through normal libmv channels, because I, the libmv BDFL, decided it was faster to work on libmv directly in Blender, then later reverse-port the libmv changes from Blender back into libmv trunk. The interesting part is that I added a full Levenberg-Marquardt loop to the region tracking code, which should lead to a more stable solutions. I also added a hacky implementation of "Efficient Second-Order Minimization" for tracking, which works nicely. A more detailed quantitative evaluation will follow. Original patch by Keir, cleaned a bit by myself.
Diffstat (limited to 'source/blender/blenkernel')
-rw-r--r--source/blender/blenkernel/BKE_tracking.h2
-rw-r--r--source/blender/blenkernel/intern/tracking.c86
2 files changed, 87 insertions, 1 deletions
diff --git a/source/blender/blenkernel/BKE_tracking.h b/source/blender/blenkernel/BKE_tracking.h
index a8fb2c836de..af852d49d82 100644
--- a/source/blender/blenkernel/BKE_tracking.h
+++ b/source/blender/blenkernel/BKE_tracking.h
@@ -91,6 +91,8 @@ void BKE_tracking_sync_user(struct MovieClipUser *user, struct MovieTrackingCont
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);
diff --git a/source/blender/blenkernel/intern/tracking.c b/source/blender/blenkernel/intern/tracking.c
index d65840720cd..4989e8f1b55 100644
--- a/source/blender/blenkernel/intern/tracking.c
+++ b/source/blender/blenkernel/intern/tracking.c
@@ -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"
@@ -1260,7 +1261,28 @@ static struct libmv_Tracks *create_libmv_tracks(MovieTracking *tracking, int wid
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;
@@ -1373,7 +1395,68 @@ static int retrieve_libmv_reconstruct(MovieTracking *tracking, struct libmv_Reco
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)
{
@@ -1384,6 +1467,7 @@ float BKE_tracking_solve_reconstruction(MovieTracking *tracking, int width, int
struct libmv_Tracks *tracks= create_libmv_tracks(tracking, width, height*aspy);
struct libmv_Reconstruction *reconstruction = libmv_solveReconstruction(tracks,
tracking->settings.keyframe1, tracking->settings.keyframe2,
+ get_refine_intrinsics_flags(tracking),
camera->focal,
camera->principal[0], camera->principal[1]*aspy,
camera->k1, camera->k2, camera->k3);