Commit Graph

814 Commits

Author SHA1 Message Date
Sergey Sharybin
cf5e979fb4 Motion tracking: automatic keyframe selection
Implements an automatic keyframe selection algorithm which uses
couple of approaches to find out best keyframes candidates:

- First, slightly modifier Pollefeys's criteria is used, which
  limits correspondence ration from 80% to 100%. This allows to
  reject keyframe candidate early without doing heavy math in
  cases there're not much common features with first keyframe.

- Second step is based on Geometric Robust Information Criteria
  (aka GRIC), which checks whether features motion between
  candidate keyframes is better defined by homography or
  fundamental matrices.

  To be a good keyframe candidate, fundamental matrix need to
  define motion better than homography (in this case F-GRIC will
  be smaller than H-GRIC).

  This two criteria are well described in this paper:
  http://www.cs.ait.ac.th/~mdailey/papers/Tahir-KeyFrame.pdf

- Final step is based on estimating reconstruction error of
  a full-scene solution using candidate keyframes. This part
  is based on the following paper:

  ftp://ftp.tnt.uni-hannover.de/pub/papers/2004/ECCV2004-TTHBAW.pdf

  This step requires reconstruction using candidate keyframes
  and obtaining covariance matrix of 3D points positions.
  Reconstruction was done pretty much straightforward using
  other simple pipeline routines, and for covariance estimation
  pseudo-inverse of Hessian is used, which is in this case
  (J^T * J)+, where + denotes pseudo-inverse.

  Jacobian matrix is estimating using Ceres evaluate API.

  This is also crucial to get rid of possible gauge ambiguity,
  which is in our case made by zero-ing 7 (by gauge freedoms
  number) eigen values in pseudo-inverse.

  There're still room for improving and optimizing the code,
  but we need some point to start with anyway :)

  Thanks to Keir Mierle and Sameer Agarwal who assisted a lot
  to make this feature working.
2013-05-30 09:03:49 +00:00
Campbell Barton
225c5fee6b move BLO_sys_types.h -> BLI_sys_types.h (it had nothing todo with loading)
remove MEM_sys_types.h which was a duplicate.
2013-05-28 19:35:26 +00:00
Campbell Barton
8982439383 quiet warnings from r56825
- using vars before checking they are defined
- /* within comment
2013-05-16 03:55:47 +00:00
Jürgen Herrmann
8a89d27b87 Libmv internal compiler error workaround for VC2012.
Will be reverted as soon as the x64 compiler is fixed.
For now it shouldn't have an impact on tracking performance. My test have shown no significant speed difference to official VC2008 build of 2.67.
2013-05-15 17:00:53 +00:00
Campbell Barton
ff1a587e1c update libmv stub. 2013-05-14 03:06:58 +00:00
Sergey Sharybin
d4c6ac9a60 Cleanup and small improvements to libmv
- Added const modifiers where it makes sense and
  helps keep code safe.
- Reshuffled argument to match <inputs>,<outputs>
  convention on parameters.
- Pass values to ApplyRadialDistortionCameraIntrinsics
  by a constant reference.
  This will save lots of CPU ticks passing relatively
  heavy jet objects to this function when running
  bundle adjustment.
2013-05-13 14:39:06 +00:00
Sergey Sharybin
4e5541a9a6 Headers cleanup. 2013-05-13 09:51:36 +00:00
Sergey Sharybin
91b659d174 Forgot this in one of previous commits
Idea here is to be able to have all files opened in IDE
and not confuse it by the same function implemented in
multiple files.
2013-05-12 22:40:12 +00:00
Sergey Sharybin
4dba8307f2 Compilation fix for recent commit. 2013-05-12 22:30:34 +00:00
Sergey Sharybin
32faec1a53 Remplace bunch of annoying ifdefs in tracking.c with a libmv-capi_stub.cc
Makes code in tracking.cc much easier to understand and modify,
without worring to breck compulation with Libmv disabled.

It is still possible compilation will break due to libmv-capi
changes, but that's not happening so much often.
2013-05-12 22:17:37 +00:00
Sergey Sharybin
5637b0d39b Update bundled version of libmv
- Ensures fix for msvc2012 is applying correct.
- Some code cleanup to match libmv's code style.
- Do not include points which were intersect
  behind the camera to a reconstruction.
- Includes changes needed for keyframe selection.
2013-05-12 17:06:00 +00:00
Sergey Sharybin
beb73831f6 Documentation for functions inside tracking.c
Additional changes:

- Cleaned up sources to reduce mess in some
  big functions.
- Removed unused function from libmv c-api.
- Made functions naming more consistent.
- Use bool for internal stuff in tracking.c.

Shall be no functional changes :)
2013-05-12 16:04:08 +00:00
Brecht Van Lommel
309db8032c Fix libmv build with visual studio 2012.
Patch #35158 by Jurgen Herrmann.
2013-05-11 13:10:39 +00:00
Sergey Sharybin
2cf1f1f4d6 Left extra logging print by accident. 2013-05-10 07:26:55 +00:00
Sergey Sharybin
4648ec3e82 Remove check for zero focal length in BA cost functor
This check is actually redundant, because empty intrinsics
will have focal length of 1.0, which means original comment
about BundleIntrinsics was not truth.

It is possible that external user will send focal length of
zero to be refined, but blender prevents this from happening.
2013-05-10 06:48:47 +00:00
Sergey Sharybin
3a309a8313 Synchronize changes between bunded libmv and own libmv branch. 2013-05-10 06:26:01 +00:00
Sergey Sharybin
ed131e67c4 Add check for points behind camera in euclidan BA cost functor
In cases keyframes are no so good, algebraic two frames construction
could produce result, for which more aggressive Ceres-based BA code
will fall to a solution for which points goes behind the camera,
which is not so nice.

Seems in newer Ceres returning false from cost functor wouldn't
abort solution, but will restrict solver from moving points behind
the camera.

Works fine in own tests, but requires more tests.
2013-05-09 16:38:58 +00:00
Sergey Sharybin
4f5f97254c Reconstructed scene scale ambiguity improvement
Made it so reconstructed scene always scaled in a way
that variance of camera centers is unity.

This solves "issues" when different keyframes will
give the same reprojection error but will give scenes
with different.scale, which could easily have been
considered as a bad keyframe combination.

This change is essential for automatic keyframe
selection algorithm to work reliable for user.
2013-05-09 16:38:43 +00:00
Sergej Reich
424e8b69f1 bullet: Don't use sse in api for windows.
Remove stray BT_USE_SSE_IN_API definitions.
Was causing problems especially for 32 bit windows.

It's not quite clear why they were added in the first place since
this should be defined in btScalar.h, needs further investigation.

Thanks to Francisco De La Cruz (xercesblue) for looking into this.

Should fix [#35071] Bullet Convex Hull Crashes on Win32 with SSE
2013-05-06 22:53:11 +00:00
Sergej Reich
c80ff61d40 bullet: Fix avoiding collision response between static/kinematic objects
Sent patch upstream.

Fixes [#35115] Character physics type fails collision with static type with an action on 2.67 rc
2013-04-28 21:40:54 +00:00
Sergey Sharybin
d2f61b36f9 Revert 56319, misunderstood API
This was completely skipping BA step when point
goes behind the camera.
2013-04-26 18:25:49 +00:00
Sergey Sharybin
126ca24dbf Fix for BA possible move bundles behind the camera
In some cases (was noticed on not good enough keyframe
pair) bundle adjuster could have moved bundles behind
the camera.

This could indeed lead to lower rewprojection error but
this is just pointless thing to do.

Now added check to residuals functor which will return
false to Ceres in cases point moved behind the camera
to prevent such issues.
2013-04-26 15:43:20 +00:00
Sergey Sharybin
d05f5da111 Update Ceres to current upstream version
This brings a fixes for threading issue in BLAS
making BA step more robust (there were some in-detemrinacy
caused by this threading issue).

Also brings some optimizations, which does not directly
affect on blender.
2013-04-22 09:25:37 +00:00
Sergey Sharybin
79ca1bd004 Make it so FATAL messages from libmv are print to the console
even when --debug-libmv is not passed via command line.
2013-04-15 10:02:33 +00:00
Sergey Sharybin
8cca2fec82 Fix for bundle adjusting with motion restricted
This commit bundles new libmv version from own branch
which brings fix for wrong parameter block used for
modal solver parameterization.

Fixes #34985: Crash with Motion tracker (Tripod Motion)
2013-04-14 23:43:00 +00:00
Sergey Sharybin
d2b55d1171 Bundle adjustment improvements
- Get rid of rotation matrix parameterization,
  use angle-axis instead.

  Also Joined rotation and translation into a
  single parameter block.

  This made minimization go significantly faster,
  like 1.3x times in average.

- Fix first camera when bundling. This is to
  address orientation ambiguity.

  Reconstruction result could still vary in
  size, but that's another issue to be addressed
  later.

Additional change:

Split EuclideanBundleCommonIntrinsics into
smaller functions, so it's now a bit easier
to follow.
2013-04-08 17:05:52 +00:00
Sergey Sharybin
8e8823be12 Update ceres to current upstream version
Brings fixes for BLAS.
2013-04-08 17:05:48 +00:00
Sergey Sharybin
f62d2669de Revert change made to bilinear sampler in libmv
This made preview working but that broke internals
of tracking.

Namely, BlurredImageAndDerivativesChannels is giving
much more blurred image because it was assuming pixel
center is an integer position.

Guess other parts of libmv used to suffer because of
this issue.

Now pixel centering happens in blender side, and
libmv assumes integer position is a pixel center.
2013-04-06 14:47:45 +00:00
Sergey Sharybin
898ba93a12 Update libmv to current upstream version
- Solves some strict compilation warning
- Style/code cleanup
2013-04-05 09:23:20 +00:00
Sergey Sharybin
43b61fb8bd Bundle current master of ceres-solver
Thins brings up some speed improvements:

SPARSE_SCHUR is approx 1.3-1.5x times faster
ITERATIVE_SCHUR is approx 1.2x times faster

For blender this means camera solution go a bit
faster now. Would not have affect on tracking
speed.
2013-04-05 09:22:54 +00:00
Campbell Barton
1777a69818 misc minor edits.
- pass string size to BLI_timestr() to avoid possible buffer overrun.
- quiet warning for mingw.
- include guards for windows utf conversion funcs.
- fix for mistage in edge-angle-selection check.
- some style cleanup.
2013-03-29 06:25:22 +00:00
Sergey Sharybin
729b76eb79 Update ceres to current git version.
Mainly to support msvc2010, bit also includes some minor fixes.
2013-03-21 18:07:03 +00:00
Sergey Sharybin
8a7ce9c924 Fix #34707: Blender crash on enabling of boolean modifier
Stupid mistake by my own with recent Carve update which
undid fix for MSVC STL library.
2013-03-21 08:47:18 +00:00
Campbell Barton
3966722057 code cleanup: misc warnings/style 2013-03-21 02:58:21 +00:00
Sergey Sharybin
6dc4ea34e4 Multi-threaded frame calculation for movie clip proxies
This commit implements multi-threaded calculation of frames
when building proxies. Both scaling and undistortion steps
are now threaded.

Frames and proxy resolution are still handled one-by-one,
saving files after every single step. So if HDD is not so
fast, this commit could have not so much benefit.

Internal changes:

- Added IMB_scaleImBuf_threaded which scales given image
  buffer in multiple threads and uses bilinear filtering.

- libmv's camera intrinsics now have SetThreads() method
  which is used to specify how many OpenMP threads to use
  for buffer distortion/undistortion.

  And yeah, this code is using OpenMP for threading.

- Reshuffled a bit libmv-capi calls and added function
  BKE_tracking_distortion_set_threads to specify number
  of threads used by intrinscis.
2013-03-15 11:59:46 +00:00
Irie Shinsuke
5792e77239 Patch [#34373] Use i18n monospace font in Text editor and Python console
This patch allows Blender to display i18n monospace font in the text
editor and the Python interactive console. Wide characters that occupy
multiple columns such as CJK characters can be displayed correctly.
Furthermore, wrapping, selection, suggestion, cursor drawing, and
syntax highlighting should work.

Also fixes a bug [#34543]: In Text Editor false color in comment on cyrillic

To estimate how many columns each character occupies, this patch uses
wcwidth.c written by Markus Kuhn and distributed under MIT-style license:

  http://www.cl.cam.ac.uk/~mgk25/ucs/wcwidth.c

wcwidth.c is stored in extern/wcwidth and used as a static library.

This patch adds new API to blenfont, blenlib and blenkernel:

BLF_get_unifont_mono()
BLF_free_unifont_mono()
BLF_draw_mono()
BLI_wcwidth()
BLI_wcswidth()
BLI_str_utf8_char_width()
BLI_str_utf8_char_width_safe()
txt_utf8_offset_to_column()
txt_utf8_column_to_offset()
2013-03-12 07:25:53 +00:00
Jens Verwiebe
373de9e936 OSX/gcc-4.6: workaround a compilerbug, use apple-gcc instead 2013-03-07 22:12:23 +00:00
Sergej Reich
643b0be4cb bullet: Update to current svn, r2636
Apply patches in patches directory, remove patches that were applied
upstream.
If you made changes without adding a patch, please check.

Fixes [#32233] exporting bullet format results in corrupt files.
2013-03-07 17:53:16 +00:00
Sergey Sharybin
f81b594790 Switch from DENSE_NORMAL_CHOLESKY to DENSE_QR
DENSE_QR is better behaved numerically and after recent
changes from Sameer there's no big difference in speed.
2013-03-05 09:38:50 +00:00
Sergey Sharybin
3a0d62f4f4 Update Ceres to 1.5RC3
It brings optimization of DENSE_QR and DENSE_SCHUR solvers.
2013-03-05 09:38:43 +00:00
Sergey Sharybin
9da36d3ab1 Updates to libmv's bundle.sh to make sure libmv upstream
is copying properly to our sources.
2013-03-01 11:52:38 +00:00
Sergey Sharybin
1a7ab1da09 Hrm, gcc became broken after recent commit.
Hope now gcc and 32bit msvc would both work.
2013-03-01 08:56:04 +00:00
Sergey Sharybin
a2027237ed Pass data to modal reprojection cost functor by reference
Seems it solves alignment error reported by 32bit MSVC.
2013-03-01 08:20:13 +00:00
Sergey Sharybin
aada0e4a29 Header cleanup in libmv c-api 2013-02-28 14:25:40 +00:00
Sergey Sharybin
d68e766c8c This lines are also not so much useful for now. 2013-02-28 14:25:33 +00:00
Sergey Sharybin
3e320a67e3 Remove unused rigid registration code
There're some features planned which would
require rigid registration, but this code
would need to be re-done anyway to use new
minimizer and solving some issues with ICP
algorithm there.
2013-02-28 14:24:52 +00:00
Sergey Sharybin
52f34f017d Modal (aka tripod) solver rework
Several major things are done in this commit:

- First of all, logic of modal solver was changed.
  We do not rely on only minimizer to take care of
  guessing rotation for frame, but we're using
  analytical rotation computation for point clouds
  to obtain initial rotation.

  Then this rotation is being refined using Ceres
  minimizer and now instead of minimizing average
  distance between points of point of two clouds,
  minimization of reprojection error of point
  cloud onto frame happens.

  This gives quite a bit of precision improvement.

- Second bigger improvement here is using bundle
  adjustment for a result of first step when we're
  only estimating rotation between neighbor images
  and reprojecting markers.

  This averages error across the image sequence
  avoiding error accumulation. Also, this will
  tweak bundles themselves a bit for better match.

- And last bigger improvement here is support of
  camera intrinsics refirenment.

  This allowed to significantly improve solution
  for real-life footage and results after such
  refining are much more usable than it were before.

Thanks to Keir for the help and code review.
2013-02-28 14:24:42 +00:00
Sergey Sharybin
2a5ed5293d 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.

Now behavior would be:
- running `./blender --debug-libmv` will print all the
  debug messages
- running `./blender --debug-libmv --verbose 0` will
  print only debug messages from solvers, recosntruction
  and so, but will bypass final reprojection bunch of
  messages
- running `./blender --debug-lib,v --verbose 1` will
  include final reprojection messages.
2013-02-28 14:24:25 +00:00
Sergey Sharybin
9bfe99281c Move radial distortion code to own templated function
This shall not lead to any functional changes, just
avoids radial distortion code duplicated in camera
intrinsics and bundling code.

For fancier bundle adjustment supprting different
distortion models this is not actually enough and
would need to make some bigger changes, but this
changes makes code a bit easier to maintain already.
2013-02-28 14:24:17 +00:00
Sergey Sharybin
1d20f2496a Use threaded cost function and jacobian computation
Also made it theraded linear solver, seems it makes
sense for iterative schur with inner iterations
enabled.

Use OpenMO's max therads called from bundler code
to detect how many threads to use. Could be changed
in a way that number of threads is passing in options
from blender side in the future.

Also removed redundant V3D definition from compiler's
flags.
2013-02-26 17:52:10 +00:00