Commit Graph

120 Commits

Author SHA1 Message Date
Bastien Montagne 9da7dfa158 Refactor ID copying (and to some extent, ID freeing).
This will allow much finer controll over how we copy data-blocks, from
full copy in Main database, to "lighter" ones (out of Main, inside an
already allocated datablock, etc.).

This commit also transfers a llot of what was previously handled by
per-ID-type custom code to generic ID handling code in BKE_library.
Hopefully will avoid in future inconsistencies and missing bits we had
all over the codebase in the past.

It also adds missing copying handling for a few types, most notably
Scene (which where using a fully customized handling previously).

Note that the type of allocation used during copying (regular in Main,
allocated but outside of Main, or not allocated by ID handling code at
all) is stored in ID's, which allows to handle them correctly when
freeing. This needs to be taken care of with caution when doing 'weird'
unusual things with ID copying and/or allocation!

As a final note, while rather noisy, this commit will hopefully not
break too much existing branches, old 'API' has been kept for the main
part, as a wrapper around new code. Cleaning it up will happen later.

Design task : T51804
Phab Diff: D2714
2017-08-07 16:39:55 +02:00
Bastien Montagne eeb9e5316a Make whole ID copying code use const source pointer.
Noisy change, but safe, and better do it sooner than later if we are to
rework copying code. Also, previous commit shows this *is* useful to
catch some mistakes.
2017-06-14 22:38:11 +02:00
Ichthyostega b1677201f9 Rework 2D stabilizator
See this page for motivation and description of concepts:
https://github.com/Ichthyostega/blender/wiki

See this video for UI explanation and demonstration of usage
http://vimeo.com/blenderHack/stabilizerdemo

This proposal attempts to improve usability of Blender's image stabilization
feature for real-world footage esp. with moving and panning camera. It builds
upon the feature tracking to get a measurement of 2D image movement.

  - Use a weighted average of movement contributions (instead of a median).
  - Allow for rotation compensation and zoom (image scale) compensation.
  - Allow to pick a different set of tracks for translation and for
    rotation/zoom.
  - Treat translation / rotation / zoom contributions systematically in a
    similar way.
  - Improve handling of partial tracking data with gaps and varying
    start / end points.
  - Have a user definable anchor frame and interpolate / extrapolate data to
    avoid jumping back to "neutral" position when no tracking data is available.
  - Support for travelling and panning shots by including an //intended//
    position/rotation/zoom ("target position"). The idea is for these parameters
    to be //animated// by the user, in order to supply an smooth, intended
    camera movement. This way, we can keep the image content roughly in frame
    even when moving completely away from the initial view.

A known shortcoming is that the pivot point for rotation compensation is set to
the translation compensated image center. This can produce spurious rotation on
travelling shots, which needs to be compensated manually (by animating the
target rotation parameter). There are several possible ways to address that
problem, yet all of them are considered beyond the scope of this improvement
proposal for now.

Own modifications:

- Restrict line length, it's really handy for split-view editing
- In motion tracking we prefer fully human-readable comments, meaning we
  don't use doxygen with it's weird markup and comments are supposed to
  start with capital and end with a full stop,
- Add explicit comparison of pointer to NULL.

Reviewers: sergey

Subscribers: kusi, kdawg, forest-house, mardy, Samoth, plasmasolutions, willolis, sebastian_k, hype, enetheru, sunboy, jta, leon_cheung

Maniphest Tasks: T49036

Differential Revision: https://developer.blender.org/D583
2016-08-16 13:30:40 +02:00
Bastien Montagne 3d7cf808b8 Add copy/make_local to movieclip datablock.
As title says... Copying tracking data from movieclip was not the simplest thing...

Reviewers: sergey

Differential Revision: https://developer.blender.org/D2126
2016-07-29 23:13:31 +02:00
Sergey Sharybin c8d2ebe13c Compositor: Speedup movie (un)distortion operation
Avoid per-pixel camera intrincs object construction and synchronization.

Here on a bit synthetic file it gives about 40% speedup with a single node.
2016-01-26 11:44:43 +01:00
Sergey Sharybin 6f7926c61c Fix T45394: Motion tracking constraints did not work with Cycles motion blur 2015-07-13 18:17:46 +02:00
Campbell Barton a077be3658 Cleanup: use r_* prefix for return args 2015-05-08 07:25:39 +10:00
Sergey Sharybin b35743d39f Tracking: Add missing plane track remapping when joining two point tracks 2015-04-22 02:10:50 +05:00
Sergey Sharybin 260f75a2ca Tracking: Cleanup, move some plane tracks code to utility functions 2015-04-22 02:10:50 +05:00
Campbell Barton b1d758ae6b Cleanup: redundant struct declarations 2015-03-29 03:56:39 +11:00
Sergey Sharybin 8e16c5294b Fix T42585: Mask motion blur is wrong when parented to plane track
it wasn't wrong, it wasn't implemented.
2014-11-18 15:29:32 +01:00
Sergey Sharybin 606329d0f8 Libmv: Replace region tracker with autotracker in Blender
The title actually tells it all, this commit switches Blender to use the new
autotrack API from Libmv.

From the user point of view it means that prediction model is now used when
tracking which gives really nice results.

All the other changes are not really visible for users, those are just frame
accessors, caches and so for the new API.
2014-10-30 23:12:19 +05:00
Sergey Sharybin ed6942f9ad Fix wrong area of interest for movie undistortion 2014-09-11 19:33:01 +06:00
Sergey Sharybin ed2ddc9f70 Support multiple distortion models, including a new division model
This commit makes it so CameraIntrinsics is no longer hardcoded
to use the traditional polynomial radial distortion model. Currently
the distortion code has generic logic which is shared between
different distortion models, but had no other models until now.

This moves everything specific to the polynomial radial distortion
to a subclass PolynomialDistortionCameraIntrinsics(), and adds a
new division distortion model suitable for cameras such as the
GoPro which have much stronger distortion due to their fisheye lens.

This also cleans up the internal API of CameraIntrinsics to make
it easier to understand and reduces old C-style code.

New distortion model is available in the Lens panel of MCE.

- Polynomial is the old well-known model
- Division is the new one which s intended to deal better with huge
  distortion.

Coefficients of this model works independent from each other
and for division model one probably want to have positive values
to have a barrel distortion.
2014-04-17 17:28:41 +06:00
Sergey Sharybin 3d2b530315 Hiding plane tracks was never implemented 2014-03-06 20:07:40 +06:00
Campbell Barton d900f5be55 Code cleanup: use bools where possible 2014-02-03 19:35:44 +11:00
Sergey Sharybin be6643b5ec Followup to the previous commit
Need to take weight into account when drawing per-frame track
reprojection curve and when computing per-track average error.
2014-01-28 18:02:22 +06:00
Sergey Sharybin 9178dc9d38 Rework detector API and implement Harris detector
Switch the detector API to a single function which accepts
a float image and detector options. This makes usage of
feature detection more unified across different algorithms.

Options structure is pretty much straightforward and contains
detector to be used and all the detector-specific settings.

Also implemented Harris feature detection algorithm which
is not as fast as FAST one but is expected to detect more
robust feature points. It is also likely that less features
are detected, but better quality than quantity.

Blender will now use Harris detector by default, later we'll
remove FAST detector.
2014-01-28 15:37:19 +06:00
Sergey Sharybin 2785e8e73d Split tracking.c into several files
File tracking.c became rather huge and annoying to
maintain and it really contains several independent
areas of motrack pipeline.

Now we've got:

* tracking.c: general-purpose functions which are used
  by blender, clip editor, RNA and so.

* tracking_detect.c: feature detection functions
  (blender-side, logic is still in libmv).

* tracking_plane_tracker.c: blender-side 2D tracking logic.

* tracking_plane_tracker.c: plane track tracker.

* tracking_solver.c: functions for camera solving.

* tracking_stabilize.c: 2D stabilization functions.

* tracking_util.c: utility functions for all those files
  and which shouldn't be public.
2014-01-01 22:32:48 +06:00
Sergey Sharybin 9f32e83175 Weighted tracks
Added a weight slider to track which defines
how much particular track affects in a final
reconstruction. This weight is for sure
animateable.

Currently it affects on BA step only which in
most cases will work just fine.

The usecase of this slider is to have it set
to 1.0 most of the time where the track is
good, but blend it's weight down to 0 when
tracker looses the track. This will prevent
camera from jump.

Tutorial is to be done by Sebastian.
2013-10-26 13:22:38 +00:00
Sergey Sharybin b9be47e91c Re-track the plane after clearing the keyframe
From the math point of view there're two cases:

- Clearing the keyframe between two other ones.

  In this case tracker will first track plane from
  left keyframe to right one without doing any kind
  of blending. This will make plane stick to the
  actual plane motion, but lead to possible jump
  at the right keyframe.

  Second step is to track from the right keyframe
  to the left one with blending. This gives nice
  transition at the point of second keyframe and
  this mimics situation when you've been setting
  keyframes from left to right.

- Clearing left-most/right-most keyframe.

  In this case it's enough to only re-track the
  plane without blending from the neighbor keyframe
  without blending.
2013-09-17 08:54:10 +00:00
Sergey Sharybin e72c6f191f Tweaks to plane track
- Do plane re-evaluation only when transform is actually done.
  Before this re-evaluation happened on every mouse move.

- Added a flag "Auto Keyframe" for the plane track, which does:

  * If Auto Keyframe is enabled, then every manual edit of the
    plane will create a new keyframe at current frame and update
    plane motion between current frame and previous/next keyframe.

    This now also implies blending detected motion with neighbor
    keyframes, so there's no jump happening.

    No automatic update on manual point tracks edit will happen.

  * If auto Keyframe is disabled, then no keyframes are adding
    to the plane and every plane tweak will re-evaluate in on
    the whole frame range.

    In this case manual tweaks to point tracks and re-tracking
    them implies plane re-evaluation.
2013-09-10 12:46:18 +00:00
Sergey Sharybin e23ff65643 Code cleanup: use boolean instead of int for tracking API 2013-09-05 13:37:36 +00:00
Sergey Sharybin 24ce60cfe4 Merge plane track feature from tomato branch
This commit includes all the changes made for plane tracker
in tomato branch.

Movie clip editor changes:

- Artist might create a plane track out of multiple point
  tracks which belongs to the same track (minimum amount of
  point tracks is 4, maximum is not actually limited).

  When new plane track is added, it's getting "tracked"
  across all point tracks, which makes it stick to the same
  plane point tracks belong to.

- After plane track was added, it need to be manually adjusted
  in a way it covers feature one might to mask/replace.

  General transform tools (G, R, S) or sliding corners with
  a mouse could be sued for this. Plane corner which
  corresponds to left bottom image corner has got X/Y axis
  on it (red is for X axis, green for Y).

- Re-adjusting plane corners makes plane to be "re-tracked"
  for the frames sequence between current frame and next
  and previous keyframes.

- Kayframes might be removed from the plane, using Shit-X
  (Marker Delete) operator. However, currently manual
  re-adjustment or "re-track" trigger is needed.

Compositor changes:

- Added new node called Plane Track Deform.

- User selects which plane track to use (for this he need
  to select movie clip datablock, object and track names).

- Node gets an image input, which need to be warped into
  the plane.

- Node outputs:
  * Input image warped into the plane.
  * Plane, rasterized to a mask.

Masking changes:

- Mask points might be parented to a plane track, which
  makes this point deforming in a way as if it belongs
  to the tracked plane.

Some video tutorials are available:
- Coder video: http://www.youtube.com/watch?v=vISEwqNHqe4
- Artist video: https://vimeo.com/71727578

This is mine and Keir's holiday code project :)
2013-08-16 09:46:30 +00:00
Sergey Sharybin 22d2faccef Cleaned code a bit around 2D stabilization
Hopefully it's more readable now. Took me a while to remmeber
all the stuff going on here while was looking into possibility
of implementing some feature here.
2013-06-12 12:34:10 +00:00
Sergey Sharybin 682da3ac98 Apply scale on scene reconstruction when applying scale on camera
This means when you've got reconstructed scene assigned to a
3d camera (via camera solver constraint) and applies scale on
this camera from Ctrl-A menu, scale will be applied on the
reconstructed scene and reset camera size to identity.

This is very useful feature for scene orientation, when you'll
just scale camera by S in the viewport to match bundles
some points in the space, and then you'll easiy make camera
have identity scale (which is needed for nice working moblur
and other things mentioning by Sebastian :) without loosing
scale of bundles themselves.

Behavior of apply scale for cameras without clip assigned
to them does not change at all.
2013-05-13 13:37:05 +00:00
Sergey Sharybin d9ca50ff64 Refine markers position operator
This operator will run a tracker from previous
keyframe to current frame for all selected markers.
Current markers positions are considering initial
position guess which could be updated by a tracker
for better match.

Useful in cases when feature disappears from the
frame and then appears again. Usage in this case
is the following:

- When feature point re-appeared on frame, manully
  place marker on it.
- Use Refine Markers operation (which is in Track
  panel) to allow tracker to find a better match.

Depending on direction of tracking use either
Forwards or Backwards refining. It's easy: if
trackign happens forwards, use Refine Frowards,
otherwise use Refine Backwards :)
2013-05-12 16:04:14 +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
Sergey Sharybin 495aa863ae Fix for incorrect subpixel precision of marker when using track offset
Issue was caused by the way how pattern sampling happens in case of
anchored display: track offset is applying on search buffer which
means offset is rounding to an integer. Fractional pat of offset was
completely ignoring which lead to jumps in pattern buffer.

This was only a visualization issue in track preview widget.
2013-03-04 18:30:48 +00:00
Sergey Sharybin 5cc377022b Correction to r54600
Calculate dependent area based on distortion model rather than
using 15% of image resolution for this.

Some assumptions here:

- We're assuming real-life camera calibration is used here
- Maximal undistortion delta would be achieved on frame boundary
- Distortion fully goes inside frame

This makes it possible to approximate margin for distortion by
checking undistortion delta across frame boundary and use it
for dependent area of interest.

We do not use any formula-based equation here because we're likely
support other distortion models and in that case it'll be stupid
to try detecting formula here.
2013-02-18 10:12:44 +00:00
Campbell Barton a31449edad all remove functions now invalidate the RNA objects passed, to help script authors to avoid bugs with accessing removed data. 2012-11-02 09:41:26 +00:00
Sergey Sharybin c84802f51c Motion Tracking: fixed dopesheet left in incorrect state after joining tracks 2012-10-15 10:43:10 +00:00
Campbell Barton 872ebc7310 fill in dummy values when using movie clip distort node but compiled without libmv. 2012-07-31 22:01:44 +00:00
Sergey Sharybin 52aa7a4a4c Added utility function to return marker's subframe position
Used in mask parenting stuff.
2012-07-27 10:12:58 +00:00
Sergey Sharybin f0c724219d Internal refactoring of tracking module, should be no functional changes
- Re-arrange functions in headers and implementation file to make them
  more grouped by entity they're operating with. Also order of functions
  in implementation file should match order of functions in header for
  easier navigation.

- Rename some functions to match conventions of naming public functions.
- Some code de-duplication, still some room for improvements tho.
- Split main 2D tracking functions into smaller steps to make it more clear.

Accidentally OpenMP was disabled in some of previous commits, re-enable it.
2012-06-15 11:03:23 +00:00
Sergey Sharybin 55ca0e7636 Make dopesheet settings per-tracking data
It was a bit confusing to synchronize settings used in pre-calculated
dopesheet channels which was storing in tracking data with settings
used for display which is in space data.

This was initially done by converting one flags to other and checking
if space's settings matches pre-calculated one, but that had several
issues if two different dopesheet are using different settings:

- Channels would be re-calculated on every redraw for each of spaces
- Dopesheet operators could fail due to the could be using  channels
  calculated for other space.

That was also quite nasty code checking if requested settings matches
pre-calculated one.
2012-06-12 17:10:24 +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
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
Campbell Barton 51d9bf725d style cleanup 2012-06-10 19:59:02 +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 04766ab071 Added sorting by average reprojection error to motion tracking dopesheet. 2012-06-08 16:42:24 +00:00
Sergey Sharybin 9a9924c79c Camera tracking: show disabled active track even if Show Disabled is switched off 2012-05-03 23:41:28 +00:00
Sergey Sharybin 48ead27366 Camera tracking: switch dopesheet information to lazy calculation
All operators which changes tracking data now just tags dopsheet as outdated,
actual re-calculaiton of happens only when this information is actually needed
(like on dopesheet draw).

This makes things a bit faster when there's no dopesheet visible in current
screen and also makes it much easier to update dopesheet using dependency
graph.

Also renamed dopesheet_sort_order to dopesheet_sort_method in rna and internal
stuff which makes much more sense and also correlated with naming in
file browser.
2012-05-03 23:15:01 +00:00
Sergey Sharybin b1006fb949 Clip editor: sort order for dopesheet channels
Supported sorting by name, longest tracked segment and total tracked frames.

Internally tracks are stored in Tracking datablock, but sort order is
a clip editor space property and sorting happens on clip editor draw.
If there's no dopesheet opened with different sort orders it's not
a problem due to re-sorting wouldn't happen.

Also fixed draw issue of tracked segments introduced in previous commit.
2012-05-03 19:28:41 +00:00
Sergey Sharybin f111131ca6 Camera tracking: initial commit of dopesheet view for clip editor
- Displays dopesheet information for selected tracks, and currently does not
  support any kind of editing.
- Changed regions to use the whole main region for such views as curves and dopesheet.
  This allows to have own panels with tools/properties in this area.
- Active clip is getting synchronized between different clip editor editors in the
  same screen, so updating of curve/dopesheet views happens automatically when one
  changes current clip in one of this editors.
- Panels in toolbox and properties panels are now separated to rely on current view
  mode, but some operators and poll functions still need to be updated.
- Added new screen called "Movie Tracking" where layout is configured to
  display timeline, main clip window, curves and dopesheet.
2012-04-30 16:19:20 +00:00
Sergey Sharybin 1ce2c73816 Code style cleaup for motion-tracking modules.
Should be no functional changes.
2012-03-25 23:19:21 +00:00
Sergey Sharybin d110ae7791 Allow merging two tracks in cases when they've got overlapping tracked/keyframed
frame ranges using average position of both tracks as position/
2012-03-16 14:06:43 +00:00
Campbell Barton d2cab3e8b0 move bmesh wiki docs into bmesh header and update doxygen.
also have doxygen ignore *.py files and fix some warnings.
2012-02-27 20:27:19 +00:00
Sergey Sharybin 8285fef0e8 Fixed for selected bundles drawing in 3D viewport:
- If track was hidded in clip editor it wasn't highlighted in 3d viewport
  even if it's selected.
- If two tracks has got the same bundle coordinate and one of them is
  selected it might not be highlighted in 3d viewport because of
  draw order.
2012-02-26 08:14:14 +00:00
Campbell Barton 2b7ca2304a unify include guard defines, __$FILENAME__
without the underscores these clogged up the namespace for autocompleation which was annoying.
2012-02-17 18:59:41 +00:00