Commit Graph

164 Commits

Author SHA1 Message Date
Sergey Sharybin
0d7e4f3229 Camera tracking: synchronize changes with own branch
Should be no functional changes.
2012-12-20 11:03:39 +00:00
Sergey Sharybin
4aeed148d1 Fix for camera solver not working properly when built with scons 2012-12-09 17:42:36 +00:00
Sergey Sharybin
5ba213facd Camera tracking: fixed type in camera intrinsics update function
Seems to be from the very beginning here, not sure why nobody noticed this is wrong.
2012-12-07 13:47:35 +00:00
Campbell Barton
767bfba808 cmake was missing some header files. 2012-12-04 14:43:42 +00:00
Sergey Sharybin
1dd5a89c87 Motion tracking: dump mask image when dump images is enabled
This is pure development option which is enabled by defining DUMP_FAILURE
or DUMP_ALWAYS libmv-capi.
2012-11-20 12:54:28 +00:00
Sergey Sharybin
3bd7816c75 Camera Tracking: allow fallback to reprojection resection by user demand
This fixes some "regressions" introduced in rev50781 which lead to much
worse solution in some cases. Now it's possible to bring old behavior back.

Perhaps it's more like temporal solution for time being smarter solution is
found. But finding such a solution isn't so fast, so let's bring manual
control over reprojection usage.

But anyway, imo it's now nice to have a structure which could be used to
pass different settings to the solver.
2012-11-05 08:04:27 +00:00
Campbell Barton
536d9fec80 code cleanup:
- move object_iterators.c --> view3d_iterators. (ED_object.h had to include ED_view3d.h which isn't so nice)
- move projection functions from view3d_view.c --> view3d_project.c (view3d_view was becoming a mishmash of utility functions and operators).
- some some cmake includes as system-includes.
2012-10-17 04:13:03 +00:00
Campbell Barton
3a947cf537 code cleanup: remove redundant casts 2012-10-14 08:49:01 +00:00
Keir Mierle
e38c1a5ae7 Make Euclidean resection "always" succeed.
The Euclidean resection code had a magical constant, 1e-3, used to
compare the results of solving an equation. This failure detection
was well-intended, trying to prevent poor solutions from getting
made without notifying the caller. Unfortunately in practice, this
threshold is too conservative. Furthermore, it is not clear the
threshold should exist at all; the purpose of the Euclidean
resection is to come up with the best solution it can; other
methods (e.g. reprojection error) should be used to compare
whether the method succeeded.

This commit changes the Euclidean EPnP code to always succeed,
causing the previous fallback to projective resection to never
run. In most cases, this will result in better reconstructions.

This should, in most cases, fix the dreaded "flipping" problem.
2012-09-20 18:55:44 +00:00
Keir Mierle
5e433927b5 Fix variable naming in the planar tracker. 2012-09-20 02:27:34 +00:00
Keir Mierle
0af0da957d Add smarter tolerance checking in the planar tracker.
The planar tracker uses Ceres for the refinement stage. During
refinement, Ceres iteratively updates the parameters with the
latest best guess. If the change in the parameters falls below a
threshold, Ceres will abort successfully ("converged").

For the case of pure translation tracking, the parameters are
exactly the two pixel shifts (dx, dy), and measuring the change in
these parameters gives a meaningful termination criterion.
However, for all the other parameterizations like affine, where
the parameterization involves affine parameters that have no
physical interpretation, Ceres is left with no way to terminate
the solver early. With the existing code, often many iterations
are run long after Ceres has found a solution sufficiently
accurate for all tracking needs. No one needs tracking with
a quadrillionth of a pixel accuracy; that time is wasted.

This patch extends the existing iteration callback that is passed
in to Ceres to check if the pattern has fallen out of the search
window, to also check if the optimizer has made a tiny step. In
particular, if the maximum shift of any patch corner between two
successful optimizer steps is less than a threshold (currently
0.005 pixels), the track is declared successful and tracking
is terminated.

This leads to dramatic speed increases in some cases, with little
to no loss in track quality. This is especially apparent when
tracking patches with affine or perspective motion models. For
example, on some tracking cases I tried, the iterations Ceres took
went from 50 to 3.
2012-09-20 02:10:33 +00:00
Keir Mierle
a6f447427b Detect too-small planar tracking patches.
The planar tracker did not detect very skinny patches which have
effectively zero area and are untrackable. This adds detection and
rejection of patterns with zero area. This fixes a crash found by
during Mango production.
2012-09-19 22:25:02 +00:00
Keir Mierle
8a46b8454e Cleanup for when trackers fall out of the search window.
Sergey originally left a TODO() here, but his fix is the correct
one. I removed the TODO and fixed some comment issues.
2012-09-19 22:01:42 +00:00
Sergey Sharybin
16a698ad4a Fix crash when tracking in planar motion model (and maybe some other)
It was an Abort() caused by check for solver result not equal to USER_ABORT.

In some cases solver returns USER_ABORT due to BoundaryCheckingCallback
detects coordinates does not belong to image.

Somehow this callback wasn't called in previous version of Ceres and
in the same case marker was jumping. Now when the callback is called
it seems we could simply return failure of tracking without aborting
Blender.

Probably this is in fact some issue somewhere else, would double
check with Keir about this.
2012-09-19 12:43:39 +00:00
Sergey Sharybin
60e43ebf9c Ceres: resolve no previous declarations warnings
Currently done as patch applied on bundling, would forward it to Ceres developers.
2012-09-18 11:01:51 +00:00
Sergey Sharybin
e37ff1dd46 Libmv: resolved some compilation warnings (missed prototypes)
In some cases it was missed include of header file, in some other
cases symbol could be static.
2012-09-18 10:31:00 +00:00
Sergey Sharybin
c11ca1dc00 Libmv: fixed wrong function prototypes
Also mark non-public functions as static.
2012-09-18 07:09:07 +00:00
Campbell Barton
00c37e1ff6 code cleanup: correct include paths and comment 2012-09-17 04:08:36 +00:00
Sergey Sharybin
eacf3054aa Real fix for OSX CMake -- was a typo in build file generation file
Now Ceres re-bundling should go smooth :)
2012-09-16 14:43:44 +00:00
Jens Verwiebe
de72707b7d Fix OSX compile 2012-09-16 14:31:25 +00:00
Sergey Sharybin
3d84172bc8 Fix typo in one of previous commits 2012-09-16 13:58:15 +00:00
Sergey Sharybin
a4992871d6 Ceres: tweak namespace for hash classes for MSVC2010
Not sure if it'll solve all issues, but at least it should reduce
amount of errors.

Also added missed patch from previous commit.
2012-09-16 12:24:54 +00:00
Sergey Sharybin
02ef4cc33d Ceres: reshuffle include order to solve compilation error with MSVC
Not sure why exactly this happens, would need extra investigation
and should probably be also fixed in upstream.
2012-09-16 12:24:48 +00:00
Sergey Sharybin
bf6ab7a5e2 Libmv: remove unwind hack from CMake rules.
Such stuff better be solved in glog itself.

Should be pretty safe change since it was defined for CMake only
and AFAIR Jens wanted to get rid of this too.
2012-09-16 12:24:43 +00:00
Sergey Sharybin
a737bc49af Ceres: upgrade to version 1.3.0
This should contain real fixes for Windows, making it more robost and hopefully
faster (due to proper collection port) on that platform.

Also hack to fix Eigen alignment shouldn't be needed anymore.

Also on platforms which have got broken TR1 collections it's better to define
CERES_NO_TR1 instead of using Boost hacks. Made changes to Scons and CMake,
but can not check if this indeed works since i don't have OSX here.
2012-09-16 12:24:37 +00:00
Sergey Sharybin
d066ce9533 Ceres: remove debug-only code from bundling script, also move osx workaround to template 2012-09-16 12:23:00 +00:00
Brecht Van Lommel
becd442a36 Fix libmv build on OS X with 10.5 SDK. The tr1::unordered_map implementation
is broken in this SDK, now it uses the boost implementation instead.
2012-09-11 11:54:10 +00:00
Sergey Sharybin
cad8609172 Code cleanup: silence some -Wnarrowing warnings from C++11 2012-08-01 15:02:09 +00:00
Daniel Genrich
24a00f14af Fix compile errors on VC++ 2012 RC1.
Note: Compile still fails during ceres compile (namespace tr1 problems).
2012-07-27 18:18:13 +00:00
Sergey Sharybin
554107b6a1 Disable fixed-sized specializations for schur solver
As far as i remember Keir, this should be safe for our usages of ceres
and it should save noticeable amount of time and used memory when
compiling blender with libmv support.

Quick tests with tracking went smooth after this.
2012-06-14 13:33:37 +00:00
Sergey Sharybin
552887251f Masking support for motion tracks
Added option to use Grease Pencil datablock as a mask for pattern
when doing motion tracking. Option could be found in Tracking Settings
panel.

All strokes would be rasterized separately from each other and every
stroke is treating as a closed spline.

Also added option to apply a mask on track preview which is situated
just after B/B/W channel button under track preview.
2012-06-12 11:13:53 +00:00
Antony Riakiotakis
5f1eec564f Fix compilation of new tracker for MinGW/MinGW64 2012-06-11 13:00:35 +00:00
Sergey Sharybin
6ab087ff99 Scale search area when doing planar tracking
Helps keeping features tracked when there's large scale happens
without need to manually re-adjust search area.

Currently using factor of pattern's boundbox scale, but probably
could be done in more accurate way?
2012-06-11 11:40:54 +00:00
Guillermo S. Romero
379cf37b38 SVN maintenance. 2012-06-11 02:29:25 +00:00
Sergey Sharybin
84b734a4df Commit patch from Stephan Kassemeyer sent to ML
This patch aims to solve unaligned operation assert
happens in Eigen library.

This is short-term solution which in fact shall be reverted
as soon as real solution would be added to Ceres. Meanwhile
this should be acceptable to have for a while.
2012-06-10 15:28:29 +00:00
Sergey Sharybin
25bb441301 Planar tracking support for motion tracking
===========================================

Major list of changes done in tomato branch:

- Add a planar tracking implementation to libmv
  This adds a new planar tracking implementation to libmv. The
  tracker is based on Ceres[1], the new nonlinear minimizer that
  myself and Sameer released from Google as open source. Since
  the motion model is more involved, the interface is
  different than the RegionTracker interface used previously
  in Blender.

  The start of a C API in libmv-capi.{cpp,h} is also included.

- Migrate from pat_{min,max} for markers to 4 corners representation

  Convert markers in the movie clip editor / 2D tracker from using
  pat_min and pat_max notation to using the a more general, 4-corner
  representation.

  There is still considerable porting work to do; in particular
  sliding from preview widget does not work correct for rotated
  markers.

  All other areas should be ported to new representation:

  * Added support of sliding individual corners. LMB slide + Ctrl
    would scale the whole pattern
  * S would scale the whole marker, S-S would scale pattern only
  * Added support of marker's rotation which is currently rotates
    only patterns around their centers or all markers around median,

    Rotation or other non-translation/scaling transformation of search
    area doesn't make sense.

  * Track Preview widget would display transformed pattern which
    libmv actually operates with.

- "Efficient Second-order Minimization" for the planar tracker

  This implements the "Efficient Second-order Minimization"
  scheme, as supported by the existing translation tracker.
  This increases the amount of per-iteration work, but
  decreases the number of iterations required to converge and
  also increases the size of the basin of attraction for the
  optimization.

- Remove the use of the legacy RegionTracker API from Blender,
  and replaces it with the new TrackRegion API. This also
  adds several features to the planar tracker in libmv:

  * Do a brute-force initialization of tracking similar to "Hybrid"
    mode in the stable release, but using all floats. This is slower
    but more accurate. It is still necessary to evaluate if the
    performance loss is worth it. In particular, this change is
    necessary to support high bit depth imagery.

  * Add support for masks over the search window. This is a step
    towards supporting user-defined tracker masks. The tracker masks
    will make it easy for users to make a mask for e.g. a ball.

    Not exposed into interface yet/

  * Add Pearson product moment correlation coefficient checking (aka
    "Correlation" in the UI. This causes tracking failure if the
    tracked patch is not linearly related to the template.

  * Add support for warping a few points in addition to the supplied
    points. This is useful because the tracking code deliberately
    does not expose the underlying warp representation. Instead,
    warps are specified in an aparametric way via the correspondences.

- Replace the old style tracker configuration panel with the
  new planar tracking panel. From a users perspective, this means:

  * The old "tracking algorithm" picker is gone. There is only 1
    algorithm now. We may revisit this later, but I would much
    prefer to have only 1 algorithm. So far no optimization work
    has been done so the speed is not there yet.

  * There is now a dropdown to select the motion model. Choices:

        * Translation
        * Translation, rotation
        * Translation, scale
        * Translation, rotation, scale
        * Affine
        * Perspective

  * The old "Hybrid" mode is gone; instead there is a toggle to
    enable or disable translation-only tracker initialization. This
    is the equivalent of the hyrbid mode before, but rewritten to work
    with the new planar tracking modes.

  * The pyramid levels setting is gone. At a future date, the planar
    tracker will decide to use pyramids or not automatically. The
    pyramid setting was ultimately a mistake; with the brute force
    initialization it is unnecessary.

- Add light-normalized tracking

  Added the ability to normalize patterns by their average value while
  tracking, to make them invariant to global illumination changes.

Additional details could be found at wiki page [2]

  [1] http://code.google.com/p/ceres-solver
  [2] http://wiki.blender.org/index.php/Dev:Ref/Release_Notes/2.64/Motion_Tracker
2012-06-10 15:28:19 +00:00
Sergey Sharybin
59ef51aa27 Initial Ceres integration into Blender
Currently only put sources of Ceres library into extern/libmv/third_party and
setup CMake and SCons building systems.

Integration details:

- Even CMake build files are not re-used from Ceres's trunk: they're using some
  automatic stuff detection like glog, pthreads, protobuf and so and it's not
  so clear how to re-use that files without modifications.
  And IMO it's easier if build files are getting re-generated automatically to
  match Blender-specific setup rather than keeping changes made locally in
  Blender in sync when re-bundling Ceres library. Especially in case when it's
  already needed to support SCons build system.
- Integrated only actual sources, all tests were stripped. Probably it'll be nice
  to have them, but they'll need clear integration with current module test stuff
  in Blender.
- Suitesparse was disabled. It'll help a lot having it, but there are some difficulties
  making cholmod working fine on windows. Would be added in future
- collections_port.cc was also stripped. It's not used by Ceres's upstream and
  it gives compilation error (undefined uint32 -- looks like namespace issue).
- Currently all schur eliminators are included. Not sure if it makes sense,
  also not sure if it makes sense having them switchable on and off -- IMO better
  to have single configuration which works and does not require special tweaks
  after everything was set up.

To bundle updated version of Ceres:
- Go to extern/libmv/third_party/ceres folder
- Run ./bundle.sh

This will checkout fresh Ceres snapshot of Windows branch (which is currently
most interesting from integration into Blender POV), apply all patches listed
in patches/series and copy needed files into Blender's working copy. This will
also re-generate CMake/SCons build rules.

If you'll need extra files from Ceres repository which are not present in
Blender, you'll need to copy them manually and then run ./mkfiles.sh from
extern/libmv/third_party/ceres folder which will update list of files used
by Blender.

Thanks to Leir Mierle and Sameer Agarwal (and all others who helped developing
Ceres) this library and thanks to Keir Mierle with help integrating it into Blender!
2012-06-10 15:27:41 +00:00
Sergey Sharybin
4bf0e61de2 Style cleanup: use 2 spaces for indentation in bundle scripts 2012-05-10 11:17:15 +00:00
Sergey Sharybin
cc5f18693f Carve and libmv bundling scripts: should work with svn checkout now 2012-05-10 11:08:25 +00:00
Sergey Sharybin
b73307471f Synchronize libmv with changes in git branch 2012-05-10 10:39:28 +00:00
Sergey Sharybin
e6a022816c Remove unneeded and unused patch for libmv 2012-05-09 12:30:15 +00:00
Keir Mierle
f33080532c Enhance logging in libmv's trackers.
Cleanups in brute_region_tracker.cc.
2012-05-08 23:13:53 +00:00
Sergey Sharybin
51a4188105 Camera tracking: support of tripod motion solving
Expose option into interface to use modal solver which currently
supports only tripod motion.

This solver requires two tracks at least to reconstruct motion.
Using more tracks aren't improving solution in general, just adds
instability into solution and slows down things a lot.

Refirement of camera intrinsics was disabled due to it's not only
refines camera intrinsics but also adjusts camera position which
isn't necessary here

To use this solver just activate "Tripod Motion" checkbox in
solver panel.

Merged from tomato: svn merge ^/branches/soc-2011-tomato -r45622:45624 -r46036:46037

P.S. Quite experimental yet, requires more checking and probably
tweaks to prevent camera jumps when tracks apperars/disappears
from the screen.
2012-04-28 14:54:45 +00:00
Antony Riakiotakis
4782522379 Add libMV and Scons support for MinGW-w64, patches by Caleb Joseph with slight modifications.
Thanks!
2012-04-24 12:57:58 +00:00
Sergey Sharybin
f9d9b4635d Camera tracking: support of tripod motion solving
Expose option into interface to use modal solver which currently
supports only tripod motion.

This solver requires two tracks at least to reconstruct motion.
Using more tracks aren't improving solution in general, just adds
instability into solution and slows down things a lot.

Refirement of camera intrinsics is supported by this solver.

To use this solver just activate "Tripod Motion" checkbox in
solver panel.
2012-04-14 12:02:47 +00:00
Sergey Sharybin
efb9b6c1c3 libmv: bundle new upstream version of libmv from own branch
Added modal solver module which is needed for tripod solving.
For details of this solver read changelog of libmv.
2012-04-14 12:02:39 +00:00
Sergey Sharybin
bfca79a657 Merging r44227 through r45619 from trunk into soc-2011-tomato 2012-04-14 10:46:47 +00:00
Sergey Sharybin
e6c45cc1de libmv: bundle new upstream version from own branch with rigid registration implementation
Currently not used in blender code but is needed for some current work.
2012-04-12 11:37:51 +00:00
Sergey Sharybin
ce95b0be1e libmv: bundle new upstream version from own branch which should support
compilation of glog on hurd platform.
2012-04-11 13:51:37 +00:00
Sergey Sharybin
81e3db364d Camera tracking refactoring:
- Deduplicate patetrn sampling used in esm and lmicklt trackers and
  move SamplePattern to image/sample.h - Move computation of Pearson
  product-moment correlation into own function in new file image/correlation.h
  so all trackers can use it to check final correlation.
- Remove SAD tracker. It's almost the same as brute tracker, with only two differences:
  1. It does brute search of affine transformation which in some cases helps to track
     rotating features 2. It didn't use common tracker api which probably gave some
     speed advantage, but lead to a real headache to use it together with other
     trackers leading to duplicated code in blender side.
- Switch blenedr to use brute tracker instead of sad tracker which tracking made
  source code much more simple to follow.
2012-03-30 10:37:39 +00:00