diff options
author | Sergey Sharybin <sergey.vfx@gmail.com> | 2013-05-30 16:05:20 +0400 |
---|---|---|
committer | Sergey Sharybin <sergey.vfx@gmail.com> | 2013-05-30 16:05:20 +0400 |
commit | c5b4983eca9ba782987b212d1fe50be3eb8c02cb (patch) | |
tree | d45216e0d4b261cabd2a6b311856084e9ad75210 /extern/libmv | |
parent | 281e538be0c3d55efaa9461e38231a07cc2db15b (diff) |
Remove files unused by blender's tracker
They were giving compilation error with msvc2012,
and instead of having workaround in them let's
drop them away form blender (they're not used even).
Diffstat (limited to 'extern/libmv')
-rw-r--r-- | extern/libmv/CMakeLists.txt | 4 | ||||
-rw-r--r-- | extern/libmv/ChangeLog | 19 | ||||
-rw-r--r-- | extern/libmv/files.txt | 4 | ||||
-rw-r--r-- | extern/libmv/libmv/tracking/esm_region_tracker.cc | 313 | ||||
-rw-r--r-- | extern/libmv/libmv/tracking/esm_region_tracker.h | 63 | ||||
-rw-r--r-- | extern/libmv/libmv/tracking/lmicklt_region_tracker.cc | 253 | ||||
-rw-r--r-- | extern/libmv/libmv/tracking/lmicklt_region_tracker.h | 62 | ||||
-rw-r--r-- | extern/libmv/libmv/tracking/track_region.h | 2 |
8 files changed, 9 insertions, 711 deletions
diff --git a/extern/libmv/CMakeLists.txt b/extern/libmv/CMakeLists.txt index 4c88a4b7cc2..2c9a21965f0 100644 --- a/extern/libmv/CMakeLists.txt +++ b/extern/libmv/CMakeLists.txt @@ -75,10 +75,8 @@ if(WITH_LIBMV) libmv/simple_pipeline/resect.cc libmv/simple_pipeline/tracks.cc libmv/tracking/brute_region_tracker.cc - libmv/tracking/esm_region_tracker.cc libmv/tracking/hybrid_region_tracker.cc libmv/tracking/klt_region_tracker.cc - libmv/tracking/lmicklt_region_tracker.cc libmv/tracking/pyramid_region_tracker.cc libmv/tracking/retrack_region_tracker.cc libmv/tracking/track_region.cc @@ -134,10 +132,8 @@ if(WITH_LIBMV) libmv/simple_pipeline/resect.h libmv/simple_pipeline/tracks.h libmv/tracking/brute_region_tracker.h - libmv/tracking/esm_region_tracker.h libmv/tracking/hybrid_region_tracker.h libmv/tracking/klt_region_tracker.h - libmv/tracking/lmicklt_region_tracker.h libmv/tracking/pyramid_region_tracker.h libmv/tracking/region_tracker.h libmv/tracking/retrack_region_tracker.h diff --git a/extern/libmv/ChangeLog b/extern/libmv/ChangeLog index 34f63011ea8..0176fda6455 100644 --- a/extern/libmv/ChangeLog +++ b/extern/libmv/ChangeLog @@ -1,3 +1,12 @@ +commit f61b8198b9bddd8d2fa53feae7924aa23df48cbd +Author: Sergey Sharybin <sergey.vfx@gmail.com> +Date: Thu May 30 18:00:03 2013 +0600 + + Code cleanup + + - Made some arguments passing to detector const. + - Remove unneeded include from track_region header. + commit 61ac890908a397860cabc60207500039876532cc Author: Sergey Sharybin <sergey.vfx@gmail.com> Date: Mon May 13 04:44:14 2013 +0600 @@ -624,13 +633,3 @@ Date: Fri Mar 1 17:40:38 2013 +0600 refining are much more usable than it were before. Thanks to Keir for the help and code review! - -commit 5d6c2e7a27bdd1a1b23bf289d70a9b8f62514c9a -Author: Sergey Sharybin <sergey.vfx@gmail.com> -Date: Fri Mar 1 17:37:35 2013 +0600 - - Increase verbosity level for reprojected markers info - - This information is useful, but in cases when you, say, - working on a bundler it's annoying to scroll all the - information up. diff --git a/extern/libmv/files.txt b/extern/libmv/files.txt index bfa22bfe898..e5297c7cced 100644 --- a/extern/libmv/files.txt +++ b/extern/libmv/files.txt @@ -62,14 +62,10 @@ libmv/simple_pipeline/tracks.cc libmv/simple_pipeline/tracks.h libmv/tracking/brute_region_tracker.cc libmv/tracking/brute_region_tracker.h -libmv/tracking/esm_region_tracker.cc -libmv/tracking/esm_region_tracker.h libmv/tracking/hybrid_region_tracker.cc libmv/tracking/hybrid_region_tracker.h libmv/tracking/klt_region_tracker.cc libmv/tracking/klt_region_tracker.h -libmv/tracking/lmicklt_region_tracker.cc -libmv/tracking/lmicklt_region_tracker.h libmv/tracking/pyramid_region_tracker.cc libmv/tracking/pyramid_region_tracker.h libmv/tracking/region_tracker.h diff --git a/extern/libmv/libmv/tracking/esm_region_tracker.cc b/extern/libmv/libmv/tracking/esm_region_tracker.cc deleted file mode 100644 index d50c9420767..00000000000 --- a/extern/libmv/libmv/tracking/esm_region_tracker.cc +++ /dev/null @@ -1,313 +0,0 @@ -// Copyright (c) 2007, 2008, 2009, 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. - -/* needed for M_E when building with msvc */ -#define _USE_MATH_DEFINES - -#include "libmv/tracking/esm_region_tracker.h" - -#include "libmv/logging/logging.h" -#include "libmv/image/image.h" -#include "libmv/image/convolve.h" -#include "libmv/image/correlation.h" -#include "libmv/image/sample.h" -#include "libmv/numeric/numeric.h" -#include "libmv/tracking/track_region.h" - -namespace libmv { - -// TODO(keir): Reduce duplication between here and the other region trackers. -static bool RegionIsInBounds(const FloatImage &image1, - double x, double y, - int half_window_size) { - // Check the minimum coordinates. - int min_x = floor(x) - half_window_size - 1; - int min_y = floor(y) - half_window_size - 1; - if (min_x < 0.0 || - min_y < 0.0) { - LG << "Out of bounds; min_x: " << min_x << ", min_y: " << min_y; - return false; - } - - // Check the maximum coordinates. - int max_x = ceil(x) + half_window_size + 1; - int max_y = ceil(y) + half_window_size + 1; - if (max_x > image1.cols() || - max_y > image1.rows()) { - LG << "Out of bounds; max_x: " << max_x << ", max_y: " << max_y - << ", image1.cols(): " << image1.cols() - << ", image1.rows(): " << image1.rows(); - return false; - } - - // Ok, we're good. - return true; -} - -/* Ugly but necessary fix for compilation on VS2012 - * this file causes an Internal Compiler Error */ -// TODO: check regularly if ICE is fixed by MS! -#if defined(_MSC_VER) && defined(_WIN64) && (_MSC_VER >= 1700) -#pragma optimize("s", on) -#endif - -// This is implemented from "Lukas and Kanade 20 years on: Part 1. Page 42, -// figure 14: the Levenberg-Marquardt-Inverse Compositional Algorithm". -bool EsmRegionTracker::Track(const FloatImage &image1, - const FloatImage &image2, - double x1, double y1, - double *x2, double *y2) const { - if (!RegionIsInBounds(image1, x1, y1, half_window_size)) { - LG << "Fell out of image1's window with x1=" << x1 << ", y1=" << y1 - << ", hw=" << half_window_size << "."; - return false; - } - - // XXX - // TODO(keir): Delete the block between the XXX's once the planar tracker is - // integrated into blender. - // - // For now, to test, replace the ESM tracker with the Ceres tracker in - // translation mode. In the future, this should get removed and alloed to - // co-exist, since Ceres is not as fast as the ESM implementation since it - // specializes for translation. - double xx1[4], yy1[4]; - double xx2[4], yy2[4]; - // Clockwise winding, starting from the "origin" (top-left). - xx1[0] = xx2[0] = x1 - half_window_size; - yy1[0] = yy2[0] = y1 - half_window_size; - - xx1[1] = xx2[1] = x1 + half_window_size; - yy1[1] = yy2[1] = y1 - half_window_size; - - xx1[2] = xx2[2] = x1 + half_window_size; - yy1[2] = yy2[2] = y1 + half_window_size; - - xx1[3] = xx2[3] = x1 - half_window_size; - yy1[3] = yy2[3] = y1 + half_window_size; - - TrackRegionOptions options; - options.mode = TrackRegionOptions::TRANSLATION; - options.max_iterations = 20; - options.sigma = sigma; - options.use_esm = true; - - TrackRegionResult result; - TrackRegion(image1, image2, xx1, yy1, options, xx2, yy2, &result); - - *x2 = xx2[0] + half_window_size; - *y2 = yy2[0] + half_window_size; - - return true; - - // XXX - int width = 2 * half_window_size + 1; - - // TODO(keir): Avoid recomputing gradients for e.g. the pyramid tracker. - Array3Df image_and_gradient1; - Array3Df image_and_gradient2; - BlurredImageAndDerivativesChannels(image1, sigma, &image_and_gradient1); - BlurredImageAndDerivativesChannels(image2, sigma, &image_and_gradient2); - - // Step -1: Resample the template (image1) since it is not pixel aligned. - // - // Take a sample of the gradient of the pattern area of image1 at the - // subpixel position x1, x2. This is reused for each iteration, so - // precomputing it saves time. - Array3Df image_and_gradient1_sampled; - SamplePattern(image_and_gradient1, x1, y1, half_window_size, 3, - &image_and_gradient1_sampled); - - // Step 0: Initialize delta = 0.01. - // - // Ignored for my "normal" LM loop. - - // Step 1: Warp I with W(x, p) to compute I(W(x; p). - // - // Use two images for accepting / rejecting updates. - // XXX is this necessary? - int current_image = 0, new_image = 1; - Array3Df image_and_gradient2_sampled[2]; - SamplePattern(image_and_gradient2, *x2, *y2, half_window_size, 3, - &image_and_gradient2_sampled[current_image]); - - // Step 2: Compute the squared error I - J. - double error = 0; - for (int r = 0; r < width; ++r) { - for (int c = 0; c < width; ++c) { - double e = image_and_gradient1_sampled(r, c, 0) - - image_and_gradient2_sampled[current_image](r, c, 0); - error += e*e; - } - } - - // Step 3: Evaluate the gradient of the template. - // - // This is done above when sampling the template (step -1). - - // Step 4: Evaluate the jacobian dw/dp at (x; 0). - // - // The jacobian between dx,dy and the warp is constant 2x2 identity, so it - // doesn't have to get computed. The Gauss-Newton Hessian matrix computation - // below would normally have to include a multiply by the jacobian. - - // Step 5: Compute the steepest descent images of the template. - // - // Since the jacobian of the position w.r.t. the sampled template position is - // the identity, the steepest descent images are the same as the gradient. - - // Step 6: Compute the Gauss-Newton Hessian for the template (image1). - // - // This could get rolled into the previous loop, but split it for now for - // clarity. - Mat2 H_image1 = Mat2::Zero(); - for (int r = 0; r < width; ++r) { - for (int c = 0; c < width; ++c) { - Vec2 g(image_and_gradient1_sampled(r, c, 1), - image_and_gradient1_sampled(r, c, 2)); - H_image1 += g * g.transpose(); - } - } - - double tau = 1e-4; - - double mu = tau * std::max(H_image1(0, 0), H_image1(1, 1)); - double nu = M_E; - - int i; - for (i = 0; i < max_iterations; ++i) { - // Check that the entire image patch is within the bounds of the images. - if (!RegionIsInBounds(image2, *x2, *y2, half_window_size)) { - LG << "Fell out of image2's window with x2=" << *x2 << ", y2=" << *y2 - << ", hw=" << half_window_size << "."; - return false; - } - - Mat2 H = Mat2::Zero(); - for (int r = 0; r < width; ++r) { - for (int c = 0; c < width; ++c) { - Vec2 g1(image_and_gradient1_sampled(r, c, 1), - image_and_gradient1_sampled(r, c, 2)); - Vec2 g2(image_and_gradient2_sampled[current_image](r, c, 1), - image_and_gradient2_sampled[current_image](r, c, 2)); - Vec2 g = g1 + g2; // Should be / 2.0, but do that outside the loop. - H += g * g.transpose(); - } - } - H /= 4.0; - - // Step 7: Compute z - Vec2 z = Vec2::Zero(); - for (int r = 0; r < width; ++r) { - for (int c = 0; c < width; ++c) { - double e = image_and_gradient2_sampled[current_image](r, c, 0) - - image_and_gradient1_sampled(r, c, 0); - z(0) += image_and_gradient1_sampled(r, c, 1) * e; - z(1) += image_and_gradient1_sampled(r, c, 2) * e; - z(0) += image_and_gradient2_sampled[current_image](r, c, 1) * e; - z(1) += image_and_gradient2_sampled[current_image](r, c, 2) * e; - } - } - z /= 2.0; - - // Step 8: Compute Hlm and (dx,dy) - Mat2 diag = H.diagonal().asDiagonal(); - diag *= mu; - Mat2 Hlm = H + diag; - Vec2 d = Hlm.lu().solve(z); - - // TODO(keir): Use the usual LM termination and update criterion instead of - // this hacky version from the LK 20 years on paper. - LG << "x=" << *x2 << ", y=" << *y2 << ", dx=" << d[0] << ", dy=" << d[1] - << ", mu=" << mu << ", nu=" << nu; - - // Step 9: Update the warp; W(x; p) <-- W(x;p) compose W(x, dp)^-1 - double new_x2 = *x2 - d[0]; - double new_y2 = *y2 - d[1]; - - // Step 9.1: Sample the image at the new position. - SamplePattern(image_and_gradient2, new_x2, new_y2, half_window_size, 3, - &image_and_gradient2_sampled[new_image]); - - // Step 9.2: Compute the new error. - // TODO(keir): Eliminate duplication with above code. - double new_error = 0; - for (int r = 0; r < width; ++r) { - for (int c = 0; c < width; ++c) { - double e = image_and_gradient1_sampled(r, c, 0) - - image_and_gradient2_sampled[new_image](r, c, 0); - new_error += e*e; - } - } - LG << "Old error: " << error << ", new error: " << new_error; - - double rho = (error - new_error) / (d.transpose() * (mu * d + z)); - - // Step 10: Accept or reject step. - if (rho <= 0) { - // This was a bad step, so don't update. - mu *= nu; - - // The standard Levenberg-Marquardt update multiplies nu by 2, but - // instead chose e. I chose a constant greater than 2 since in typical - // tracking examples, I saw that once updates started failing they should - // ramp towards steepest descent faster. This has no basis in theory, but - // appears to lead to faster tracking overall. - nu *= M_E; - LG << "Error increased, so reject update."; - } else { - // The step was good, so update. - *x2 = new_x2; - *y2 = new_y2; - std::swap(new_image, current_image); - error = new_error; - - mu *= std::max(1/3., 1 - pow(2*rho - 1, 3)); - nu = M_E; // See above for why to use e. - LG << "Error decreased, so accept update."; - } - - // If the step was accepted, then check for termination. - if (d.squaredNorm() < min_update_squared_distance) { - // Compute the Pearson product-moment correlation coefficient to check - // for sanity. - double correlation = PearsonProductMomentCorrelation( - image_and_gradient1_sampled, - image_and_gradient2_sampled[new_image], - width); - LG << "Final correlation: " << correlation; - - // Note: Do the comparison here to handle nan's correctly (since all - // comparisons with nan are false). - if (minimum_correlation < correlation) { - LG << "Successful track in " << (i + 1) << " iterations."; - return true; - } - LG << "Correlation " << correlation << " greater than " - << minimum_correlation << " or is nan; bailing."; - return false; - } - } - // Getting here means we hit max iterations, so tracking failed. - LG << "Too many iterations; max is set to " << max_iterations << "."; - return false; -} - -} // namespace libmv diff --git a/extern/libmv/libmv/tracking/esm_region_tracker.h b/extern/libmv/libmv/tracking/esm_region_tracker.h deleted file mode 100644 index 97b8e27dba2..00000000000 --- a/extern/libmv/libmv/tracking/esm_region_tracker.h +++ /dev/null @@ -1,63 +0,0 @@ -// Copyright (c) 2007, 2008, 2009, 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. - -#ifndef LIBMV_REGION_TRACKING_LMICKLT_REGION_TRACKER_H_ -#define LIBMV_REGION_TRACKING_LMICKLT_REGION_TRACKER_H_ - -#include "libmv/image/image.h" -#include "libmv/tracking/region_tracker.h" - -namespace libmv { - -/*! - A translation-only Efficient Second-order Minimization ("ESM") tracker - - Based on the paper "Real-time image-based trackiing of planes using - Efficient Second-order Minimization" -*/ -struct EsmRegionTracker : public RegionTracker { - EsmRegionTracker() - : half_window_size(4), - max_iterations(16), - min_determinant(1e-6), - min_update_squared_distance(1e-4), - sigma(0.9), - minimum_correlation(0.78) {} - - virtual ~EsmRegionTracker() {} - - // Tracker interface. - virtual bool Track(const FloatImage &image1, - const FloatImage &image2, - double x1, double y1, - double *x2, double *y2) const; - - // No point in creating getters or setters. - int half_window_size; - int max_iterations; - double min_determinant; - double min_update_squared_distance; - double sigma; - double minimum_correlation; -}; - -} // namespace libmv - -#endif // LIBMV_REGION_TRACKING_LMICKLT_REGION_TRACKER_H_ diff --git a/extern/libmv/libmv/tracking/lmicklt_region_tracker.cc b/extern/libmv/libmv/tracking/lmicklt_region_tracker.cc deleted file mode 100644 index 5b281870f8d..00000000000 --- a/extern/libmv/libmv/tracking/lmicklt_region_tracker.cc +++ /dev/null @@ -1,253 +0,0 @@ -// Copyright (c) 2007, 2008, 2009, 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/lmicklt_region_tracker.h" - -#include "libmv/logging/logging.h" -#include "libmv/image/image.h" -#include "libmv/image/convolve.h" -#include "libmv/image/sample.h" -#include "libmv/numeric/numeric.h" - -namespace libmv { - -// TODO(keir): Reduce duplication between here and the other region trackers. -static bool RegionIsInBounds(const FloatImage &image1, - double x, double y, - int half_window_size) { - // Check the minimum coordinates. - int min_x = floor(x) - half_window_size - 1; - int min_y = floor(y) - half_window_size - 1; - if (min_x < 0.0 || - min_y < 0.0) { - return false; - } - - // Check the maximum coordinates. - int max_x = ceil(x) + half_window_size + 1; - int max_y = ceil(y) + half_window_size + 1; - if (max_x > image1.cols() || - max_y > image1.rows()) { - return false; - } - - // Ok, we're good. - return true; -} - -/* Ugly but necessary fix for compilation on VS2012 - * this file causes an Internal Compiler Error */ -// TODO: check regularly if ICE is fixed by MS! -#if defined(_WIN64) && defined(_MSC_VER) && (_MSC_VER >= 1700) -#pragma optimize("s", on) -#endif - -// Estimate "reasonable" error by computing autocorrelation for a small shift. -static double EstimateReasonableError(const FloatImage &image, - double x, double y, - int half_width) { - double error = 0.0; - for (int r = -half_width; r <= half_width; ++r) { - for (int c = -half_width; c <= half_width; ++c) { - double s = SampleLinear(image, y + r, x + c, 0); - double e1 = SampleLinear(image, y + r + 0.5, x + c, 0) - s; - double e2 = SampleLinear(image, y + r, x + c + 0.5, 0) - s; - error += e1*e1 + e2*e2; - } - } - return error / 2.0 * 8.0; -} - -// This is implemented from "Lukas and Kanade 20 years on: Part 1. Page 42, -// figure 14: the Levenberg-Marquardt-Inverse Compositional Algorithm". -bool LmickltRegionTracker::Track(const FloatImage &image1, - const FloatImage &image2, - double x1, double y1, - double *x2, double *y2) const { - if (!RegionIsInBounds(image1, x1, y1, half_window_size)) { - LG << "Fell out of image1's window with x1=" << x1 << ", y1=" << y1 - << ", hw=" << half_window_size << "."; - return false; - } - - int width = 2 * half_window_size + 1; - - // TODO(keir): Avoid recomputing gradients for e.g. the pyramid tracker. - Array3Df image_and_gradient1; - Array3Df image_and_gradient2; - BlurredImageAndDerivativesChannels(image1, sigma, &image_and_gradient1); - - // TODO(keir): Avoid computing the derivative of image2. - BlurredImageAndDerivativesChannels(image2, sigma, &image_and_gradient2); - - // Step -1: Resample the template (image1) since it is not pixel aligned. - // - // Take a sample of the gradient of the pattern area of image1 at the - // subpixel position x1, x2. This is reused for each iteration, so - // precomputing it saves time. - Array3Df image_and_gradient1_sampled; - SamplePattern(image_and_gradient1, x1, y1, half_window_size, 3, - &image_and_gradient1_sampled); - - // Step 0: Initialize delta = 0.01. - // - // Ignored for my "normal" LM loop. - - double reasonable_error = - EstimateReasonableError(image1, x1, y1, half_window_size); - - // Step 1: Warp I with W(x, p) to compute I(W(x; p). - // - // Use two images for accepting / rejecting updates. - int current_image = 0, new_image = 1; - Array3Df image2_sampled[2]; - SamplePattern(image_and_gradient2, *x2, *y2, half_window_size, 1, - &image2_sampled[current_image]); - - // Step 2: Compute the squared error I - J. - double error = 0; - for (int r = 0; r < width; ++r) { - for (int c = 0; c < width; ++c) { - double e = image_and_gradient1_sampled(r, c, 0) - - image2_sampled[current_image](r, c, 0); - error += e*e; - } - } - - // Step 3: Evaluate the gradient of the template. - // - // This is done above when sampling the template (step -1). - - // Step 4: Evaluate the jacobian dw/dp at (x; 0). - // - // The jacobian between dx,dy and the warp is constant 2x2 identity, so it - // doesn't have to get computed. The Gauss-Newton Hessian matrix computation - // below would normally have to include a multiply by the jacobian. - - // Step 5: Compute the steepest descent images of the template. - // - // Since the jacobian of the position w.r.t. the sampled template position is - // the identity, the steepest descent images are the same as the gradient. - - // Step 6: Compute the Gauss-Newton Hessian for the template (image1). - // - // This could get rolled into the previous loop, but split it for now for - // clarity. - Mat2 H = Mat2::Zero(); - for (int r = 0; r < width; ++r) { - for (int c = 0; c < width; ++c) { - Vec2 g(image_and_gradient1_sampled(r, c, 1), - image_and_gradient1_sampled(r, c, 2)); - H += g * g.transpose(); - } - } - - double tau = 1e-3; - - double mu = tau * std::max(H(0, 0), H(1, 1)); - double nu = 2.0; - - int i; - for (i = 0; i < max_iterations; ++i) { - // Check that the entire image patch is within the bounds of the images. - if (!RegionIsInBounds(image2, *x2, *y2, half_window_size)) { - LG << "Fell out of image2's window with x2=" << *x2 << ", y2=" << *y2 - << ", hw=" << half_window_size << "."; - return false; - } - - // Step 7: Compute z - Vec2 z = Vec2::Zero(); - for (int r = 0; r < width; ++r) { - for (int c = 0; c < width; ++c) { - double e = image2_sampled[current_image](r, c, 0) - - image_and_gradient1_sampled(r, c, 0); - z(0) += image_and_gradient1_sampled(r, c, 1) * e; - z(1) += image_and_gradient1_sampled(r, c, 2) * e; - } - } - - // Step 8: Compute Hlm and (dx,dy) - Mat2 diag = H.diagonal().asDiagonal(); - diag *= mu; - Mat2 Hlm = H + diag; - Vec2 d = Hlm.lu().solve(z); - - // TODO(keir): Use the usual LM termination and update criterion instead of - // this hacky version from the LK 20 years on paper. - LG << "x=" << *x2 << ", y=" << *y2 << ", dx=" << d[0] << ", dy=" << d[1] - << ", mu=" << mu << ", nu=" << nu; - - // Step 9: Update the warp; W(x; p) <-- W(x;p) compose W(x, dp)^-1 - double new_x2 = *x2 - d[0]; - double new_y2 = *y2 - d[1]; - - // Step 9.1: Sample the image at the new position. - SamplePattern(image_and_gradient2, new_x2, new_y2, half_window_size, 1, - &image2_sampled[new_image]); - - // Step 9.2: Compute the new error. - // TODO(keir): Eliminate duplication with above code. - double new_error = 0; - for (int r = 0; r < width; ++r) { - for (int c = 0; c < width; ++c) { - double e = image_and_gradient1_sampled(r, c, 0) - - image2_sampled[new_image](r, c, 0); - new_error += e*e; - } - } - LG << "Old error: " << error << ", new error: " << new_error; - - // If the step was accepted, then check for termination. - if (d.squaredNorm() < min_update_squared_distance) { - if (new_error > reasonable_error) { - LG << "Update size shrank but reasonable error (" - << reasonable_error << ") not achieved; failing."; - return false; - } - LG << "Successful track in " << i << " iterations."; - return true; - } - - double rho = (error - new_error) / (d.transpose() * (mu * d + z)); - - // Step 10: Accept or reject step. - if (rho <= 0) { - // This was a bad step, so don't update. - mu *= nu; - nu *= 2; - LG << "Error increased, so reject update."; - } else { - // The step was good, so update. - *x2 = new_x2; - *y2 = new_y2; - std::swap(new_image, current_image); - error = new_error; - - mu *= std::max(1/3., 1 - pow(2*rho - 1, 3)); - nu = 2; - } - } - // Getting here means we hit max iterations, so tracking failed. - LG << "Too many iterations; max is set to " << max_iterations << "."; - return false; -} - -} // namespace libmv diff --git a/extern/libmv/libmv/tracking/lmicklt_region_tracker.h b/extern/libmv/libmv/tracking/lmicklt_region_tracker.h deleted file mode 100644 index 95f4ba5f9b5..00000000000 --- a/extern/libmv/libmv/tracking/lmicklt_region_tracker.h +++ /dev/null @@ -1,62 +0,0 @@ -// Copyright (c) 2007, 2008, 2009, 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. - -#ifndef LIBMV_REGION_TRACKING_LMICKLT_REGION_TRACKER_H_ -#define LIBMV_REGION_TRACKING_LMICKLT_REGION_TRACKER_H_ - -#include "libmv/image/image.h" -#include "libmv/tracking/region_tracker.h" - -namespace libmv { - -/*! - Levenberg-Marquardt inverse compositional region tracking - - This tracker implements the Levenberg-Marquardt inverse compositional - region tracking algorithm as described in the paper "Lucas and Kanade 20 - years on: A unifying framework." -*/ -struct LmickltRegionTracker : public RegionTracker { - LmickltRegionTracker() - : half_window_size(4), - max_iterations(16), - min_determinant(1e-6), - min_update_squared_distance(1e-6), - sigma(0.9) {} - - virtual ~LmickltRegionTracker() {} - - // Tracker interface. - virtual bool Track(const FloatImage &image1, - const FloatImage &image2, - double x1, double y1, - double *x2, double *y2) const; - - // No point in creating getters or setters. - int half_window_size; - int max_iterations; - double min_determinant; - double min_update_squared_distance; - double sigma; -}; - -} // namespace libmv - -#endif // LIBMV_REGION_TRACKING_LMICKLT_REGION_TRACKER_H_ diff --git a/extern/libmv/libmv/tracking/track_region.h b/extern/libmv/libmv/tracking/track_region.h index cd7ee0aa2ba..6c7218f11d1 100644 --- a/extern/libmv/libmv/tracking/track_region.h +++ b/extern/libmv/libmv/tracking/track_region.h @@ -23,8 +23,6 @@ // Necessary for M_E when building with MSVC. #define _USE_MATH_DEFINES -#include "libmv/tracking/esm_region_tracker.h" - #include "libmv/image/image.h" #include "libmv/image/sample.h" #include "libmv/numeric/numeric.h" |