Commit Graph

102 Commits

Author SHA1 Message Date
Campbell Barton e6cf74515f Cleanup: disable clang-format for 'intern/libmv/third_party' headers 2021-03-22 14:35:20 +11:00
Sergey Sharybin 1b29e84c18 Fix Libmv tests after recent fix
Forgot to update regression test to the changed API.
2021-03-15 16:11:37 +01:00
Sergey Sharybin c82f65b096 Fix T86262: Tracking backwards fails after gap in track
The issue was caused by a prediction algorithm detecting tracking the
wrong way. Solved by passing tracking direction explicitly, so that
prediction will always happen correctly regardless of the state of the
Tracks context.
2021-03-15 15:55:09 +01:00
Sergey Sharybin 618c4b9daf Refactor Libmv C-API motion model conversion
Mode to an own utility function and guard missing enumerator values
with a LOG(FATAL).
2021-03-15 15:55:09 +01:00
Sergey Sharybin d8e1750e34 Cleanup: Spelling in Libmv comments 2021-03-15 15:55:09 +01:00
Sergey Sharybin 0dd9a4a576 Cleanup: Libmv, clang-format
Is based on Google style which was used in the Libmv project before,
but is now consistently applied for the sources of the library itself
and to C-API. With some time C-API will likely be removed, and it
makes it easier to make it follow Libmv style, hence the diversion
from Blender's style.

There are quite some exceptions (clang-format off) in the code around
Eigen matrix initialization. It is rather annoying, and there could be
some neat way to make initialization readable without such exception.

Could be some places where loss of readability in matrix initialization
got lost as the change is quite big. If this has happened it is easier
to address readability once actually working on the code.

This change allowed to spot some missing header guards, so that's nice.

Doing it in bundled version, as the upstream library needs to have some
of the recent development ported over from bundle to upstream.

There should be no functional changes.
2021-03-05 15:05:08 +01:00
Sergey Sharybin aeb7bc5beb GLog: Lower default logging severity to INFO
Before this change messages of ERROR and above were printed.
This change makes it so LOG(INFO), LOG(WARNING), LOG(ERROR)
and LOG(FATAL) will be printed to the console by default
(without --debug-libmv and --debug-cycles).

On a user level nothing is changed because neither INFO nor
WARNING severity are used in our codebase. For developers this
change allows to use LOG(INFO) to print relevant for debugging
information. Bering able to see WARNING messages is also nice,
since those are not related to debugging, but are about some
detected "bad" state.

After this change the LOG(INFO) is really treated as a printf.
Why not to use printf to begin with? Because it is often more
annoying to print non-scalar types. Why not to use cout? Just
a convenience, so that all type of logging is handled in the
same way. When one is familiar with Glog used in the area, it
is easy to use same utilities during development. Also, it is
easy to change LOG(INFO) to VLOG(2) when development is done
and one wants to keep the log print but make it only appear
when using special verbosity flags.

The initial reason why default severity was set to maximum
possible value is because of misuse of VLOG with verbosity
level 0, which is the same as LOG(INFO). This is also why
back in the days --debug-libmv was introduced.

Now there is some redundancy between --debug-libmv, --debug-cyles
and --verbose, but changes in their meaning will cause user
level side effects.

Differential Revision: https://developer.blender.org/D10513
2021-03-01 16:56:34 +01:00
Sergey Sharybin ea95ea644a Libmv: Avoid use of LOG(INFO) in solver
Usage of LOG(INFO) actually went against own guidelines in the
logging.h: the INFO is for messages which are to be printed
regardless of debug/verbosity settings.
2021-03-01 16:54:14 +01:00
Campbell Barton 17e1e2bfd8 Cleanup: correct spelling in comments 2021-02-05 16:23:34 +11:00
Sergey Sharybin 4c92fb6715 Libmv: Tweak default logging verbosity level
Log to verbosity level 1 rather than INFO severity.

Avoids a lot of overhead coming from construction of the INFO stream
and improves performance and threadability of code which uses logging.

This makes tracking of 250 frames of a track of default settings to
drop down from 0.6sec to 0.4sec.
2020-12-01 14:55:22 +01:00
Sergey Sharybin c21265b29e Libmv: Cleanup, remove unused logging macros
Unused and was not entirely happy with such short abbreviations.
2020-12-01 14:46:35 +01:00
Sergey Sharybin 057c15b549 Libmv: Add threading primitives
Allows to use mutex, scoped_lock, and conditional_variable from within
the libmv namespace.

Implementation is coming from C++11. Other configurations are easy to
implement, but currently C++11 is the way to go.
2020-11-30 12:12:39 +01:00
Sergey Sharybin 0f0c982ff4 Libmv: Add build configuration header
Allows to easily access build platform information, such as bitness,
compiler, supported C++ version and so on.
2020-11-30 12:12:39 +01:00
Sergey Sharybin d3dd61aab3 Libmv: add missing files to bundler
Bundler wouldn't be able to pull changes form upstream until all the
changes are upstreamed, but is better to have information consistent.
2020-11-30 12:12:39 +01:00
Sergey Sharybin 92083772e7 Libmv: Fix warning about unused parameter in Ceres
Ceres is an external library, so consider it a system header which
makes it so all strict flags are properly ignored for them.
2020-11-09 12:12:00 +01:00
Campbell Barton 605425c006 Cleanup: doxygen comments 2020-11-06 14:35:38 +11:00
Campbell Barton 7cb20d841d Cleanup: follow our code style for float literals 2020-11-06 12:32:54 +11:00
Ivan Perevala cf78053027 Libmv: Fix clang inconsistent-missing-override warnings.
Reviewed By: sergey, ankitm

Differential Revision: https://developer.blender.org/D9377
2020-10-29 10:19:50 +01:00
Sergey Sharybin 0269f0c574 Tracking: Simplify configuration of intrinsics to refine
Previously, only predefined and limited set of intrinsics combinations
could have been refined. This was caused by a bundle adjustment library
used in the early days of the solver.

Now it is possible to fully customize which intrinsics are to be refined
during camera solving. Internally solver supports per-parameter settings
but in the interface they are grouped as following:

* Focal length
* Optical center
* Radial distortion coefficients (which includes k1, k2, k3, k4)
* Tangential distortion coefficients (which includes p1, p2)

Differential Revision: https://developer.blender.org/D9294
2020-10-28 10:21:07 +01:00
Sergey Sharybin 1b1f46a98c Libmv: Fix typo in packed intrinsics
Was using doing an implicit cast of floating point value to boolean.
Was not noticed before because the boolean value was never never used.
2020-10-28 10:13:08 +01:00
Sergey Sharybin 360282cf1f Libmv: Refactor camera intrinsics parameter block
Use the newly introduced packed intrinsics, which allows to remove
code which was initializing parameters block based on distortion
model type.

Now such initialization is done by a particular implementation of
a distortion model.

Differential Revision: https://developer.blender.org/D9192
2020-10-20 15:02:50 +02:00
Sergey Sharybin 549841bbc0 Libmv: Add generic class for packed intrinsics
This is a common class which can be used in all sort of minimization
problems which needs camera intrinsics as a parameter block.

Currently unused, but will replace a lot of hard-coded logic in the
bundle adjustment code.
2020-10-20 15:02:50 +02:00
Sergey Sharybin 151173fefe Libmv: Add array<type, size> to libmv namespace 2020-10-20 15:02:50 +02:00
Sebastian Parborg 711b55b527 Fix libmv test on windows
There is no point in testing std::vector capacity as it can differ
between std implementations.
2020-10-20 14:46:48 +02:00
Harley Acheson 84ef3b80de Spelling: Miscellaneous
Corrects 34 miscellaneous misspelled words.

Differential Revision: https://developer.blender.org/D9248

Reviewed by Campbell Barton
2020-10-19 09:11:00 -07:00
Harley Acheson 3a7fd309fc Spelling: It's Versus Its
Corrects incorrect usage of contraction for 'it is', when possessive 'its' was required.

Differential Revision: https://developer.blender.org/D9250

Reviewed by Campbell Barton
2020-10-19 08:12:33 -07:00
Sebastian Parborg e3c76f7937 Fix libmv eigen alignment issues when compiling with AVX support
There would be eigen alignment issues with the custom libmv vector
class when compiling with AVX optimizations. This would lead to
segfaults.

Simply use the std::vector base class as suggested by the old TODO in
the class header.

Reviewed By: Sergey

Differential Revision: http://developer.blender.org/D8968
2020-10-19 13:06:38 +02:00
Sergey Sharybin c4c8d855c6 Libmv: Remove array access from camera intrinsics
That was a suboptimal decision from back in the days, which ended up
being problematic. It is no longer used, so remove it from API making
it so new code does not depend on this weak concept.
2020-10-12 15:12:17 +02:00
Sergey Sharybin ff5e3d6834 Libmv: Fix wrong packing order of intrinsics for BA step
The order got broken when Brown distortion model has been added.
Made it so the indexing of parameters is strictly defined in the
parameter block, matching how parameters are used in the cost
function.

There is some duplication going on accessing parameters. This can
be refactored in the future, by either moving common parts packing
and cost function to an utility function in bundle.cc.
Alternatively, can introduce a public PackedIntrinsics class which
will contain a continuous block of parameters, and each of the
camera models will have API to be initialized from packed form and
to create this packed form.

The benefit of this approach over alternative solutions previously
made in the master branch or suggested in D9116 is that the specific
implementation of BA does not dictate the way how public classes need
to be organized. It is API which needs to define how implementation
goes, not the other way around.

Thanks Bastien and Ivan for the investigation!
2020-10-12 15:12:17 +02:00
Sergey Sharybin 86138d88f6 Revert "Fix critical lens distortion bug in libmv after rB3a7d62cd1f5e."
This reverts commit 7e836bde11.

Reverting the incomplete workaround, due to the following reasoning:

- There should be no dependency between CameraIntrinsics and the bundler
  code. This violates intended abstraction of the intrinsics class.

- The fix was not complete, or wrong. Even in the world where there is
  a requirement to the parameters storage size this should have applied
  to all distortion models, including Divisions, Nuke.

Proper fix will be committed next.
2020-10-12 15:12:17 +02:00
Sergey Sharybin df5b65811e Libmv: Fix memory leak in modal solver
The leak was happening when problem did not have any parameters blocks
defined. This happens, for example, if there are no 3D points at all,
or when all markers are set to 0 weight.

Was noticeable in libmv_modal_solver_test when building with LSAN
enabled.
2020-10-12 15:12:17 +02:00
Sergey Sharybin 590220e451 Libmv: Cleanup, spelling in function name
Is a local function, not affecting API.
2020-10-12 15:12:17 +02:00
Bastien Montagne 7e836bde11 Fix critical lens distortion bug in libmv after rB3a7d62cd1f5e.
Current libmv_modal_solver_test fails since rB3a7d62cd1f5e.

It appears that the issue is caused by the insertion of the new OFFSET_K4 parameter,
as, if camera intrinsics are not required to implement/use all of those deform
parameters, they absolutely have to keep order (values) matching those defined
in bundle.cc, otherwise `PackIntrinisicsIntoArray` and `UnpackIntrinsicsFromArray`
will mangle them around.
2020-10-05 11:47:32 +02:00
Ivan Perevala 3a7d62cd1f Tracking: Implement Brown-Conrady distortion model
Implemented Brown-Conrady lens distortion model with 4 radial and
2 tangential coefficients to improve compatibility with other software,
such as Agisoft Photoscan/Metashapes, 3DF Zephir, RealityCapture,
Bentley ContextCapture, Alisevision Meshroom(opensource).

Also older programs: Bundler, CPMVS.
In general terms, most photogrammetric software.

The new model is available under the distortion model menu in Lens
settings.

For tests and demos check the original patch.

Reviewed By: sergey

Differential Revision: https://developer.blender.org/D9037
2020-09-30 15:54:24 +02:00
Ivan 4c19dd523e Libmv: Fix NukeCameraIntrinsics copy constructor
Copy the appropriate parameter

Reviewed By: sergey

Differential Revision: https://developer.blender.org/D9014
2020-09-28 09:57:28 +02:00
Sybren A. Stüvel 56aa5b0d8c T73268: Link C/C++ unit tests into single executable
This commit introduces a new way to build unit tests. It is now possible
for each module to generate its own test library. The tests in these
libraries are then bundled into a single executable.

The test executable can be run with `ctest`. Even though the tests
reside in a single executable, they are still exposed as individual
tests to `ctest`, and thus can be selected via its `-R` argument.

Not yet ported tests still build & run as before.

The following rules apply:

- Test code should reside in the same directory as the code under test.
- Tests that target functionality in `somefile.{c,cc}` should reside in
  `somefile_test.cc`.
- The namespace for tests is the `tests` sub-namespace of the code under
  test. For example, tests for `blender::bke` should be in
  `blender::bke:tests`.
- The test files should be listed in the module's `CMakeLists.txt` in a
  `blender_add_test_lib()` call. See the `blenkernel` module for an
  example.

Reviewed By: brecht

Differential Revision: https://developer.blender.org/D7649
2020-07-16 12:58:49 +02:00
Johan Walles 80fe5e1b15 UI: Add units to motion tracking solve errors
The unit being "pixels".

Before this change the solve errors were unitless in the UI.

With this change in place, the UI is now clear on that the unit of the
reprojection errors is pixels (px).

Differential Revision: https://developer.blender.org/D8000
2020-07-07 11:22:12 +02:00
Campbell Barton 36d6aa428f Cleanup: spelling 2020-07-01 13:12:24 +10:00
Sergey Sharybin 31ae833811 Ceres: Update to the latest upstream version
Using latest master because of various compilation error fixes.

Brings a lot of recent development. From most interesting parts:

- New threading model.
- Tiny solver.
- Compatibility with C++17.
2020-06-19 12:02:21 +02:00
Sergey Sharybin 2b36cf3118 Libmv: Fix crash solving when having negative frames
Don't use linear array with frame as an index since it has the
following disadvantages:

- Requires every application to take care of frame remapping, which
  could be way more annoying than it sounds.

- Inefficient from memory point of view when solving part of a footage
  which is closer to the end of frame range.

Using map technically is slower from performance point of view, but
could not feel any difference as the actual computation is way more
complex than access of camera on individual frames.

Solves crash aspect of T72009
2020-05-15 14:59:25 +02:00
Sergey Sharybin 547f50b5e0 Libmv: Add map utility 2020-05-15 11:20:45 +02:00
Sergey Sharybin 6398892121 Libmv: Cleanup, spelling 2020-05-15 11:20:45 +02:00
Aaron Carlisle b4d50d3f07 Cleanup: Doxygen: fix markup warnings for links 2020-05-07 23:43:19 -04:00
Sergey Sharybin b7bcd0a87c Tracking: Implement Nuke/Natron distortion model
Neither Nuke nor Natron support OpenCV's radial distortion model
which makes it impossible to have any kind of interoperability.

The new model is available under the distortion model menu in Lens
settings.

Differential Revision: https://developer.blender.org/D7484
2020-04-29 16:39:30 +02:00
Sergey Sharybin 805c52b1fd Libmv: Cleanup, naming
Initial bundle adjustment only supported OpenCV's radial distortion
model, so the cost functor was called after it.

Nowadays it supports more than this single model, so naming was a bit
wrong and misleading.
2020-04-21 16:41:23 +02:00
Sergey Sharybin a02da85b55 Libmv: Cleanup, spelling and naming in bundle adjustment
Just more things which were discovered to be annoying on unclear when
adding more features to this code.
2020-04-21 12:25:45 +02:00
Sergey Sharybin 749181ff4d Libmv: Cleanup, spelling in comment 2020-04-20 17:26:45 +02:00
Sergey Sharybin e9c9e1c2c7 Libmv: De-duplicate creation of residual block
Allows to centralize logic which is needed to check which cost functor
to use for the specific intrinsics.
2020-04-20 16:26:39 +02:00
Sergey Sharybin f0e8965090 Libmv: Cleanup reprojection cost function
Make it smaller and more clear how and what it operates on.
2020-04-20 16:26:32 +02:00
Sergey Sharybin ce82e9e64a Libmv: Pass entire camera intrinsics to reprojection error functor
Currently no functional changes, but allows to have access to some
invariant settings of camera intrinsics such as image dimensions.
2020-04-20 16:26:32 +02:00