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

Sergey Sharybin g.ulairi at gmail.com
Mon Sep 26 17:07:06 CEST 2011


Revision: 40573
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=40573
Author:   nazgul
Date:     2011-09-26 15:07:06 +0000 (Mon, 26 Sep 2011)
Log Message:
-----------
Camera tracking integration
===========================

- If render size is set to "Full Render" and undistorted render
  is enabled, do on-fly undistortion so distortion coefficients
  can be visually verifed before baking.
- Made slight change in libmv-side to survive with large distortion
  coefficients. Hope this change is fine.

Modified Paths:
--------------
    branches/soc-2011-tomato/extern/libmv/bundle.sh
    branches/soc-2011-tomato/extern/libmv/libmv/simple_pipeline/camera_intrinsics.cc
    branches/soc-2011-tomato/extern/libmv/patches/series
    branches/soc-2011-tomato/intern/guardedalloc/intern/mallocn.c
    branches/soc-2011-tomato/release/scripts/startup/bl_ui/space_clip.py
    branches/soc-2011-tomato/source/blender/blenkernel/intern/movieclip.c

Added Paths:
-----------
    branches/soc-2011-tomato/extern/libmv/patches/function_derivative.patch
    branches/soc-2011-tomato/extern/libmv/patches/high_distortion_crash_fix.patch
    branches/soc-2011-tomato/extern/libmv/patches/levenberg_marquardt.patch

Modified: branches/soc-2011-tomato/extern/libmv/bundle.sh
===================================================================
--- branches/soc-2011-tomato/extern/libmv/bundle.sh	2011-09-26 15:00:23 UTC (rev 40572)
+++ branches/soc-2011-tomato/extern/libmv/bundle.sh	2011-09-26 15:07:06 UTC (rev 40573)
@@ -176,8 +176,6 @@
 			string(REPLACE "${FLAG}" "Od" CMAKE_C_FLAGS_RELWITHDEBINFO "${CMAKE_C_FLAGS_RELWITHDEBINFO}")
 		endforeach()
 	ENDIF(MSVC)
-
-	add_definitions(-DEIGEN_DONT_ALIGN_STATICALLY)
 ELSE(WIN32)
 	list(APPEND SRC
 ${third_glog_sources}
@@ -234,8 +232,6 @@
             cflags_libmv = Split(env['REL_CFLAGS'])
             ccflags_libmv = Split(env['REL_CCFLAGS'])
             cxxflags_libmv = Split(env['REL_CXXFLAGS'])
-
-    defs.append('EIGEN_DONT_ALIGN_STATICALLY')
 else:
     src += env.Glob("third_party/glog/src/*.cc")
     incs += ' ./third_party/glog/src'

Modified: branches/soc-2011-tomato/extern/libmv/libmv/simple_pipeline/camera_intrinsics.cc
===================================================================
--- branches/soc-2011-tomato/extern/libmv/libmv/simple_pipeline/camera_intrinsics.cc	2011-09-26 15:00:23 UTC (rev 40572)
+++ branches/soc-2011-tomato/extern/libmv/libmv/simple_pipeline/camera_intrinsics.cc	2011-09-26 15:07:06 UTC (rev 40573)
@@ -160,9 +160,13 @@
       if( iy < 0 ) { iy = 0, fy = 0; }
       if( ix >= width-2 ) ix = width-2;
       if( iy >= height-2 ) iy = height-2;
-      //assert( ix-x > -128 && ix-x < 128 && iy-y > -128 && iy-y < 128 );
-      Offset offset = { ix-x, iy-y, fx, fy };
-      grid[y*width+x] = offset;
+      if ( ix-x > -128 && ix-x < 128 && iy-y > -128 && iy-y < 128 ) {
+        Offset offset = { ix-x, iy-y, fx, fy };
+        grid[y*width+x] = offset;
+      } else {
+        Offset offset = { 0, 0, 0, 0 };
+        grid[y*width+x] = offset;
+      }
     }
   }
 }

Added: branches/soc-2011-tomato/extern/libmv/patches/function_derivative.patch
===================================================================
--- branches/soc-2011-tomato/extern/libmv/patches/function_derivative.patch	                        (rev 0)
+++ branches/soc-2011-tomato/extern/libmv/patches/function_derivative.patch	2011-09-26 15:07:06 UTC (rev 40573)
@@ -0,0 +1,21 @@
+diff --git a/src/libmv/numeric/function_derivative.h b/src/libmv/numeric/function_derivative.h
+index 0075d23..d7bc437 100644
+--- a/src/libmv/numeric/function_derivative.h
++++ b/src/libmv/numeric/function_derivative.h
+@@ -24,6 +24,7 @@
+ #include <cmath>
+ 
+ #include "libmv/numeric/numeric.h"
++#include "libmv/logging/logging.h"
+ 
+ namespace libmv {
+ 
+@@ -97,7 +98,7 @@ bool CheckJacobian(const Function &f, const typename Function::XMatrixType &x) {
+ 
+   typename NumericJacobian<Function>::JMatrixType J_numeric = j_numeric(x);
+   typename NumericJacobian<Function>::JMatrixType J_analytic = j_analytic(x);
+-  //LG << J_numeric - J_analytic;
++  LG << J_numeric - J_analytic;
+   return true;
+ }
+ 

Added: branches/soc-2011-tomato/extern/libmv/patches/high_distortion_crash_fix.patch
===================================================================
--- branches/soc-2011-tomato/extern/libmv/patches/high_distortion_crash_fix.patch	                        (rev 0)
+++ branches/soc-2011-tomato/extern/libmv/patches/high_distortion_crash_fix.patch	2011-09-26 15:07:06 UTC (rev 40573)
@@ -0,0 +1,21 @@
+diff --git a/src/libmv/simple_pipeline/camera_intrinsics.cc b/src/libmv/simple_pipeline/camera_intrinsics.cc
+index 4e88e1f..f9888ff 100644
+--- a/src/libmv/simple_pipeline/camera_intrinsics.cc
++++ b/src/libmv/simple_pipeline/camera_intrinsics.cc
+@@ -160,9 +160,13 @@ void CameraIntrinsics::ComputeLookupGrid(Offset* grid, int width, int height) {
+       if( iy < 0 ) { iy = 0, fy = 0; }
+       if( ix >= width-2 ) ix = width-2;
+       if( iy >= height-2 ) iy = height-2;
+-      //assert( ix-x > -128 && ix-x < 128 && iy-y > -128 && iy-y < 128 );
+-      Offset offset = { ix-x, iy-y, fx, fy };
+-      grid[y*width+x] = offset;
++      if ( ix-x > -128 && ix-x < 128 && iy-y > -128 && iy-y < 128 ) {
++        Offset offset = { ix-x, iy-y, fx, fy };
++        grid[y*width+x] = offset;
++      } else {
++        Offset offset = { 0, 0, 0, 0 };
++        grid[y*width+x] = offset;
++      }
+     }
+   }
+ }

Added: branches/soc-2011-tomato/extern/libmv/patches/levenberg_marquardt.patch
===================================================================
--- branches/soc-2011-tomato/extern/libmv/patches/levenberg_marquardt.patch	                        (rev 0)
+++ branches/soc-2011-tomato/extern/libmv/patches/levenberg_marquardt.patch	2011-09-26 15:07:06 UTC (rev 40573)
@@ -0,0 +1,71 @@
+diff --git a/src/libmv/numeric/levenberg_marquardt.h b/src/libmv/numeric/levenberg_marquardt.h
+index 6a54f66..4473b72 100644
+--- a/src/libmv/numeric/levenberg_marquardt.h
++++ b/src/libmv/numeric/levenberg_marquardt.h
+@@ -33,6 +33,7 @@
+ 
+ #include "libmv/numeric/numeric.h"
+ #include "libmv/numeric/function_derivative.h"
++#include "libmv/logging/logging.h"
+ 
+ namespace libmv {
+ 
+@@ -123,26 +124,40 @@ class LevenbergMarquardt {
+     Parameters dx, x_new;
+     int i;
+     for (i = 0; results.status == RUNNING && i < params.max_iterations; ++i) {
+-      if (dx.norm() <= params.relative_step_threshold * x.norm()) {
++      VLOG(1) << "iteration: " << i;
++      VLOG(1) << "||f(x)||: " << f_(x).norm();
++      VLOG(1) << "max(g): " << g.array().abs().maxCoeff();
++      VLOG(1) << "u: " << u;
++      VLOG(1) << "v: " << v;
++
++      AMatrixType A_augmented = A + u*AMatrixType::Identity(J.cols(), J.cols());
++      Solver solver(A_augmented);
++      dx = solver.solve(g);
++      bool solved = (A_augmented * dx).isApprox(g);
++      if (!solved) {
++        LOG(ERROR) << "Failed to solve";
++      }
++      if (solved && dx.norm() <= params.relative_step_threshold * x.norm()) {
+         results.status = RELATIVE_STEP_SIZE_TOO_SMALL;
+         break;
+-      }
+-      x_new = x + dx;
+-      // Rho is the ratio of the actual reduction in error to the reduction
+-      // in error that would be obtained if the problem was linear.
+-      // See [1] for details.
+-      Scalar rho((error.squaredNorm() - f_(x_new).squaredNorm())
+-                 / dx.dot(u*dx + g));
+-      if (rho > 0) {
+-        // Accept the Gauss-Newton step because the linear model fits well.
+-        x = x_new;
+-        results.status = Update(x, params, &J, &A, &error, &g);
+-        Scalar tmp = Scalar(2*rho-1);
+-        u = u*std::max(1/3., 1 - (tmp*tmp*tmp));
+-        v = 2;
+-        continue;
+-      }
+-
++      } 
++      if (solved) {
++        x_new = x + dx;
++        // Rho is the ratio of the actual reduction in error to the reduction
++        // in error that would be obtained if the problem was linear.
++        // See [1] for details.
++        Scalar rho((error.squaredNorm() - f_(x_new).squaredNorm())
++                   / dx.dot(u*dx + g));
++        if (rho > 0) {
++          // Accept the Gauss-Newton step because the linear model fits well.
++          x = x_new;
++          results.status = Update(x, params, &J, &A, &error, &g);
++          Scalar tmp = Scalar(2*rho-1);
++          u = u*std::max(1/3., 1 - (tmp*tmp*tmp));
++          v = 2;
++          continue;
++        } 
++      } 
+       // Reject the update because either the normal equations failed to solve
+       // or the local linear model was not good (rho < 0). Instead, increase u
+       // to move closer to gradient descent.

Modified: branches/soc-2011-tomato/extern/libmv/patches/series
===================================================================
--- branches/soc-2011-tomato/extern/libmv/patches/series	2011-09-26 15:00:23 UTC (rev 40572)
+++ branches/soc-2011-tomato/extern/libmv/patches/series	2011-09-26 15:07:06 UTC (rev 40573)
@@ -3,3 +3,6 @@
 bundle_tweaks.patch
 fast.patch
 config_mac.patch
+levenberg_marquardt.patch
+function_derivative.patch
+high_distortion_crash_fix.patch

Modified: branches/soc-2011-tomato/intern/guardedalloc/intern/mallocn.c
===================================================================
--- branches/soc-2011-tomato/intern/guardedalloc/intern/mallocn.c	2011-09-26 15:00:23 UTC (rev 40572)
+++ branches/soc-2011-tomato/intern/guardedalloc/intern/mallocn.c	2011-09-26 15:07:06 UTC (rev 40573)
@@ -636,7 +636,7 @@
 	} else{
 		error = -1;
 		name = check_memlist(memh);
-		if (name == NULL)
+		if (name == NULL) 
 			MemorY_ErroR("free","pointer not in memlist");
 		else
 			MemorY_ErroR(name,"error in header");

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-09-26 15:00:23 UTC (rev 40572)
+++ branches/soc-2011-tomato/release/scripts/startup/bl_ui/space_clip.py	2011-09-26 15:07:06 UTC (rev 40573)
@@ -592,9 +592,7 @@
         col.label(text="Proxy render size:")
 
         col.prop(sc.clip_user, "proxy_render_size", text="")
-        row = col.row()
-        row.active = sc.clip_user.proxy_render_size != 'FULL'
-        row.prop(sc.clip_user, "use_render_undistorted")
+        col.prop(sc.clip_user, "use_render_undistorted")
 
 
 class CLIP_PT_footage(Panel):

Modified: branches/soc-2011-tomato/source/blender/blenkernel/intern/movieclip.c
===================================================================
--- branches/soc-2011-tomato/source/blender/blenkernel/intern/movieclip.c	2011-09-26 15:00:23 UTC (rev 40572)
+++ branches/soc-2011-tomato/source/blender/blenkernel/intern/movieclip.c	2011-09-26 15:07:06 UTC (rev 40573)
@@ -271,6 +271,12 @@
 	ImBuf *stableibuf;
 	int proxy;
 	short render_flag;
+
+	/* cache for undistorted shot */
+	int undist_framenr;
+	float principal[2];
+	float k1, k2, k3;
+	ImBuf *undistibuf;
 } MovieClipCache;
 
 typedef struct MovieClipImBufCacheKey {
@@ -477,18 +483,120 @@
 	}
 }
 
+static int need_undistorted_cache(MovieClipUser *user, int flag)
+{
+	if (!user)
+		return 0;
+
+	/* only full undistorted render can be used as on-fly undistorting image */
+	if(flag&MCLIP_USE_PROXY)
+		if(user->render_size != MCLIP_PROXY_RENDER_SIZE_FULL || (user->render_flag&MCLIP_PROXY_RENDER_UNDISTORT)==0)
+			return 0;
+
+	return 1;
+}
+
+static ImBuf *get_undistorted_cache(MovieClip *clip, MovieClipUser *user)
+{
+	MovieClipCache *cache= clip->cache;
+	MovieTrackingCamera *camera= &clip->tracking.camera;

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list