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

Sergey Sharybin g.ulairi at gmail.com
Wed Aug 17 19:12:11 CEST 2011


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

- Bundling new libmv, issues with undefined uint and C99 functions should gone.
- Changes to Detect operator to match new API.

Modified Paths:
--------------
    branches/soc-2011-tomato/extern/libmv/ChangeLog
    branches/soc-2011-tomato/extern/libmv/libmv/numeric/function_derivative.h
    branches/soc-2011-tomato/extern/libmv/libmv/numeric/levenberg_marquardt.h
    branches/soc-2011-tomato/extern/libmv/libmv/simple_pipeline/detect.cc
    branches/soc-2011-tomato/extern/libmv/libmv/simple_pipeline/detect.h
    branches/soc-2011-tomato/extern/libmv/libmv/tracking/sad.cc
    branches/soc-2011-tomato/extern/libmv/libmv/tracking/sad.h
    branches/soc-2011-tomato/extern/libmv/libmv-capi.cpp
    branches/soc-2011-tomato/extern/libmv/libmv-capi.h
    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

Modified: branches/soc-2011-tomato/extern/libmv/ChangeLog
===================================================================
--- branches/soc-2011-tomato/extern/libmv/ChangeLog	2011-08-17 15:55:42 UTC (rev 39496)
+++ branches/soc-2011-tomato/extern/libmv/ChangeLog	2011-08-17 17:12:10 UTC (rev 39497)
@@ -1,3 +1,49 @@
+commit d22720e618456329388d2c107422c3b371657cba
+Author: Matthias Fauconneau <matthias.fauconneau at gmail.com>
+Date:   Wed Aug 17 14:14:45 2011 +0200
+
+    Improve Detect and SAD Tracker API and documentation.
+
+commit 5d6cd4ad365b061901bad40695b51d568487a0cf
+Author: Matthias Fauconneau <matthias.fauconneau at gmail.com>
+Date:   Wed Aug 17 11:57:29 2011 +0200
+
+    MSVC support fixes.
+
+commit 50f0323173c6deebd6aaf9c126f0b51b2a79c3c1
+Author: Matthias Fauconneau <matthias.fauconneau at gmail.com>
+Date:   Tue Aug 16 23:21:37 2011 +0200
+
+    Detector can detect features similar to a given pattern.
+
+commit 5734cc27bbf84c2b6edcfcc1ea736798e12d5820
+Author: Matthias Fauconneau <matthias.fauconneau at gmail.com>
+Date:   Tue Aug 16 22:53:54 2011 +0200
+
+    Ensure SAD Tracker is C compatible.
+    Update Detect API documentation.
+
+commit 701c42842574064fea992f8822e3899cb9066108
+Author: Matthias Fauconneau <matthias.fauconneau at gmail.com>
+Date:   Tue Aug 16 21:56:42 2011 +0200
+
+    Remove FAST detector.
+    Add Moravec detector.
+    This detector is more suited to tracking since it try to choose patterns which are unlikely to drift by computing SAD with neighbouring patches.
+    It could be improved to better avoid edges.
+
+commit 9bdf93e13fc880c78b6f34397da673388c16040e
+Author: Matthias Fauconneau <matthias.fauconneau at gmail.com>
+Date:   Tue Aug 16 21:55:08 2011 +0200
+
+    Fix Qt Tracker GL to work with AMD drivers.
+
+commit 81613ee0cc94b315f333c9632b18b95d426aad05
+Author: Matthias Fauconneau <matthias.fauconneau at gmail.com>
+Date:   Tue Aug 16 21:54:12 2011 +0200
+
+    Make CameraIntrinsics (and thus Qt tracker) compilable without linking libmv.
+
 commit a1d9a8fa8b01ef7cf2a79b3b891633fc333fc9cf
 Author: Matthias Fauconneau <matthias.fauconneau at gmail.com>
 Date:   Tue Aug 16 21:24:51 2011 +0200

Modified: branches/soc-2011-tomato/extern/libmv/libmv/numeric/function_derivative.h
===================================================================
--- branches/soc-2011-tomato/extern/libmv/libmv/numeric/function_derivative.h	2011-08-17 15:55:42 UTC (rev 39496)
+++ branches/soc-2011-tomato/extern/libmv/libmv/numeric/function_derivative.h	2011-08-17 17:12:10 UTC (rev 39497)
@@ -24,7 +24,6 @@
 #include <cmath>
 
 #include "libmv/numeric/numeric.h"
-#include "libmv/logging/logging.h"
 
 namespace libmv {
 
@@ -98,7 +97,7 @@
 
   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;
 }
 

Modified: branches/soc-2011-tomato/extern/libmv/libmv/numeric/levenberg_marquardt.h
===================================================================
--- branches/soc-2011-tomato/extern/libmv/libmv/numeric/levenberg_marquardt.h	2011-08-17 15:55:42 UTC (rev 39496)
+++ branches/soc-2011-tomato/extern/libmv/libmv/numeric/levenberg_marquardt.h	2011-08-17 17:12:10 UTC (rev 39497)
@@ -33,7 +33,6 @@
 
 #include "libmv/numeric/numeric.h"
 #include "libmv/numeric/function_derivative.h"
-#include "libmv/logging/logging.h"
 
 namespace libmv {
 
@@ -124,40 +123,26 @@
     Parameters dx, x_new;
     int i;
     for (i = 0; results.status == RUNNING && i < params.max_iterations; ++i) {
-      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()) {
+      if (dx.norm() <= params.relative_step_threshold * x.norm()) {
         results.status = RELATIVE_STEP_SIZE_TOO_SMALL;
         break;
-      } 
-      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;
-        } 
-      } 
+      }
+      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/libmv/simple_pipeline/detect.cc
===================================================================
--- branches/soc-2011-tomato/extern/libmv/libmv/simple_pipeline/detect.cc	2011-08-17 15:55:42 UTC (rev 39496)
+++ branches/soc-2011-tomato/extern/libmv/libmv/simple_pipeline/detect.cc	2011-08-17 17:12:10 UTC (rev 39497)
@@ -23,49 +23,84 @@
 ****************************************************************************/
 
 #include "libmv/simple_pipeline/detect.h"
-#include <third_party/fast/fast.h>
-#include <stdlib.h>
+#include <string.h>
 
 namespace libmv {
 
-std::vector<Corner> Detect(const unsigned char* data, int width, int height, int stride,
-                           int margin, int min_trackness, int min_distance) {
-  std::vector<Corner> corners;
-  data += margin*width + margin;
-  // TODO(MatthiasF): Support targetting a feature count (binary search trackness)
-  int num_corners;
-  xy* all = fast9_detect(data, width-2*margin, height-2*margin,
-                         stride, min_trackness, &num_corners);
-  if(num_corners == 0) {
-    free(all);
-    return corners;
+#ifdef __SSE2__
+#include <emmintrin.h>
+static uint SAD(const ubyte* imageA, const ubyte* imageB, int strideA, int strideB) {
+  __m128i a = _mm_setzero_si128();
+  for(int i = 0; i < 16; i++) {
+    a = _mm_adds_epu16(a, _mm_sad_epu8( _mm_loadu_si128((__m128i*)(imageA+i*strideA)),
+                                        _mm_loadu_si128((__m128i*)(imageB+i*strideB))));
   }
-  int* scores = fast9_score(data, stride, all, num_corners, min_trackness);
-  // TODO: merge with close feature suppression
-  xy* nonmax = nonmax_suppression(all, scores, num_corners, &num_corners);
-  free(all);
-  // Remove too close features
-  // TODO(MatthiasF): A resolution independent parameter would be better than distance
-  // e.g. a coefficient going from 0 (no minimal distance) to 1 (optimal circle packing)
-  // FIXME(MatthiasF): this method will not necessarily give all maximum markers
-  if(num_corners) corners.reserve(num_corners);
-  for(int i = 0; i < num_corners; ++i) {
-    xy xy = nonmax[i];
-    Corner a = { xy.x+margin, xy.y+margin, scores[i], 7 };
-    // compare each feature against filtered set
-    for(int j = 0; j < corners.size(); j++) {
-      Corner& b = corners[j];
-      if ( (a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y) < min_distance*min_distance ) {
-        // already a nearby feature
-        goto skip;
+  return _mm_extract_epi16(a,0) + _mm_extract_epi16(a,4);
+}
+#else
+static uint SAD(const ubyte* imageA, const ubyte* imageB, int strideA, int strideB) {
+  uint sad=0;
+  for(int i = 0; i < 16; i++) {
+    for(int j = 0; j < 16; j++) {
+      sad += abs((int)imageA[i*strideA+j] - imageB[i*strideB+j]);
+    }
+  }
+  return sad;
+}
+#endif
+
+void Detect(ubyte* image, int stride, int width, int height, Feature* detected, int* count, int distance, ubyte* pattern) {
+  unsigned short histogram[256];
+  memset(histogram,0,sizeof(histogram));
+  ubyte scores[width*height];
+  memset(scores,0,sizeof(scores));
+  const int r = 1; //radius for self similarity comparison
+  for(int y=distance; y<height-distance; y++) {
+    for(int x=distance; x<width-distance; x++) {
+      ubyte* s = &image[y*stride+x];
+      int score = // low self-similarity with overlapping patterns //OPTI: load pattern once
+          SAD(s, s-r*stride-r, stride, stride)+SAD(s, s-r*stride, stride, stride)+SAD(s, s-r*stride+r, stride, stride)+
+          SAD(s, s         -r, stride, stride)+                                   SAD(s, s         +r, stride, stride)+
+          SAD(s, s+r*stride-r, stride, stride)+SAD(s, s+r*stride, stride, stride)+SAD(s, s+r*stride+r, stride, stride);
+      score /= 256; // normalize
+      if(pattern) score -= SAD(s, pattern, stride, 16); // find only features similar to pattern
+      if(score<=16) continue; // filter very self-similar features
+      score -= 16; // translate to score/histogram values
+      if(score>255) score=255; // clip
+      ubyte* c = &scores[y*width+x];
+      for(int i=-distance; i<0; i++) {
+        for(int j=-distance; j<distance; j++) {
+          int s = c[i*width+j];
+          if(s == 0) continue;
+          if(s >= score) goto nonmax;
+          c[i*width+j]=0, histogram[s]--;
+        }
       }
+      for(int i=0, j=-distance; j<0; j++) {
+        int s = c[i*width+j];
+        if(s == 0) continue;
+        if(s >= score) goto nonmax;
+        c[i*width+j]=0, histogram[s]--;
+      }
+      c[0] = score, histogram[score]++;
+      nonmax:;
     }
-    // otherwise add the new feature

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list