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

Sergey Sharybin g.ulairi at gmail.com
Wed Aug 17 09:16:12 CEST 2011


Revision: 39479
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=39479
Author:   nazgul
Date:     2011-08-17 07:16:11 +0000 (Wed, 17 Aug 2011)
Log Message:
-----------
Camera tracking integration
===========================

- Bundle new version of libmv.
- Use image from nearest track's keyframe as reference for tracking.
  This should reduce drifting.
- Added option to switch to new SAD tracker.
  This tracker doesn't support pattern with variable size (yet?)
  and always uses pattern 16x16px.
  Tracker could be choosed in Tracking Settings panel.

Modified Paths:
--------------
    branches/soc-2011-tomato/extern/libmv/CMakeLists.txt
    branches/soc-2011-tomato/extern/libmv/ChangeLog
    branches/soc-2011-tomato/extern/libmv/files.txt
    branches/soc-2011-tomato/extern/libmv/libmv/simple_pipeline/camera_intrinsics.h
    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

Added Paths:
-----------
    branches/soc-2011-tomato/extern/libmv/libmv/tracking/sad.cc
    branches/soc-2011-tomato/extern/libmv/libmv/tracking/sad.h

Modified: branches/soc-2011-tomato/extern/libmv/CMakeLists.txt
===================================================================
--- branches/soc-2011-tomato/extern/libmv/CMakeLists.txt	2011-08-17 07:03:54 UTC (rev 39478)
+++ branches/soc-2011-tomato/extern/libmv/CMakeLists.txt	2011-08-17 07:16:11 UTC (rev 39479)
@@ -52,6 +52,7 @@
 	libmv/image/convolve.cc
 	libmv/image/array_nd.cc
 	libmv/tracking/pyramid_region_tracker.cc
+	libmv/tracking/sad.cc
 	libmv/tracking/trklt_region_tracker.cc
 	libmv/tracking/klt_region_tracker.cc
 	libmv/tracking/retrack_region_tracker.cc
@@ -97,6 +98,7 @@
 	libmv/image/image.h
 	libmv/tracking/region_tracker.h
 	libmv/tracking/retrack_region_tracker.h
+	libmv/tracking/sad.h
 	libmv/tracking/pyramid_region_tracker.h
 	libmv/tracking/trklt_region_tracker.h
 	libmv/tracking/klt_region_tracker.h

Modified: branches/soc-2011-tomato/extern/libmv/ChangeLog
===================================================================
--- branches/soc-2011-tomato/extern/libmv/ChangeLog	2011-08-17 07:03:54 UTC (rev 39478)
+++ branches/soc-2011-tomato/extern/libmv/ChangeLog	2011-08-17 07:16:11 UTC (rev 39479)
@@ -1,3 +1,22 @@
+commit a1d9a8fa8b01ef7cf2a79b3b891633fc333fc9cf
+Author: Matthias Fauconneau <matthias.fauconneau at gmail.com>
+Date:   Tue Aug 16 21:24:51 2011 +0200
+
+    Fix SAD tracker. Pattern was transposed by affine pattern sampler.
+
+commit c3b794da2e7fd23f2fbdf90dbd71de0e6b3bc811
+Author: Matthias Fauconneau <matthias.fauconneau at gmail.com>
+Date:   Tue Aug 16 21:19:02 2011 +0200
+
+    Fix SAD tracker. Pattern was transposed by affine pattern sampler.
+
+commit a9b61bf3356f27174cdd983f562f99c3a6a2cc35
+Author: Matthias Fauconneau <matthias.fauconneau at gmail.com>
+Date:   Sun Aug 14 09:56:51 2011 +0200
+
+    Clarify CameraIntrinsics documentation.
+    Edit CameraInstrinsics test to fail.
+
 commit 10bdad9ad2cea2603896263cde5a5339169a9af0
 Author: Matthias Fauconneau <matthias.fauconneau at gmail.com>
 Date:   Fri Aug 12 21:05:32 2011 +0200
@@ -342,79 +361,3 @@
 Date:   Sun Jul 17 16:35:48 2011 +0200
 
     Use deprecated FFmpeg API.
-
-commit 09b090a20134a8ccef273d802752bbf475ff5280
-Author: Matthias Fauconneau <matthias.fauconneau at gmail.com>
-Date:   Sat Jul 16 21:19:14 2011 +0200
-
-    Fix loading cache directly after creation.
-
-commit 1190584f6ca60fb74188cac36c61333951244026
-Author: Matthias Fauconneau <matthias.fauconneau at gmail.com>
-Date:   Sat Jul 16 20:02:36 2011 +0200
-
-    Add custom FileDialog to handle multiple files and folders selection in the same dialog
-
-commit 50504af3d0fc11665483aed524d52d076f38ffa8
-Author: Matthias Fauconneau <matthias.fauconneau at gmail.com>
-Date:   Fri Jul 15 23:34:41 2011 +0200
-
-    Fix mistake.
-
-commit a8e322a2c37cc87acd864d94a354334d611b9750
-Author: Matthias Fauconneau <matthias.fauconneau at gmail.com>
-Date:   Fri Jul 15 22:25:51 2011 +0200
-
-    Use cache even on first run (i.e don't load all images on the heap).
-
-commit 66ac3b5833a1fd4fbd97b082db6ddf859b33811c
-Author: Matthias Fauconneau <matthias.fauconneau at gmail.com>
-Date:   Fri Jul 15 21:15:45 2011 +0200
-
-    Improve Zoom View.
-
-commit dec996966d5466717a813da2d8b9962115dfc8ac
-Author: Matthias Fauconneau <matthias.fauconneau at gmail.com>
-Date:   Fri Jul 15 20:04:06 2011 +0200
-
-    Detect API documentation.
-
-commit bfc07bd0940bba0d5439ccd0297368607db514be
-Author: Matthias Fauconneau <matthias.fauconneau at gmail.com>
-Date:   Fri Jul 15 16:22:52 2011 +0200
-
-    Refactor Qt Tracker.
-    Create Detect API.
-    Improve CameraIntrinsics API.
-    Put Calibration settings UI in a QDockWidget.
-    Support anamorphic.
-    
-    TODO: Finish new Zoom widget.
-
-commit e59595806c045916ab4ef15ef7047c1a728b2da9
-Author: Matthias Fauconneau <matthias.fauconneau at gmail.com>
-Date:   Thu Jul 14 22:29:06 2011 +0200
-
-    Use FAST detector.
-    
-    FAST is much faster and works much better than the "Good Features to Track algorithm".
-
-commit 17c036e9f8c6529c2f771fdd9dc73f3022e36c77
-Author: Matthias Fauconneau <matthias.fauconneau at gmail.com>
-Date:   Wed Jul 13 22:23:40 2011 +0200
-
-    Add visualization of image filtering operations.
-
-commit c4f71e17b6b72acc0f863906c01c87d53e8bbb2c
-Author: Matthias Fauconneau <matthias.fauconneau at gmail.com>
-Date:   Wed Jul 13 10:37:26 2011 +0200
-
-    Simplify feature detection.
-
-commit d8109b7a4fede1660e0dbd73735f1a9e3fd79eec
-Author: Matthias Fauconneau <matthias.fauconneau at gmail.com>
-Date:   Wed Jul 13 10:21:52 2011 +0200
-
-    Add feature detection.
-    
-    Remove unused keyframe selection code.

Modified: branches/soc-2011-tomato/extern/libmv/files.txt
===================================================================
--- branches/soc-2011-tomato/extern/libmv/files.txt	2011-08-17 07:03:54 UTC (rev 39478)
+++ branches/soc-2011-tomato/extern/libmv/files.txt	2011-08-17 07:16:11 UTC (rev 39479)
@@ -34,9 +34,11 @@
 libmv/image/image.h
 libmv/tracking/pyramid_region_tracker.cc
 libmv/tracking/region_tracker.h
+libmv/tracking/sad.cc
 libmv/tracking/trklt_region_tracker.cc
 libmv/tracking/klt_region_tracker.cc
 libmv/tracking/retrack_region_tracker.h
+libmv/tracking/sad.h
 libmv/tracking/pyramid_region_tracker.h
 libmv/tracking/trklt_region_tracker.h
 libmv/tracking/retrack_region_tracker.cc

Modified: branches/soc-2011-tomato/extern/libmv/libmv/simple_pipeline/camera_intrinsics.h
===================================================================
--- branches/soc-2011-tomato/extern/libmv/libmv/simple_pipeline/camera_intrinsics.h	2011-08-17 07:03:54 UTC (rev 39478)
+++ branches/soc-2011-tomato/extern/libmv/libmv/simple_pipeline/camera_intrinsics.h	2011-08-17 07:16:11 UTC (rev 39479)
@@ -65,7 +65,7 @@
   /*!
       Apply camera intrinsics to the normalized point to get image coordinates.
 
-      This applies the camera intrinsics to a point which is in normalized
+      This applies the lens distortion to a point which is in normalized
       camera coordinates (i.e. the principal point is at (0, 0)) to get image
       coordinates in pixels.
   */
@@ -75,7 +75,7 @@
   /*!
       Invert camera intrinsics on the image point to get normalized coordinates.
 
-      This reverses the effect of camera intrinsics on a point which is in image
+      This reverses the effect of lens distortion on a point which is in image
       coordinates to get normalized camera coordinates.
   */
   void InvertIntrinsics(double image_x, double image_y,

Added: branches/soc-2011-tomato/extern/libmv/libmv/tracking/sad.cc
===================================================================
--- branches/soc-2011-tomato/extern/libmv/libmv/tracking/sad.cc	                        (rev 0)
+++ branches/soc-2011-tomato/extern/libmv/libmv/tracking/sad.cc	2011-08-17 07:16:11 UTC (rev 39479)
@@ -0,0 +1,129 @@
+/****************************************************************************
+**
+** Copyright (c) 2011 libmv authors.
+**
+** Permission is hereby granted, free of charge, to any person obtaining a copy
+** of this software and associated documentation files (the "Software"), to
+** deal in the Software without restriction, including without limitation the
+** rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
+** sell copies of the Software, and to permit persons to whom the Software is
+** furnished to do so, subject to the following conditions:
+**
+** The above copyright notice and this permission notice shall be included in
+** all copies or substantial portions of the Software.
+**
+** THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+** IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+** FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+** AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+** LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+** FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
+** IN THE SOFTWARE.
+**
+****************************************************************************/
+
+#include "libmv/tracking/sad.h"
+#include <stdlib.h>
+#include <math.h>
+
+namespace libmv {
+
+struct vec2 {
+  float x,y;
+  inline vec2(float x, float y):x(x),y(y){}
+};
+static vec2 operator*(mat3 m, vec2 v) {
+  float z = v.x*m[6]+v.y*m[7]+m[8];
+  return vec2((v.x*m[0]+v.y*m[1]+m[2])/z,(v.x*m[3]+v.y*m[4]+m[5])/z);
+}
+
+//! fixed point bilinear sample with precision k
+template <int k> inline int sample(const ubyte* image,int stride, int x, int y, int u, int v) {
+  const ubyte* s = &image[y*stride+x];
+  return ((s[     0] * (k-u) + s[       1] * u) * (k-v)
+        + (s[stride] * (k-u) + s[stride+1] * u) * (  v) ) / (k*k);
+}
+
+void SamplePattern(const ubyte* image, int stride, mat3 warp, ubyte* pattern) {
+  const int k = 256;
+  for (int i = 0; i < 16; i++) for (int j = 0; j < 16; j++) {
+    vec2 p = warp*vec2(j-8,i-8);
+    int fx = lround(p.x*k), fy = lround(p.y*k);
+    int ix = fx/k, iy = fy/k;
+    int u = fx%k, v = fy%k;
+    pattern[i*16+j] = sample<k>(image,stride,ix,iy,u,v);
+  }
+}
+
+#ifdef __SSE2__
+#include <emmintrin.h>
+static uint SAD(const ubyte* pattern, const ubyte* image, int stride) {
+  __m128i a = _mm_setzero_si128();
+  for(int i = 0; i < 16; i++) {
+    a = _mm_adds_epu16(a, _mm_sad_epu8( _mm_loadu_si128((__m128i*)(pattern+i*16)),
+                                        _mm_loadu_si128((__m128i*)(image+i*stride))));
+  }
+  return _mm_extract_epi16(a,0) + _mm_extract_epi16(a,4);
+}
+#else
+static uint SAD(const ubyte* pattern, const ubyte* image, int stride) {
+  uint sad=0;
+  for(int i = 0; i < 16; i++) {
+    for(int j = 0; j < 16; j++) {
+      sad += abs((int)pattern[i*16+j] - image[i*stride+j]);
+    }
+  }
+  return sad;
+}
+#endif
+
+//float sq( float x ) { return x*x; }
+bool Track(const ubyte* pattern, const ubyte* image, int stride, int w, int h, float* px, float* py) {
+  int ix = *px-8, iy = *py-8;
+  uint min=-1;
+  // integer pixel
+  for(int y = 0; y < h-16; y++) {
+    for(int x = 0; x < w-16; x++) {
+      uint d = SAD(pattern,&image[y*stride+x],stride); //image L1 distance
+      //d += sq(x-w/2-8)+sq(y-h/2-8); //spatial L2 distance
+      if(d < min) {
+        min = d;
+        ix = x, iy = y;
+      }
+    }
+  }
+
+  const int kPrecision = 4; //subpixel precision in bits
+  const int kScale = 1<<kPrecision;
+  int fx=0,fy=0;
+  for(int k = 1; k <= kPrecision; k++) {
+    fx *= 2, fy *= 2;
+    int nx = fx, ny = fy;

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list