Camera tracking integration
authorSergey Sharybin <sergey.vfx@gmail.com>
Sun, 9 Oct 2011 20:28:29 +0000 (20:28 +0000)
committerSergey Sharybin <sergey.vfx@gmail.com>
Sun, 9 Oct 2011 20:28:29 +0000 (20:28 +0000)
===========================

Support for (un)distortion of images with overscan. Needed for
easier keeping this up-to-date until proper overscan support is
implemented in renderer. Not exposed into UI yet at all.

extern/libmv/libmv-capi.cpp
extern/libmv/libmv-capi.h
extern/libmv/libmv/simple_pipeline/camera_intrinsics.cc
extern/libmv/libmv/simple_pipeline/camera_intrinsics.h
extern/libmv/patches/overscan.patch [new file with mode: 0644]
extern/libmv/patches/series
source/blender/blenkernel/BKE_tracking.h
source/blender/blenkernel/intern/movieclip.c
source/blender/blenkernel/intern/tracking.c
source/blender/nodes/composite/nodes/node_composite_moviedistortion.c

index c3d3c02b043e0c59b693e2fe287a768d88afe08a..8bf27ac065675506384442e06d49efebddee671e 100644 (file)
@@ -592,40 +592,40 @@ void libmv_CameraIntrinsicsUpdate(struct libmv_CameraIntrinsics *libmvIntrinsics
 }
 
 void libmv_CameraIntrinsicsUndistortByte(struct libmv_CameraIntrinsics *libmvIntrinsics,
-                       unsigned char *src, unsigned char *dst, int width, int height, int channels)
+                       unsigned char *src, unsigned char *dst, int width, int height, float overscan, int channels)
 {
        libmv::CameraIntrinsics *intrinsics = (libmv::CameraIntrinsics *) libmvIntrinsics;
 
-       intrinsics->Undistort(src, dst, width, height, channels);
+       intrinsics->Undistort(src, dst, width, height, overscan, channels);
 }
 
 void libmv_CameraIntrinsicsUndistortFloat(struct libmv_CameraIntrinsics *libmvIntrinsics,
-                       float *src, float *dst, int width, int height, int channels)
+                       float *src, float *dst, int width, int height, float overscan, int channels)
 {
        libmv::CameraIntrinsics *intrinsics = (libmv::CameraIntrinsics *) libmvIntrinsics;
 
-       intrinsics->Undistort(src, dst, width, height, channels);
+       intrinsics->Undistort(src, dst, width, height, overscan, channels);
 }
 
 void libmv_CameraIntrinsicsDistortByte(struct libmv_CameraIntrinsics *libmvIntrinsics,
-                       unsigned char *src, unsigned char *dst, int width, int height, int channels)
+                       unsigned char *src, unsigned char *dst, int width, int height, float overscan, int channels)
 {
        libmv::CameraIntrinsics *intrinsics = (libmv::CameraIntrinsics *) libmvIntrinsics;
-       intrinsics->Distort(src, dst, width, height, channels);
+       intrinsics->Distort(src, dst, width, height, overscan, channels);
 }
 
 void libmv_CameraIntrinsicsDistortFloat(struct libmv_CameraIntrinsics *libmvIntrinsics,
-                       float *src, float *dst, int width, int height, int channels)
+                       float *src, float *dst, int width, int height, float overscan, int channels)
 {
        libmv::CameraIntrinsics *intrinsics = (libmv::CameraIntrinsics *) libmvIntrinsics;
 
-       intrinsics->Distort(src, dst, width, height, channels);
+       intrinsics->Distort(src, dst, width, height, overscan, channels);
 }
 
 /* ************ distortion ************ */
 
 void libmv_undistortByte(double focal_length, double principal_x, double principal_y, double k1, double k2, double k3,
-                       unsigned char *src, unsigned char *dst, int width, int height, int channels)
+                       unsigned char *src, unsigned char *dst, int width, int height, float overscan, int channels)
 {
        libmv::CameraIntrinsics intrinsics;
 
@@ -633,11 +633,11 @@ void libmv_undistortByte(double focal_length, double principal_x, double princip
        intrinsics.SetPrincipalPoint(principal_x, principal_y);
        intrinsics.SetRadialDistortion(k1, k2, k3);
 
-       intrinsics.Undistort(src, dst, width, height, channels);
+       intrinsics.Undistort(src, dst, width, height, overscan, channels);
 }
 
 void libmv_undistortFloat(double focal_length, double principal_x, double principal_y, double k1, double k2, double k3,
-                       float *src, float *dst, int width, int height, int channels)
+                       float *src, float *dst, int width, int height, float overscan, int channels)
 {
        libmv::CameraIntrinsics intrinsics;
 
@@ -645,11 +645,11 @@ void libmv_undistortFloat(double focal_length, double principal_x, double princi
        intrinsics.SetPrincipalPoint(principal_x, principal_y);
        intrinsics.SetRadialDistortion(k1, k2, k3);
 
-       intrinsics.Undistort(src, dst, width, height, channels);
+       intrinsics.Undistort(src, dst, width, height, overscan, channels);
 }
 
 void libmv_distortByte(double focal_length, double principal_x, double principal_y, double k1, double k2, double k3,
-                       unsigned char *src, unsigned char *dst, int width, int height, int channels)
+                       unsigned char *src, unsigned char *dst, int width, int height, float overscan, int channels)
 {
        libmv::CameraIntrinsics intrinsics;
 
@@ -657,11 +657,11 @@ void libmv_distortByte(double focal_length, double principal_x, double principal
        intrinsics.SetPrincipalPoint(principal_x, principal_y);
        intrinsics.SetRadialDistortion(k1, k2, k3);
 
-       intrinsics.Distort(src, dst, width, height, channels);
+       intrinsics.Distort(src, dst, width, height, overscan, channels);
 }
 
 void libmv_distortFloat(double focal_length, double principal_x, double principal_y, double k1, double k2, double k3,
-                       float *src, float *dst, int width, int height, int channels)
+                       float *src, float *dst, int width, int height, float overscan, int channels)
 {
        libmv::CameraIntrinsics intrinsics;
 
@@ -669,7 +669,7 @@ void libmv_distortFloat(double focal_length, double principal_x, double principa
        intrinsics.SetPrincipalPoint(principal_x, principal_y);
        intrinsics.SetRadialDistortion(k1, k2, k3);
 
-       intrinsics.Distort(src, dst, width, height, channels);
+       intrinsics.Distort(src, dst, width, height, overscan, channels);
 }
 
 /* ************ utils ************ */
index e0a40a1ad862d7b634cb23112c3bdaf25839482e..8f2a57748b2e495c15fbe1ba3269a8ccb2a737e0 100644 (file)
@@ -84,22 +84,24 @@ struct libmv_CameraIntrinsics *libmv_CameraIntrinsicsNew(double focal_length, do
 
 struct libmv_CameraIntrinsics *libmv_CameraIntrinsicsCopy(struct libmv_CameraIntrinsics *libmvIntrinsics);
 
+struct libmv_CameraIntrinsics *libmv_CameraIntrinsicsCopy(struct libmv_CameraIntrinsics *libmvIntrinsics);
+
 void libmv_CameraIntrinsicsDestroy(struct libmv_CameraIntrinsics *libmvIntrinsics);
 
 void libmv_CameraIntrinsicsUpdate(struct libmv_CameraIntrinsics *libmvIntrinsics, double focal_length,
                        double principal_x, double principal_y, double k1, double k2, double k3, int width, int height);
 
 void libmv_CameraIntrinsicsUndistortByte(struct libmv_CameraIntrinsics *libmvIntrinsics,
-                       unsigned char *src, unsigned char *dst, int width, int height, int channels);
+                       unsigned char *src, unsigned char *dst, int width, int height, float overscan, int channels);
 
 void libmv_CameraIntrinsicsUndistortFloat(struct libmv_CameraIntrinsics *libmvIntrinsics,
-                       float *src, float *dst, int width, int height, int channels);
+                       float *src, float *dst, int width, int height, float overscan, int channels);
 
 void libmv_CameraIntrinsicsDistortByte(struct libmv_CameraIntrinsics *libmvIntrinsics,
-                       unsigned char *src, unsigned char *dst, int width, int height, int channels);
+                       unsigned char *src, unsigned char *dst, int width, int height, float overscan, int channels);
 
 void libmv_CameraIntrinsicsDistortFloat(struct libmv_CameraIntrinsics *libmvIntrinsics,
-                       float *src, float *dst, int width, int height, int channels);
+                       float *src, float *dst, int width, int height, float overscan, int channels);
 
 /* dsitortion */
 void libmv_undistortByte(double focal_length, double principal_x, double principal_y, double k1, double k2, double k3,
index 110a16d1812519f6b987d103f9281432f2246cec..366129dd3d225b6ec077415a27654a29fd554090 100644 (file)
@@ -31,6 +31,7 @@ struct Offset {
 struct Grid {
   struct Offset *offset;
   int width, height;
+  double overscan;
 };
 
 static struct Grid *copyGrid(struct Grid *from)
@@ -42,6 +43,7 @@ static struct Grid *copyGrid(struct Grid *from)
 
     to->width = from->width;
     to->height = from->height;
+    to->overscan = from->overscan;
 
     to->offset = new Offset[to->width*to->height];
     memcpy(to->offset, from->offset, sizeof(struct Offset)*to->width*to->height);
@@ -184,17 +186,19 @@ void CameraIntrinsics::InvertIntrinsics(double image_x,
 
 // TODO(MatthiasF): downsample lookup
 template<typename WarpFunction>
-void CameraIntrinsics::ComputeLookupGrid(Grid* grid, int width, int height) {
-  double aspx = (double)width / image_width_;
-  double aspy = (double)height / image_height_;
+void CameraIntrinsics::ComputeLookupGrid(Grid* grid, int width, int height, double overscan) {
+  double w = (double)width / (1 + overscan);
+  double h = (double)height / (1 + overscan);
+  double aspx = (double)w / image_width_;
+  double aspy = (double)h / image_height_;
 
   for (int y = 0; y < height; y++) {
     for (int x = 0; x < width; x++) {
-      double src_x = x / aspx, src_y = y / aspy;
+      double src_x = (x - 0.5 * overscan * w) / aspx, src_y = (y - 0.5 * overscan * h) / aspy;
       double warp_x, warp_y;
       WarpFunction(this,src_x,src_y,&warp_x,&warp_y);
-      warp_x = warp_x*aspx;
-      warp_y = warp_y*aspy;
+      warp_x = warp_x*aspx + 0.5 * overscan * w;
+      warp_y = warp_y*aspy + 0.5 * overscan * h;
       int ix = int(warp_x), iy = int(warp_y);
       int fx = round((warp_x-ix)*256), fy = round((warp_y-iy)*256);
       if(fx == 256) { fx=0; ix++; }
@@ -264,10 +268,10 @@ struct InvertIntrinsicsFunction {
   }
 };
 
-void CameraIntrinsics::CheckDistortLookupGrid(int width, int height)
+void CameraIntrinsics::CheckDistortLookupGrid(int width, int height, double overscan)
 {
   if(distort_) {
-    if(distort_->width != width || distort_->height != height) {
+    if(distort_->width != width || distort_->height != height || distort_->overscan != overscan) {
       delete [] distort_->offset;
       distort_->offset = NULL;
     }
@@ -278,17 +282,18 @@ void CameraIntrinsics::CheckDistortLookupGrid(int width, int height)
 
   if(!distort_->offset) {
       distort_->offset = new Offset[width*height];
-      ComputeLookupGrid<InvertIntrinsicsFunction>(distort_,width,height);
+      ComputeLookupGrid<InvertIntrinsicsFunction>(distort_,width,height,overscan);
   }
 
   distort_->width = width;
   distort_->height = height;
+  distort_->overscan = overscan;
 }
 
-void CameraIntrinsics::CheckUndistortLookupGrid(int width, int height)
+void CameraIntrinsics::CheckUndistortLookupGrid(int width, int height, double overscan)
 {
   if(undistort_) {
-    if(undistort_->width != width || undistort_->height != height) {
+    if(undistort_->width != width || undistort_->height != height || undistort_->overscan != overscan) {
       delete [] undistort_->offset;
       undistort_->offset = NULL;
     }
@@ -299,15 +304,16 @@ void CameraIntrinsics::CheckUndistortLookupGrid(int width, int height)
 
   if(!undistort_->offset) {
       undistort_->offset = new Offset[width*height];
-      ComputeLookupGrid<ApplyIntrinsicsFunction>(undistort_,width,height);
+      ComputeLookupGrid<ApplyIntrinsicsFunction>(undistort_,width,height,overscan);
   }
 
   undistort_->width = width;
   undistort_->height = height;
+  undistort_->overscan = overscan;
 }
 
-void CameraIntrinsics::Distort(const float* src, float* dst, int width, int height, int channels) {
-  CheckDistortLookupGrid(width, height);
+void CameraIntrinsics::Distort(const float* src, float* dst, int width, int height, double overscan, int channels) {
+  CheckDistortLookupGrid(width, height, overscan);
        if(channels==1) Warp<float,1>(distort_,src,dst,width,height);
   else if(channels==2) Warp<float,2>(distort_,src,dst,width,height);
   else if(channels==3) Warp<float,3>(distort_,src,dst,width,height);
@@ -315,8 +321,8 @@ void CameraIntrinsics::Distort(const float* src, float* dst, int width, int heig
   //else assert("channels must be between 1 and 4");
 }
 
-void CameraIntrinsics::Distort(const unsigned char* src, unsigned char* dst, int width, int height, int channels) {
-  CheckDistortLookupGrid(width, height);
+void CameraIntrinsics::Distort(const unsigned char* src, unsigned char* dst, int width, int height, double overscan, int channels) {
+  CheckDistortLookupGrid(width, height, overscan);
        if(channels==1) Warp<unsigned char,1>(distort_,src,dst,width,height);
   else if(channels==2) Warp<unsigned char,2>(distort_,src,dst,width,height);
   else if(channels==3) Warp<unsigned char,3>(distort_,src,dst,width,height);
@@ -324,8 +330,8 @@ void CameraIntrinsics::Distort(const unsigned char* src, unsigned char* dst, int
   //else assert("channels must be between 1 and 4");
 }
 
-void CameraIntrinsics::Undistort(const float* src, float* dst, int width, int height, int channels) {
-  CheckUndistortLookupGrid(width, height);
+void CameraIntrinsics::Undistort(const float* src, float* dst, int width, int height, double overscan, int channels) {
+  CheckUndistortLookupGrid(width, height, overscan);
        if(channels==1) Warp<float,1>(undistort_,src,dst,width,height);
   else if(channels==2) Warp<float,2>(undistort_,src,dst,width,height);
   else if(channels==3) Warp<float,3>(undistort_,src,dst,width,height);
@@ -333,8 +339,8 @@ void CameraIntrinsics::Undistort(const float* src, float* dst, int width, int he
   //else assert("channels must be between 1 and 4");
 }
 
-void CameraIntrinsics::Undistort(const unsigned char* src, unsigned char* dst, int width, int height, int channels) {
-  CheckUndistortLookupGrid(width, height);
+void CameraIntrinsics::Undistort(const unsigned char* src, unsigned char* dst, int width, int height, double overscan, int channels) {
+  CheckUndistortLookupGrid(width, height, overscan);
        if(channels==1) Warp<unsigned char,1>(undistort_,src,dst,width,height);
   else if(channels==2) Warp<unsigned char,2>(undistort_,src,dst,width,height);
   else if(channels==3) Warp<unsigned char,3>(undistort_,src,dst,width,height);
index f5255713e8956a1d167ae2956565e11a8410a474..f4bf903c36cea8def03213e608350d56eb3d41d8 100644 (file)
@@ -91,7 +91,7 @@ class CameraIntrinsics {
       \note This is the reference implementation using floating point images.
   */
   void Distort(const float* src, float* dst,
-               int width, int height, int channels);
+               int width, int height, double overscan, int channels);
   /*!
       Distort an image using the current camera instrinsics
 
@@ -101,7 +101,7 @@ class CameraIntrinsics {
       \note This version is much faster.
   */
   void Distort(const unsigned char* src, unsigned char* dst,
-               int width, int height, int channels);
+               int width, int height, double overscan, int channels);
   /*!
       Undistort an image using the current camera instrinsics
 
@@ -111,7 +111,7 @@ class CameraIntrinsics {
       \note This is the reference implementation using floating point images.
   */
   void Undistort(const float* src, float* dst,
-                 int width, int height, int channels);
+                 int width, int height, double overscan, int channels);
   /*!
       Undistort an image using the current camera instrinsics
 
@@ -121,12 +121,12 @@ class CameraIntrinsics {
       \note This version is much faster.
   */
   void Undistort(const unsigned char* src, unsigned char* dst,
-                 int width, int height, int channels);
+                 int width, int height, double overscan, int channels);
 
  private:
-  template<typename WarpFunction> void ComputeLookupGrid(struct Grid* grid, int width, int height);
-  void CheckUndistortLookupGrid(int width, int height);
-  void CheckDistortLookupGrid(int width, int height);
+  template<typename WarpFunction> void ComputeLookupGrid(struct Grid* grid, int width, int height, double overscan);
+  void CheckUndistortLookupGrid(int width, int height, double overscan);
+  void CheckDistortLookupGrid(int width, int height, double overscan);
   void FreeLookupGrid();
 
   // The traditional intrinsics matrix from x = K[R|t]X.
diff --git a/extern/libmv/patches/overscan.patch b/extern/libmv/patches/overscan.patch
new file mode 100644 (file)
index 0000000..c68f368
--- /dev/null
@@ -0,0 +1,182 @@
+diff --git a/src/libmv/simple_pipeline/camera_intrinsics.cc b/src/libmv/simple_pipeline/camera_intrinsics.cc
+index 110a16d..366129d 100644
+--- a/src/libmv/simple_pipeline/camera_intrinsics.cc
++++ b/src/libmv/simple_pipeline/camera_intrinsics.cc
+@@ -31,6 +31,7 @@ struct Offset {
+ struct Grid {
+   struct Offset *offset;
+   int width, height;
++  double overscan;
+ };
+ static struct Grid *copyGrid(struct Grid *from)
+@@ -42,6 +43,7 @@ static struct Grid *copyGrid(struct Grid *from)
+     to->width = from->width;
+     to->height = from->height;
++    to->overscan = from->overscan;
+     to->offset = new Offset[to->width*to->height];
+     memcpy(to->offset, from->offset, sizeof(struct Offset)*to->width*to->height);
+@@ -184,17 +186,19 @@ void CameraIntrinsics::InvertIntrinsics(double image_x,
+ // TODO(MatthiasF): downsample lookup
+ template<typename WarpFunction>
+-void CameraIntrinsics::ComputeLookupGrid(Grid* grid, int width, int height) {
+-  double aspx = (double)width / image_width_;
+-  double aspy = (double)height / image_height_;
++void CameraIntrinsics::ComputeLookupGrid(Grid* grid, int width, int height, double overscan) {
++  double w = (double)width / (1 + overscan);
++  double h = (double)height / (1 + overscan);
++  double aspx = (double)w / image_width_;
++  double aspy = (double)h / image_height_;
+   for (int y = 0; y < height; y++) {
+     for (int x = 0; x < width; x++) {
+-      double src_x = x / aspx, src_y = y / aspy;
++      double src_x = (x - 0.5 * overscan * w) / aspx, src_y = (y - 0.5 * overscan * h) / aspy;
+       double warp_x, warp_y;
+       WarpFunction(this,src_x,src_y,&warp_x,&warp_y);
+-      warp_x = warp_x*aspx;
+-      warp_y = warp_y*aspy;
++      warp_x = warp_x*aspx + 0.5 * overscan * w;
++      warp_y = warp_y*aspy + 0.5 * overscan * h;
+       int ix = int(warp_x), iy = int(warp_y);
+       int fx = round((warp_x-ix)*256), fy = round((warp_y-iy)*256);
+       if(fx == 256) { fx=0; ix++; }
+@@ -264,10 +268,10 @@ struct InvertIntrinsicsFunction {
+   }
+ };
+-void CameraIntrinsics::CheckDistortLookupGrid(int width, int height)
++void CameraIntrinsics::CheckDistortLookupGrid(int width, int height, double overscan)
+ {
+   if(distort_) {
+-    if(distort_->width != width || distort_->height != height) {
++    if(distort_->width != width || distort_->height != height || distort_->overscan != overscan) {
+       delete [] distort_->offset;
+       distort_->offset = NULL;
+     }
+@@ -278,17 +282,18 @@ void CameraIntrinsics::CheckDistortLookupGrid(int width, int height)
+   if(!distort_->offset) {
+       distort_->offset = new Offset[width*height];
+-      ComputeLookupGrid<InvertIntrinsicsFunction>(distort_,width,height);
++      ComputeLookupGrid<InvertIntrinsicsFunction>(distort_,width,height,overscan);
+   }
+   distort_->width = width;
+   distort_->height = height;
++  distort_->overscan = overscan;
+ }
+-void CameraIntrinsics::CheckUndistortLookupGrid(int width, int height)
++void CameraIntrinsics::CheckUndistortLookupGrid(int width, int height, double overscan)
+ {
+   if(undistort_) {
+-    if(undistort_->width != width || undistort_->height != height) {
++    if(undistort_->width != width || undistort_->height != height || undistort_->overscan != overscan) {
+       delete [] undistort_->offset;
+       undistort_->offset = NULL;
+     }
+@@ -299,15 +304,16 @@ void CameraIntrinsics::CheckUndistortLookupGrid(int width, int height)
+   if(!undistort_->offset) {
+       undistort_->offset = new Offset[width*height];
+-      ComputeLookupGrid<ApplyIntrinsicsFunction>(undistort_,width,height);
++      ComputeLookupGrid<ApplyIntrinsicsFunction>(undistort_,width,height,overscan);
+   }
+   undistort_->width = width;
+   undistort_->height = height;
++  undistort_->overscan = overscan;
+ }
+-void CameraIntrinsics::Distort(const float* src, float* dst, int width, int height, int channels) {
+-  CheckDistortLookupGrid(width, height);
++void CameraIntrinsics::Distort(const float* src, float* dst, int width, int height, double overscan, int channels) {
++  CheckDistortLookupGrid(width, height, overscan);
+        if(channels==1) Warp<float,1>(distort_,src,dst,width,height);
+   else if(channels==2) Warp<float,2>(distort_,src,dst,width,height);
+   else if(channels==3) Warp<float,3>(distort_,src,dst,width,height);
+@@ -315,8 +321,8 @@ void CameraIntrinsics::Distort(const float* src, float* dst, int width, int heig
+   //else assert("channels must be between 1 and 4");
+ }
+-void CameraIntrinsics::Distort(const unsigned char* src, unsigned char* dst, int width, int height, int channels) {
+-  CheckDistortLookupGrid(width, height);
++void CameraIntrinsics::Distort(const unsigned char* src, unsigned char* dst, int width, int height, double overscan, int channels) {
++  CheckDistortLookupGrid(width, height, overscan);
+        if(channels==1) Warp<unsigned char,1>(distort_,src,dst,width,height);
+   else if(channels==2) Warp<unsigned char,2>(distort_,src,dst,width,height);
+   else if(channels==3) Warp<unsigned char,3>(distort_,src,dst,width,height);
+@@ -324,8 +330,8 @@ void CameraIntrinsics::Distort(const unsigned char* src, unsigned char* dst, int
+   //else assert("channels must be between 1 and 4");
+ }
+-void CameraIntrinsics::Undistort(const float* src, float* dst, int width, int height, int channels) {
+-  CheckUndistortLookupGrid(width, height);
++void CameraIntrinsics::Undistort(const float* src, float* dst, int width, int height, double overscan, int channels) {
++  CheckUndistortLookupGrid(width, height, overscan);
+        if(channels==1) Warp<float,1>(undistort_,src,dst,width,height);
+   else if(channels==2) Warp<float,2>(undistort_,src,dst,width,height);
+   else if(channels==3) Warp<float,3>(undistort_,src,dst,width,height);
+@@ -333,8 +339,8 @@ void CameraIntrinsics::Undistort(const float* src, float* dst, int width, int he
+   //else assert("channels must be between 1 and 4");
+ }
+-void CameraIntrinsics::Undistort(const unsigned char* src, unsigned char* dst, int width, int height, int channels) {
+-  CheckUndistortLookupGrid(width, height);
++void CameraIntrinsics::Undistort(const unsigned char* src, unsigned char* dst, int width, int height, double overscan, int channels) {
++  CheckUndistortLookupGrid(width, height, overscan);
+        if(channels==1) Warp<unsigned char,1>(undistort_,src,dst,width,height);
+   else if(channels==2) Warp<unsigned char,2>(undistort_,src,dst,width,height);
+   else if(channels==3) Warp<unsigned char,3>(undistort_,src,dst,width,height);
+diff --git a/src/libmv/simple_pipeline/camera_intrinsics.h b/src/libmv/simple_pipeline/camera_intrinsics.h
+index f525571..f4bf903 100644
+--- a/src/libmv/simple_pipeline/camera_intrinsics.h
++++ b/src/libmv/simple_pipeline/camera_intrinsics.h
+@@ -91,7 +91,7 @@ class CameraIntrinsics {
+       \note This is the reference implementation using floating point images.
+   */
+   void Distort(const float* src, float* dst,
+-               int width, int height, int channels);
++               int width, int height, double overscan, int channels);
+   /*!
+       Distort an image using the current camera instrinsics
+@@ -101,7 +101,7 @@ class CameraIntrinsics {
+       \note This version is much faster.
+   */
+   void Distort(const unsigned char* src, unsigned char* dst,
+-               int width, int height, int channels);
++               int width, int height, double overscan, int channels);
+   /*!
+       Undistort an image using the current camera instrinsics
+@@ -111,7 +111,7 @@ class CameraIntrinsics {
+       \note This is the reference implementation using floating point images.
+   */
+   void Undistort(const float* src, float* dst,
+-                 int width, int height, int channels);
++                 int width, int height, double overscan, int channels);
+   /*!
+       Undistort an image using the current camera instrinsics
+@@ -121,12 +121,12 @@ class CameraIntrinsics {
+       \note This version is much faster.
+   */
+   void Undistort(const unsigned char* src, unsigned char* dst,
+-                 int width, int height, int channels);
++                 int width, int height, double overscan, int channels);
+  private:
+-  template<typename WarpFunction> void ComputeLookupGrid(struct Grid* grid, int width, int height);
+-  void CheckUndistortLookupGrid(int width, int height);
+-  void CheckDistortLookupGrid(int width, int height);
++  template<typename WarpFunction> void ComputeLookupGrid(struct Grid* grid, int width, int height, double overscan);
++  void CheckUndistortLookupGrid(int width, int height, double overscan);
++  void CheckDistortLookupGrid(int width, int height, double overscan);
+   void FreeLookupGrid();
+   // The traditional intrinsics matrix from x = K[R|t]X.
index 8f785a659cffc97569354df70f9192423d66f505..410a14ca1351bda47b39cc710574bd0dc5061662 100644 (file)
@@ -9,3 +9,4 @@ high_distortion_crash_fix.patch
 mingw.patch
 msvc2010.patch
 scaled_distortion.patch
+overscan.patch
index 23c72855c8a7a68e3ad1dac8dd31d76c28178c37..84e2acfb147cac29d789198aafc4dca92603036a 100644 (file)
@@ -99,11 +99,11 @@ void BKE_tracking_stabdata_to_mat4(int width, int height, float loc[2], float sc
 struct MovieDistortion *BKE_tracking_distortion_create(void);
 struct MovieDistortion *BKE_tracking_distortion_copy(struct MovieDistortion *distortion);
 struct ImBuf *BKE_tracking_distortion_exec(struct MovieDistortion *distortion, struct MovieTracking *tracking,
-                       struct ImBuf *ibuf, int width, int height, int undistort);
+                       struct ImBuf *ibuf, int width, int height, float overscan, int undistort);
 void BKE_tracking_distortion_destroy(struct MovieDistortion *distortion);
 
-struct ImBuf *BKE_tracking_undistort(struct MovieTracking *tracking, struct ImBuf *ibuf, int width, int height);
-struct ImBuf *BKE_tracking_distort(struct MovieTracking *tracking, struct ImBuf *ibuf, int width, int height);
+struct ImBuf *BKE_tracking_undistort(struct MovieTracking *tracking, struct ImBuf *ibuf, int width, int height, float overscan);
+struct ImBuf *BKE_tracking_distort(struct MovieTracking *tracking, struct ImBuf *ibuf, int width, int height, float overscan);
 
 #define TRACK_SELECTED(track)                          ((((track)->flag&TRACK_HIDDEN)==0) && ((track)->flag&SELECT || (track)->pat_flag&SELECT || (track)->search_flag&SELECT))
 #define TRACK_AREA_SELECTED(track, area)       ((((track)->flag&TRACK_HIDDEN)==0) && ((area)==TRACK_AREA_POINT?(track)->flag&SELECT : ((area)==TRACK_AREA_PAT?(track)->pat_flag&SELECT:(track)->search_flag&SELECT)))
index 2b83a1c0b6491f7744489661dffeb326748b6537..86c2ea89744669f663f0ac46d8e472ecd15955e4 100644 (file)
@@ -532,9 +532,9 @@ static ImBuf *get_undistorted_ibuf(MovieClip *clip, struct MovieDistortion *dist
        imb_freerectfloatImBuf(ibuf);
 
        if(distoriton)
-               undistibuf= BKE_tracking_distortion_exec(distoriton, &clip->tracking, ibuf, ibuf->x, ibuf->y, 1);
+               undistibuf= BKE_tracking_distortion_exec(distoriton, &clip->tracking, ibuf, ibuf->x, ibuf->y, 0.f, 1);
        else
-               undistibuf= BKE_tracking_undistort(&clip->tracking, ibuf, ibuf->x, ibuf->y);
+               undistibuf= BKE_tracking_undistort(&clip->tracking, ibuf, ibuf->x, ibuf->y, 0.f);
 
        if(undistibuf->userflags|= IB_RECT_INVALID) {
                ibuf->userflags&= ~IB_RECT_INVALID;
index 7b69a16dc8aeed1b1ff08c2d112ec440aaa43338..36f3f51a03babc5590506a294c21c9d876538257 100644 (file)
@@ -1940,7 +1940,7 @@ void BKE_tracking_distortion_update(MovieDistortion *distortion, MovieTracking *
 }
 
 ImBuf *BKE_tracking_distortion_exec(MovieDistortion *distortion, MovieTracking *tracking,
-                       ImBuf *ibuf, int width, int height, int undistort)
+                       ImBuf *ibuf, int width, int height, float overscan, int undistort)
 {
        ImBuf *resibuf;
 
@@ -1953,11 +1953,11 @@ ImBuf *BKE_tracking_distortion_exec(MovieDistortion *distortion, MovieTracking *
                if(undistort) {
                        libmv_CameraIntrinsicsUndistortFloat(distortion->intrinsics,
                                                ibuf->rect_float, resibuf->rect_float,
-                                               ibuf->x, ibuf->y, ibuf->channels);
+                                               ibuf->x, ibuf->y, overscan, ibuf->channels);
                } else {
                        libmv_CameraIntrinsicsDistortFloat(distortion->intrinsics,
                                                ibuf->rect_float, resibuf->rect_float,
-                                               ibuf->x, ibuf->y, ibuf->channels);
+                                               ibuf->x, ibuf->y, overscan, ibuf->channels);
                }
 #endif
 
@@ -1967,11 +1967,11 @@ ImBuf *BKE_tracking_distortion_exec(MovieDistortion *distortion, MovieTracking *
                if(undistort) {
                                libmv_CameraIntrinsicsUndistortByte(distortion->intrinsics,
                                                        (unsigned char*)ibuf->rect, (unsigned char*)resibuf->rect,
-                                                       ibuf->x, ibuf->y, ibuf->channels);
+                                                       ibuf->x, ibuf->y, overscan, ibuf->channels);
                } else {
                        libmv_CameraIntrinsicsDistortByte(distortion->intrinsics,
                                                (unsigned char*)ibuf->rect, (unsigned char*)resibuf->rect,
-                                               ibuf->x, ibuf->y, ibuf->channels);
+                                               ibuf->x, ibuf->y, overscan, ibuf->channels);
                }
 #endif
        }
@@ -1988,22 +1988,22 @@ void BKE_tracking_distortion_destroy(MovieDistortion *distortion)
        MEM_freeN(distortion);
 }
 
-ImBuf *BKE_tracking_undistort(MovieTracking *tracking, ImBuf *ibuf, int width, int height)
+ImBuf *BKE_tracking_undistort(MovieTracking *tracking, ImBuf *ibuf, int width, int height, float overscan)
 {
        MovieTrackingCamera *camera= &tracking->camera;
 
        if(camera->intrinsics == NULL)
                camera->intrinsics= BKE_tracking_distortion_create();
 
-       return BKE_tracking_distortion_exec(camera->intrinsics, tracking, ibuf, width, height, 1);
+       return BKE_tracking_distortion_exec(camera->intrinsics, tracking, ibuf, width, height, overscan, 1);
 }
 
-ImBuf *BKE_tracking_distort(MovieTracking *tracking, ImBuf *ibuf, int width, int height)
+ImBuf *BKE_tracking_distort(MovieTracking *tracking, ImBuf *ibuf, int width, int height, float overscan)
 {
        MovieTrackingCamera *camera= &tracking->camera;
 
        if(camera->intrinsics == NULL)
                camera->intrinsics= BKE_tracking_distortion_create();
 
-       return BKE_tracking_distortion_exec(camera->intrinsics, tracking, ibuf, width, height, 0);
+       return BKE_tracking_distortion_exec(camera->intrinsics, tracking, ibuf, width, height, overscan, 0);
 }
index 265a986fe08c9fbafb743fa8f88dfb7d3c4e4081..d1e6d0f0b998a2d1b03cc3b4b7a60761a71e5d02 100644 (file)
@@ -62,6 +62,7 @@ static void exec(void *UNUSED(data), bNode *node, bNodeStack **in, bNodeStack **
                                ImBuf *obuf;
                                MovieTracking *tracking= &clip->tracking;
                                int width, height;
+                               float overscan= 0.f;
 
                                ibuf->rect_float= cbuf->rect;
 
@@ -71,9 +72,9 @@ static void exec(void *UNUSED(data), bNode *node, bNodeStack **in, bNodeStack **
                                        node->storage= BKE_tracking_distortion_create();
 
                                if(node->custom1==0)
-                                       obuf= BKE_tracking_distortion_exec(node->storage, tracking, ibuf, width, height, 1);
+                                       obuf= BKE_tracking_distortion_exec(node->storage, tracking, ibuf, width, height, overscan, 1);
                                else
-                                       obuf= BKE_tracking_distortion_exec(node->storage, tracking, ibuf, width, height, 0);
+                                       obuf= BKE_tracking_distortion_exec(node->storage, tracking, ibuf, width, height, overscan, 0);
 
                                stackbuf->rect= obuf->rect_float;
                                stackbuf->malloc= 1;