2011-11-07 12:55:18 +00:00
|
|
|
/*
|
|
|
|
|
* ***** BEGIN GPL LICENSE BLOCK *****
|
|
|
|
|
*
|
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
|
* as published by the Free Software Foundation; either version 2
|
|
|
|
|
* of the License, or (at your option) any later version.
|
|
|
|
|
*
|
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
|
*
|
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
|
* along with this program; if not, write to the Free Software Foundation,
|
|
|
|
|
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
|
|
|
*
|
|
|
|
|
* The Original Code is Copyright (C) 2011 Blender Foundation.
|
|
|
|
|
* All rights reserved.
|
|
|
|
|
*
|
|
|
|
|
* Contributor(s): Blender Foundation,
|
|
|
|
|
* Sergey Sharybin
|
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
|
|
|
* Keir Mierle
|
2011-11-07 12:55:18 +00:00
|
|
|
*
|
|
|
|
|
* ***** END GPL LICENSE BLOCK *****
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
/** \file blender/blenkernel/intern/tracking.c
|
|
|
|
|
* \ingroup bke
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#include <stddef.h>
|
|
|
|
|
#include <limits.h>
|
|
|
|
|
#include <math.h>
|
|
|
|
|
#include <memory.h>
|
|
|
|
|
|
|
|
|
|
#include "MEM_guardedalloc.h"
|
|
|
|
|
|
|
|
|
|
#include "DNA_gpencil_types.h"
|
|
|
|
|
#include "DNA_camera_types.h"
|
|
|
|
|
#include "DNA_movieclip_types.h"
|
2012-06-10 19:59:02 +00:00
|
|
|
#include "DNA_object_types.h" /* SELECT */
|
2011-11-07 12:55:18 +00:00
|
|
|
#include "DNA_scene_types.h"
|
|
|
|
|
|
|
|
|
|
#include "BLI_utildefines.h"
|
|
|
|
|
#include "BLI_math.h"
|
|
|
|
|
#include "BLI_math_base.h"
|
|
|
|
|
#include "BLI_listbase.h"
|
|
|
|
|
#include "BLI_ghash.h"
|
|
|
|
|
#include "BLI_path_util.h"
|
Assorted camera tracker improvements
- Add support for refining the camera's intrinsic parameters
during a solve. Currently, refining supports only the following
combinations of intrinsic parameters:
f
f, cx, cy
f, cx, cy, k1, k2
f, k1
f, k1, k2
This is not the same as autocalibration, since the user must
still make a reasonable initial guess about the focal length and
other parameters, whereas true autocalibration would eliminate
the need for the user specify intrinsic parameters at all.
However, the solver works well with only rough guesses for the
focal length, so perhaps full autocalibation is not that
important.
Adding support for the last two combinations, (f, k1) and (f,
k1, k2) required changes to the library libmv depends on for
bundle adjustment, SSBA. These changes should get ported
upstream not just to libmv but to SSBA as well.
- Improved the region of convergence for bundle adjustment by
increasing the number of Levenberg-Marquardt iterations from 50
to 500. This way, the solver is able to crawl out of the bad
local minima it gets stuck in when changing from, for example,
bundling k1 and k2 to just k1 and resetting k2 to 0.
- Add several new region tracker implementations. A region tracker
is a libmv concept, which refers to tracking a template image
pattern through frames. The impact to end users is that tracking
should "just work better". I am reserving a more detailed
writeup, and maybe a paper, for later.
- Other libmv tweaks, such as detecting that a tracker is headed
outside of the image bounds.
This includes several changes made directly to the libmv extern
code rather expecting to get those changes through normal libmv
channels, because I, the libmv BDFL, decided it was faster to work
on libmv directly in Blender, then later reverse-port the libmv
changes from Blender back into libmv trunk. The interesting part
is that I added a full Levenberg-Marquardt loop to the region
tracking code, which should lead to a more stable solutions. I
also added a hacky implementation of "Efficient Second-Order
Minimization" for tracking, which works nicely. A more detailed
quantitative evaluation will follow.
Original patch by Keir, cleaned a bit by myself.
2011-11-14 06:41:23 +00:00
|
|
|
#include "BLI_string.h"
|
2011-12-13 10:07:22 +00:00
|
|
|
#include "BLI_threads.h"
|
2011-11-07 12:55:18 +00:00
|
|
|
|
2012-10-26 17:32:50 +00:00
|
|
|
#include "BLF_translation.h"
|
|
|
|
|
|
2011-11-07 12:55:18 +00:00
|
|
|
#include "BKE_global.h"
|
|
|
|
|
#include "BKE_tracking.h"
|
|
|
|
|
#include "BKE_movieclip.h"
|
|
|
|
|
#include "BKE_object.h"
|
|
|
|
|
#include "BKE_scene.h"
|
|
|
|
|
|
|
|
|
|
#include "IMB_imbuf_types.h"
|
|
|
|
|
#include "IMB_imbuf.h"
|
|
|
|
|
|
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
|
|
|
#include "raskter.h"
|
|
|
|
|
|
2011-11-07 12:55:18 +00:00
|
|
|
#ifdef WITH_LIBMV
|
2011-11-07 16:26:23 +00:00
|
|
|
# include "libmv-capi.h"
|
|
|
|
|
#else
|
|
|
|
|
struct libmv_Features;
|
2011-11-07 12:55:18 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
typedef struct MovieDistortion {
|
|
|
|
|
struct libmv_CameraIntrinsics *intrinsics;
|
|
|
|
|
} MovieDistortion;
|
|
|
|
|
|
2012-01-09 20:18:48 +00:00
|
|
|
static struct {
|
|
|
|
|
ListBase tracks;
|
|
|
|
|
} tracking_clipboard;
|
|
|
|
|
|
2012-06-15 11:03:23 +00:00
|
|
|
/*********************** Common functions *************************/
|
|
|
|
|
|
|
|
|
|
static MovieTrackingTrack *tracking_track_duplicate(MovieTrackingTrack *track)
|
|
|
|
|
{
|
|
|
|
|
MovieTrackingTrack *new_track;
|
|
|
|
|
|
|
|
|
|
new_track = MEM_callocN(sizeof(MovieTrackingTrack), "tracksMapMerge new_track");
|
|
|
|
|
|
|
|
|
|
*new_track = *track;
|
|
|
|
|
new_track->next = new_track->prev = NULL;
|
|
|
|
|
|
|
|
|
|
new_track->markers = MEM_dupallocN(new_track->markers);
|
|
|
|
|
|
|
|
|
|
return new_track;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void tracking_tracks_free(ListBase *tracks)
|
|
|
|
|
{
|
|
|
|
|
MovieTrackingTrack *track;
|
|
|
|
|
|
|
|
|
|
for (track = tracks->first; track; track = track->next) {
|
|
|
|
|
BKE_tracking_track_free(track);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
BLI_freelistN(tracks);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void tracking_reconstruction_free(MovieTrackingReconstruction *reconstruction)
|
|
|
|
|
{
|
|
|
|
|
if (reconstruction->cameras)
|
|
|
|
|
MEM_freeN(reconstruction->cameras);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void tracking_object_free(MovieTrackingObject *object)
|
|
|
|
|
{
|
|
|
|
|
tracking_tracks_free(&object->tracks);
|
|
|
|
|
tracking_reconstruction_free(&object->reconstruction);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void tracking_objects_free(ListBase *objects)
|
|
|
|
|
{
|
|
|
|
|
MovieTrackingObject *object;
|
|
|
|
|
|
|
|
|
|
for (object = objects->first; object; object = object->next)
|
|
|
|
|
tracking_object_free(object);
|
|
|
|
|
|
|
|
|
|
BLI_freelistN(objects);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void tracking_dopesheet_free(MovieTrackingDopesheet *dopesheet)
|
|
|
|
|
{
|
|
|
|
|
MovieTrackingDopesheetChannel *channel;
|
|
|
|
|
|
|
|
|
|
channel = dopesheet->channels.first;
|
|
|
|
|
while (channel) {
|
|
|
|
|
if (channel->segments) {
|
|
|
|
|
MEM_freeN(channel->segments);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
channel = channel->next;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
BLI_freelistN(&dopesheet->channels);
|
2013-02-22 10:13:15 +00:00
|
|
|
BLI_freelistN(&dopesheet->coverage_segments);
|
2012-06-15 11:03:23 +00:00
|
|
|
|
|
|
|
|
dopesheet->channels.first = dopesheet->channels.last = NULL;
|
2013-02-22 10:13:15 +00:00
|
|
|
dopesheet->coverage_segments.first = dopesheet->coverage_segments.last = NULL;
|
2012-06-15 11:03:23 +00:00
|
|
|
dopesheet->tot_channel = 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void BKE_tracking_free(MovieTracking *tracking)
|
|
|
|
|
{
|
|
|
|
|
tracking_tracks_free(&tracking->tracks);
|
|
|
|
|
tracking_reconstruction_free(&tracking->reconstruction);
|
|
|
|
|
tracking_objects_free(&tracking->objects);
|
|
|
|
|
|
|
|
|
|
if (tracking->stabilization.scaleibuf)
|
|
|
|
|
IMB_freeImBuf(tracking->stabilization.scaleibuf);
|
|
|
|
|
|
|
|
|
|
if (tracking->camera.intrinsics)
|
|
|
|
|
BKE_tracking_distortion_free(tracking->camera.intrinsics);
|
|
|
|
|
|
|
|
|
|
tracking_dopesheet_free(&tracking->dopesheet);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void BKE_tracking_settings_init(MovieTracking *tracking)
|
|
|
|
|
{
|
|
|
|
|
tracking->camera.sensor_width = 35.0f;
|
|
|
|
|
tracking->camera.pixel_aspect = 1.0f;
|
|
|
|
|
tracking->camera.units = CAMERA_UNITS_MM;
|
|
|
|
|
|
|
|
|
|
tracking->settings.default_motion_model = TRACK_MOTION_MODEL_TRANSLATION;
|
|
|
|
|
tracking->settings.default_minimum_correlation = 0.75;
|
2013-02-05 13:10:26 +00:00
|
|
|
tracking->settings.default_pattern_size = 15;
|
2012-06-15 11:03:23 +00:00
|
|
|
tracking->settings.default_search_size = 61;
|
2013-02-05 13:10:26 +00:00
|
|
|
tracking->settings.default_algorithm_flag |= TRACK_ALGORITHM_FLAG_USE_BRUTE;
|
2012-06-15 11:03:23 +00:00
|
|
|
tracking->settings.dist = 1;
|
|
|
|
|
tracking->settings.object_distance = 1;
|
2012-11-05 08:04:27 +00:00
|
|
|
tracking->settings.reconstruction_success_threshold = 1e-3;
|
2012-06-15 11:03:23 +00:00
|
|
|
|
|
|
|
|
tracking->stabilization.scaleinf = 1.0f;
|
|
|
|
|
tracking->stabilization.locinf = 1.0f;
|
|
|
|
|
tracking->stabilization.rotinf = 1.0f;
|
|
|
|
|
tracking->stabilization.maxscale = 2.0f;
|
|
|
|
|
|
|
|
|
|
BKE_tracking_object_add(tracking, "Camera");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ListBase *BKE_tracking_get_active_tracks(MovieTracking *tracking)
|
|
|
|
|
{
|
|
|
|
|
MovieTrackingObject *object = BKE_tracking_object_get_active(tracking);
|
|
|
|
|
|
|
|
|
|
if (object && (object->flag & TRACKING_OBJECT_CAMERA) == 0) {
|
|
|
|
|
return &object->tracks;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return &tracking->tracks;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
MovieTrackingReconstruction *BKE_tracking_get_active_reconstruction(MovieTracking *tracking)
|
|
|
|
|
{
|
|
|
|
|
MovieTrackingObject *object = BKE_tracking_object_get_active(tracking);
|
|
|
|
|
|
|
|
|
|
return BKE_tracking_object_get_reconstruction(tracking, object);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void BKE_tracking_get_camera_object_matrix(Scene *scene, Object *ob, float mat[4][4])
|
|
|
|
|
{
|
|
|
|
|
if (!ob) {
|
|
|
|
|
if (scene->camera)
|
|
|
|
|
ob = scene->camera;
|
|
|
|
|
else
|
|
|
|
|
ob = BKE_scene_camera_find(scene);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (ob)
|
|
|
|
|
BKE_object_where_is_calc_mat4(scene, ob, mat);
|
|
|
|
|
else
|
|
|
|
|
unit_m4(mat);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void BKE_tracking_get_projection_matrix(MovieTracking *tracking, MovieTrackingObject *object,
|
2012-06-16 09:18:00 +00:00
|
|
|
int framenr, int winx, int winy, float mat[4][4])
|
2012-06-15 11:03:23 +00:00
|
|
|
{
|
|
|
|
|
MovieReconstructedCamera *camera;
|
|
|
|
|
float lens = tracking->camera.focal * tracking->camera.sensor_width / (float)winx;
|
|
|
|
|
float viewfac, pixsize, left, right, bottom, top, clipsta, clipend;
|
|
|
|
|
float winmat[4][4];
|
|
|
|
|
float ycor = 1.0f / tracking->camera.pixel_aspect;
|
2012-10-23 16:21:55 +00:00
|
|
|
float shiftx, shifty, winside = (float)min_ii(winx, winy);
|
2012-06-15 11:03:23 +00:00
|
|
|
|
|
|
|
|
BKE_tracking_camera_shift_get(tracking, winx, winy, &shiftx, &shifty);
|
|
|
|
|
|
|
|
|
|
clipsta = 0.1f;
|
|
|
|
|
clipend = 1000.0f;
|
|
|
|
|
|
|
|
|
|
if (winx >= winy)
|
|
|
|
|
viewfac = (lens * winx) / tracking->camera.sensor_width;
|
|
|
|
|
else
|
|
|
|
|
viewfac = (ycor * lens * winy) / tracking->camera.sensor_width;
|
|
|
|
|
|
|
|
|
|
pixsize = clipsta / viewfac;
|
|
|
|
|
|
|
|
|
|
left = -0.5f * (float)winx + shiftx * winside;
|
|
|
|
|
bottom = -0.5f * (ycor) * (float)winy + shifty * winside;
|
|
|
|
|
right = 0.5f * (float)winx + shiftx * winside;
|
|
|
|
|
top = 0.5f * (ycor) * (float)winy + shifty * winside;
|
|
|
|
|
|
|
|
|
|
left *= pixsize;
|
|
|
|
|
right *= pixsize;
|
|
|
|
|
bottom *= pixsize;
|
|
|
|
|
top *= pixsize;
|
|
|
|
|
|
|
|
|
|
perspective_m4(winmat, left, right, bottom, top, clipsta, clipend);
|
|
|
|
|
|
|
|
|
|
camera = BKE_tracking_camera_get_reconstructed(tracking, object, framenr);
|
|
|
|
|
|
|
|
|
|
if (camera) {
|
|
|
|
|
float imat[4][4];
|
|
|
|
|
|
|
|
|
|
invert_m4_m4(imat, camera->mat);
|
|
|
|
|
mult_m4_m4m4(mat, winmat, imat);
|
|
|
|
|
}
|
|
|
|
|
else copy_m4_m4(mat, winmat);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* **** space transformation functions **** */
|
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
|
|
|
|
|
|
|
|
/* Three coordinate frames: Frame, Search, and Marker
|
|
|
|
|
* Two units: Pixels, Unified
|
|
|
|
|
* Notation: {coordinate frame}_{unit}; for example, "search_pixel" are search
|
|
|
|
|
* window relative coordinates in pixels, and "frame_unified" are unified 0..1
|
|
|
|
|
* coordinates relative to the entire frame.
|
|
|
|
|
*/
|
|
|
|
|
static void unified_to_pixel(int frame_width, int frame_height,
|
|
|
|
|
const float unified_coords[2], float pixel_coords[2])
|
|
|
|
|
{
|
|
|
|
|
pixel_coords[0] = unified_coords[0] * frame_width;
|
|
|
|
|
pixel_coords[1] = unified_coords[1] * frame_height;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void marker_to_frame_unified(const MovieTrackingMarker *marker, const float marker_unified_coords[2],
|
|
|
|
|
float frame_unified_coords[2])
|
|
|
|
|
{
|
|
|
|
|
frame_unified_coords[0] = marker_unified_coords[0] + marker->pos[0];
|
|
|
|
|
frame_unified_coords[1] = marker_unified_coords[1] + marker->pos[1];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void marker_unified_to_frame_pixel_coordinates(int frame_width, int frame_height,
|
|
|
|
|
const MovieTrackingMarker *marker,
|
2012-06-15 11:03:23 +00:00
|
|
|
const float marker_unified_coords[2],
|
|
|
|
|
float frame_pixel_coords[2])
|
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
|
|
|
{
|
|
|
|
|
marker_to_frame_unified(marker, marker_unified_coords, frame_pixel_coords);
|
|
|
|
|
unified_to_pixel(frame_width, frame_height, frame_pixel_coords, frame_pixel_coords);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void get_search_origin_frame_pixel(int frame_width, int frame_height,
|
|
|
|
|
const MovieTrackingMarker *marker, float frame_pixel[2])
|
|
|
|
|
{
|
|
|
|
|
/* Get the lower left coordinate of the search window and snap to pixel coordinates */
|
|
|
|
|
marker_unified_to_frame_pixel_coordinates(frame_width, frame_height, marker, marker->search_min, frame_pixel);
|
|
|
|
|
frame_pixel[0] = (int)frame_pixel[0];
|
|
|
|
|
frame_pixel[1] = (int)frame_pixel[1];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#ifdef WITH_LIBMV
|
|
|
|
|
static void pixel_to_unified(int frame_width, int frame_height, const float pixel_coords[2], float unified_coords[2])
|
|
|
|
|
{
|
|
|
|
|
unified_coords[0] = pixel_coords[0] / frame_width;
|
|
|
|
|
unified_coords[1] = pixel_coords[1] / frame_height;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void marker_unified_to_search_pixel(int frame_width, int frame_height,
|
|
|
|
|
const MovieTrackingMarker *marker,
|
|
|
|
|
const float marker_unified[2], float search_pixel[2])
|
|
|
|
|
{
|
|
|
|
|
float frame_pixel[2];
|
|
|
|
|
float search_origin_frame_pixel[2];
|
|
|
|
|
|
|
|
|
|
marker_unified_to_frame_pixel_coordinates(frame_width, frame_height, marker, marker_unified, frame_pixel);
|
|
|
|
|
get_search_origin_frame_pixel(frame_width, frame_height, marker, search_origin_frame_pixel);
|
|
|
|
|
sub_v2_v2v2(search_pixel, frame_pixel, search_origin_frame_pixel);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void search_pixel_to_marker_unified(int frame_width, int frame_height,
|
|
|
|
|
const MovieTrackingMarker *marker,
|
|
|
|
|
const float search_pixel[2], float marker_unified[2])
|
|
|
|
|
{
|
|
|
|
|
float frame_unified[2];
|
|
|
|
|
float search_origin_frame_pixel[2];
|
|
|
|
|
|
|
|
|
|
get_search_origin_frame_pixel(frame_width, frame_height, marker, search_origin_frame_pixel);
|
|
|
|
|
add_v2_v2v2(frame_unified, search_pixel, search_origin_frame_pixel);
|
|
|
|
|
pixel_to_unified(frame_width, frame_height, frame_unified, frame_unified);
|
|
|
|
|
|
|
|
|
|
/* marker pos is in frame unified */
|
|
|
|
|
sub_v2_v2v2(marker_unified, frame_unified, marker->pos);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Each marker has 5 coordinates associated with it that get warped with
|
2012-09-28 06:45:20 +00:00
|
|
|
* tracking: the four corners ("pattern_corners"), and the center ("pos").
|
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
|
|
|
* This function puts those 5 points into the appropriate frame for tracking
|
|
|
|
|
* (the "search" coordinate frame).
|
|
|
|
|
*/
|
|
|
|
|
static void get_marker_coords_for_tracking(int frame_width, int frame_height,
|
|
|
|
|
const MovieTrackingMarker *marker,
|
|
|
|
|
double search_pixel_x[5], double search_pixel_y[5])
|
|
|
|
|
{
|
|
|
|
|
int i;
|
|
|
|
|
float unified_coords[2];
|
|
|
|
|
float pixel_coords[2];
|
|
|
|
|
|
|
|
|
|
/* Convert the corners into search space coordinates. */
|
|
|
|
|
for (i = 0; i < 4; i++) {
|
|
|
|
|
marker_unified_to_search_pixel(frame_width, frame_height, marker, marker->pattern_corners[i], pixel_coords);
|
|
|
|
|
search_pixel_x[i] = pixel_coords[0];
|
|
|
|
|
search_pixel_y[i] = pixel_coords[1];
|
|
|
|
|
}
|
2012-06-15 11:03:23 +00:00
|
|
|
|
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
|
|
|
/* Convert the center position (aka "pos"); this is the origin */
|
|
|
|
|
unified_coords[0] = 0.0;
|
|
|
|
|
unified_coords[1] = 0.0;
|
|
|
|
|
marker_unified_to_search_pixel(frame_width, frame_height, marker, unified_coords, pixel_coords);
|
|
|
|
|
|
|
|
|
|
search_pixel_x[4] = pixel_coords[0];
|
|
|
|
|
search_pixel_y[4] = pixel_coords[1];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Inverse of above. */
|
|
|
|
|
static void set_marker_coords_from_tracking(int frame_width, int frame_height, MovieTrackingMarker *marker,
|
|
|
|
|
const double search_pixel_x[5], const double search_pixel_y[5])
|
|
|
|
|
{
|
|
|
|
|
int i;
|
|
|
|
|
float marker_unified[2];
|
|
|
|
|
float search_pixel[2];
|
|
|
|
|
|
|
|
|
|
/* Convert the corners into search space coordinates. */
|
|
|
|
|
for (i = 0; i < 4; i++) {
|
|
|
|
|
search_pixel[0] = search_pixel_x[i];
|
|
|
|
|
search_pixel[1] = search_pixel_y[i];
|
|
|
|
|
search_pixel_to_marker_unified(frame_width, frame_height, marker, search_pixel, marker->pattern_corners[i]);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Convert the center position (aka "pos"); this is the origin */
|
|
|
|
|
search_pixel[0] = search_pixel_x[4];
|
|
|
|
|
search_pixel[1] = search_pixel_y[4];
|
|
|
|
|
search_pixel_to_marker_unified(frame_width, frame_height, marker, search_pixel, marker_unified);
|
|
|
|
|
|
|
|
|
|
/* If the tracker tracked nothing, then "marker_unified" would be zero.
|
|
|
|
|
* Otherwise, the entire patch shifted, and that delta should be applied to
|
|
|
|
|
* all the coordinates.
|
|
|
|
|
*/
|
|
|
|
|
for (i = 0; i < 4; i++) {
|
|
|
|
|
marker->pattern_corners[i][0] -= marker_unified[0];
|
|
|
|
|
marker->pattern_corners[i][1] -= marker_unified[1];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
marker->pos[0] += marker_unified[0];
|
|
|
|
|
marker->pos[1] += marker_unified[1];
|
|
|
|
|
}
|
|
|
|
|
#endif
|
|
|
|
|
|
2012-06-15 11:03:23 +00:00
|
|
|
/*********************** clipboard *************************/
|
2011-11-07 12:55:18 +00:00
|
|
|
|
2012-06-15 11:03:23 +00:00
|
|
|
void BKE_tracking_clipboard_free(void)
|
2011-11-28 13:26:46 +00:00
|
|
|
{
|
2012-06-15 11:03:23 +00:00
|
|
|
MovieTrackingTrack *track = tracking_clipboard.tracks.first, *next_track;
|
2012-03-25 23:19:21 +00:00
|
|
|
|
2012-06-15 11:03:23 +00:00
|
|
|
while (track) {
|
|
|
|
|
next_track = track->next;
|
2012-03-25 23:19:21 +00:00
|
|
|
|
2012-06-15 11:03:23 +00:00
|
|
|
BKE_tracking_track_free(track);
|
|
|
|
|
MEM_freeN(track);
|
2011-12-05 18:57:17 +00:00
|
|
|
|
2012-06-15 11:03:23 +00:00
|
|
|
track = next_track;
|
|
|
|
|
}
|
2012-09-03 01:05:04 +00:00
|
|
|
|
|
|
|
|
tracking_clipboard.tracks.first = tracking_clipboard.tracks.last = NULL;
|
2011-11-28 13:26:46 +00:00
|
|
|
}
|
|
|
|
|
|
2012-06-15 11:03:23 +00:00
|
|
|
void BKE_tracking_clipboard_copy_tracks(MovieTracking *tracking, MovieTrackingObject *object)
|
2011-11-07 12:55:18 +00:00
|
|
|
{
|
2012-06-15 11:03:23 +00:00
|
|
|
ListBase *tracksbase = BKE_tracking_object_get_tracks(tracking, object);
|
|
|
|
|
MovieTrackingTrack *track = tracksbase->first;
|
2011-11-07 12:55:18 +00:00
|
|
|
|
2012-06-15 11:03:23 +00:00
|
|
|
BKE_tracking_clipboard_free();
|
2012-03-25 23:19:21 +00:00
|
|
|
|
2012-06-15 11:03:23 +00:00
|
|
|
while (track) {
|
|
|
|
|
if (TRACK_SELECTED(track) && (track->flag & TRACK_HIDDEN) == 0) {
|
|
|
|
|
MovieTrackingTrack *new_track = tracking_track_duplicate(track);
|
2011-11-07 12:55:18 +00:00
|
|
|
|
2012-06-15 11:03:23 +00:00
|
|
|
BLI_addtail(&tracking_clipboard.tracks, new_track);
|
2011-11-07 12:55:18 +00:00
|
|
|
}
|
2012-03-25 23:19:21 +00:00
|
|
|
|
2012-06-15 11:03:23 +00:00
|
|
|
track = track->next;
|
2011-11-07 12:55:18 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2012-06-15 11:03:23 +00:00
|
|
|
int BKE_tracking_clipboard_has_tracks(void)
|
2011-11-07 12:55:18 +00:00
|
|
|
{
|
2012-06-15 11:03:23 +00:00
|
|
|
return tracking_clipboard.tracks.first != NULL;
|
|
|
|
|
}
|
2011-11-07 12:55:18 +00:00
|
|
|
|
2012-06-15 11:03:23 +00:00
|
|
|
void BKE_tracking_clipboard_paste_tracks(MovieTracking *tracking, MovieTrackingObject *object)
|
|
|
|
|
{
|
|
|
|
|
ListBase *tracksbase = BKE_tracking_object_get_tracks(tracking, object);
|
|
|
|
|
MovieTrackingTrack *track = tracking_clipboard.tracks.first;
|
|
|
|
|
|
|
|
|
|
while (track) {
|
|
|
|
|
MovieTrackingTrack *new_track = tracking_track_duplicate(track);
|
|
|
|
|
|
|
|
|
|
BLI_addtail(tracksbase, new_track);
|
|
|
|
|
BKE_tracking_track_unique_name(tracksbase, new_track);
|
|
|
|
|
|
|
|
|
|
track = track->next;
|
2011-11-07 12:55:18 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2012-06-15 11:03:23 +00:00
|
|
|
/*********************** Tracks *************************/
|
|
|
|
|
|
2012-09-27 14:47:23 +00:00
|
|
|
static void tracking_marker_insert_disabled(MovieTrackingTrack *track, const MovieTrackingMarker *ref_marker,
|
2012-06-15 11:03:23 +00:00
|
|
|
int before, int overwrite)
|
|
|
|
|
{
|
|
|
|
|
MovieTrackingMarker marker_new;
|
|
|
|
|
|
|
|
|
|
marker_new = *ref_marker;
|
|
|
|
|
marker_new.flag &= ~MARKER_TRACKED;
|
|
|
|
|
marker_new.flag |= MARKER_DISABLED;
|
|
|
|
|
|
|
|
|
|
if (before)
|
|
|
|
|
marker_new.framenr--;
|
|
|
|
|
else
|
|
|
|
|
marker_new.framenr++;
|
|
|
|
|
|
|
|
|
|
if (overwrite || !BKE_tracking_track_has_marker_at_frame(track, marker_new.framenr))
|
|
|
|
|
BKE_tracking_marker_insert(track, &marker_new);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
MovieTrackingTrack *BKE_tracking_track_add(MovieTracking *tracking, ListBase *tracksbase, float x, float y,
|
2012-03-25 23:19:21 +00:00
|
|
|
int framenr, int width, int height)
|
2011-11-07 12:55:18 +00:00
|
|
|
{
|
|
|
|
|
MovieTrackingTrack *track;
|
|
|
|
|
MovieTrackingMarker marker;
|
2012-03-25 23:19:21 +00:00
|
|
|
MovieTrackingSettings *settings = &tracking->settings;
|
2011-11-07 12:55:18 +00:00
|
|
|
|
2012-03-25 23:19:21 +00:00
|
|
|
float half_pattern = (float)settings->default_pattern_size / 2.0f;
|
|
|
|
|
float half_search = (float)settings->default_search_size / 2.0f;
|
2011-11-28 13:26:46 +00:00
|
|
|
float pat[2], search[2];
|
2011-11-07 12:55:18 +00:00
|
|
|
|
2012-03-25 23:19:21 +00:00
|
|
|
pat[0] = half_pattern / (float)width;
|
|
|
|
|
pat[1] = half_pattern / (float)height;
|
2011-11-07 12:55:18 +00:00
|
|
|
|
2012-03-25 23:19:21 +00:00
|
|
|
search[0] = half_search / (float)width;
|
|
|
|
|
search[1] = half_search / (float)height;
|
2011-11-07 12:55:18 +00:00
|
|
|
|
2012-03-25 23:19:21 +00:00
|
|
|
track = MEM_callocN(sizeof(MovieTrackingTrack), "add_marker_exec track");
|
2011-11-07 12:55:18 +00:00
|
|
|
strcpy(track->name, "Track");
|
|
|
|
|
|
2012-06-15 11:03:23 +00:00
|
|
|
/* fill track's settings from default settings */
|
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
|
|
|
track->motion_model = settings->default_motion_model;
|
2012-03-25 23:19:21 +00:00
|
|
|
track->minimum_correlation = settings->default_minimum_correlation;
|
|
|
|
|
track->margin = settings->default_margin;
|
|
|
|
|
track->pattern_match = settings->default_pattern_match;
|
|
|
|
|
track->frames_limit = settings->default_frames_limit;
|
|
|
|
|
track->flag = settings->default_flag;
|
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
|
|
|
track->algorithm_flag = settings->default_algorithm_flag;
|
2011-11-07 12:55:18 +00:00
|
|
|
|
|
|
|
|
memset(&marker, 0, sizeof(marker));
|
2012-03-25 23:19:21 +00:00
|
|
|
marker.pos[0] = x;
|
|
|
|
|
marker.pos[1] = y;
|
|
|
|
|
marker.framenr = framenr;
|
2011-11-07 12:55:18 +00:00
|
|
|
|
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
|
|
|
marker.pattern_corners[0][0] = -pat[0];
|
|
|
|
|
marker.pattern_corners[0][1] = -pat[1];
|
2011-11-07 12:55:18 +00:00
|
|
|
|
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
|
|
|
marker.pattern_corners[1][0] = pat[0];
|
|
|
|
|
marker.pattern_corners[1][1] = -pat[1];
|
2011-11-07 12:55:18 +00:00
|
|
|
|
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
|
|
|
negate_v2_v2(marker.pattern_corners[2], marker.pattern_corners[0]);
|
|
|
|
|
negate_v2_v2(marker.pattern_corners[3], marker.pattern_corners[1]);
|
2011-11-07 12:55:18 +00:00
|
|
|
|
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
|
|
|
copy_v2_v2(marker.search_max, search);
|
|
|
|
|
negate_v2_v2(marker.search_min, search);
|
|
|
|
|
|
2012-06-15 11:03:23 +00:00
|
|
|
BKE_tracking_marker_insert(track, &marker);
|
2011-11-28 13:26:46 +00:00
|
|
|
|
2011-12-05 18:57:17 +00:00
|
|
|
BLI_addtail(tracksbase, track);
|
2012-06-15 11:03:23 +00:00
|
|
|
BKE_tracking_track_unique_name(tracksbase, track);
|
2011-11-07 12:55:18 +00:00
|
|
|
|
|
|
|
|
return track;
|
|
|
|
|
}
|
|
|
|
|
|
2012-06-15 11:03:23 +00:00
|
|
|
void BKE_tracking_track_unique_name(ListBase *tracksbase, MovieTrackingTrack *track)
|
2011-11-07 12:55:18 +00:00
|
|
|
{
|
2012-06-15 11:03:23 +00:00
|
|
|
BLI_uniquename(tracksbase, track, "Track", '.', offsetof(MovieTrackingTrack, name), sizeof(track->name));
|
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
|
|
|
}
|
|
|
|
|
|
2012-06-15 11:03:23 +00:00
|
|
|
void BKE_tracking_track_free(MovieTrackingTrack *track)
|
2011-11-07 12:55:18 +00:00
|
|
|
{
|
2012-06-15 11:03:23 +00:00
|
|
|
if (track->markers)
|
|
|
|
|
MEM_freeN(track->markers);
|
2011-11-07 12:55:18 +00:00
|
|
|
}
|
|
|
|
|
|
2012-06-15 11:03:23 +00:00
|
|
|
void BKE_tracking_track_flag_set(MovieTrackingTrack *track, int area, int flag)
|
2011-11-07 12:55:18 +00:00
|
|
|
{
|
2012-06-15 11:03:23 +00:00
|
|
|
if (area == TRACK_AREA_NONE)
|
|
|
|
|
return;
|
2011-11-07 12:55:18 +00:00
|
|
|
|
2012-06-15 11:03:23 +00:00
|
|
|
if (area & TRACK_AREA_POINT)
|
|
|
|
|
track->flag |= flag;
|
|
|
|
|
if (area & TRACK_AREA_PAT)
|
|
|
|
|
track->pat_flag |= flag;
|
|
|
|
|
if (area & TRACK_AREA_SEARCH)
|
|
|
|
|
track->search_flag |= flag;
|
2011-11-07 12:55:18 +00:00
|
|
|
}
|
|
|
|
|
|
2012-06-15 11:03:23 +00:00
|
|
|
void BKE_tracking_track_flag_clear(MovieTrackingTrack *track, int area, int flag)
|
2011-11-07 12:55:18 +00:00
|
|
|
{
|
2012-06-15 11:03:23 +00:00
|
|
|
if (area == TRACK_AREA_NONE)
|
|
|
|
|
return;
|
2011-11-07 12:55:18 +00:00
|
|
|
|
2012-06-15 11:03:23 +00:00
|
|
|
if (area & TRACK_AREA_POINT)
|
|
|
|
|
track->flag &= ~flag;
|
|
|
|
|
if (area & TRACK_AREA_PAT)
|
|
|
|
|
track->pat_flag &= ~flag;
|
|
|
|
|
if (area & TRACK_AREA_SEARCH)
|
|
|
|
|
track->search_flag &= ~flag;
|
2011-11-07 12:55:18 +00:00
|
|
|
}
|
|
|
|
|
|
2012-06-15 11:03:23 +00:00
|
|
|
int BKE_tracking_track_has_marker_at_frame(MovieTrackingTrack *track, int framenr)
|
2011-11-07 12:55:18 +00:00
|
|
|
{
|
2012-06-15 11:03:23 +00:00
|
|
|
return BKE_tracking_marker_get_exact(track, framenr) != 0;
|
2011-11-07 12:55:18 +00:00
|
|
|
}
|
|
|
|
|
|
2012-06-15 11:03:23 +00:00
|
|
|
int BKE_tracking_track_has_enabled_marker_at_frame(MovieTrackingTrack *track, int framenr)
|
2012-01-25 13:37:11 +00:00
|
|
|
{
|
2012-06-15 11:03:23 +00:00
|
|
|
MovieTrackingMarker *marker = BKE_tracking_marker_get_exact(track, framenr);
|
2012-01-25 13:37:11 +00:00
|
|
|
|
|
|
|
|
return marker && (marker->flag & MARKER_DISABLED) == 0;
|
|
|
|
|
}
|
|
|
|
|
|
2012-06-15 11:03:23 +00:00
|
|
|
void BKE_tracking_track_path_clear(MovieTrackingTrack *track, int ref_frame, int action)
|
2011-11-07 12:55:18 +00:00
|
|
|
{
|
|
|
|
|
int a;
|
|
|
|
|
|
2012-03-25 23:19:21 +00:00
|
|
|
if (action == TRACK_CLEAR_REMAINED) {
|
|
|
|
|
a = 1;
|
|
|
|
|
|
|
|
|
|
while (a < track->markersnr) {
|
|
|
|
|
if (track->markers[a].framenr > ref_frame) {
|
|
|
|
|
track->markersnr = a;
|
2012-06-10 19:59:02 +00:00
|
|
|
track->markers = MEM_reallocN(track->markers, sizeof(MovieTrackingMarker) * track->markersnr);
|
2011-11-07 12:55:18 +00:00
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
a++;
|
|
|
|
|
}
|
|
|
|
|
|
2012-03-24 06:18:31 +00:00
|
|
|
if (track->markersnr)
|
2012-06-15 11:03:23 +00:00
|
|
|
tracking_marker_insert_disabled(track, &track->markers[track->markersnr - 1], FALSE, TRUE);
|
2012-03-24 06:18:31 +00:00
|
|
|
}
|
2012-03-25 23:19:21 +00:00
|
|
|
else if (action == TRACK_CLEAR_UPTO) {
|
2012-05-07 08:53:59 +00:00
|
|
|
a = track->markersnr - 1;
|
2012-03-25 23:19:21 +00:00
|
|
|
|
|
|
|
|
while (a >= 0) {
|
|
|
|
|
if (track->markers[a].framenr <= ref_frame) {
|
2012-05-07 08:53:59 +00:00
|
|
|
memmove(track->markers, track->markers + a, (track->markersnr - a) * sizeof(MovieTrackingMarker));
|
2011-11-07 12:55:18 +00:00
|
|
|
|
2012-05-07 08:53:59 +00:00
|
|
|
track->markersnr = track->markersnr - a;
|
2012-06-10 19:59:02 +00:00
|
|
|
track->markers = MEM_reallocN(track->markers, sizeof(MovieTrackingMarker) * track->markersnr);
|
2011-11-07 12:55:18 +00:00
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
a--;
|
|
|
|
|
}
|
|
|
|
|
|
2012-03-24 06:18:31 +00:00
|
|
|
if (track->markersnr)
|
2012-06-15 11:03:23 +00:00
|
|
|
tracking_marker_insert_disabled(track, &track->markers[0], TRUE, TRUE);
|
2012-03-24 06:18:31 +00:00
|
|
|
}
|
2012-03-25 23:19:21 +00:00
|
|
|
else if (action == TRACK_CLEAR_ALL) {
|
2011-11-07 12:55:18 +00:00
|
|
|
MovieTrackingMarker *marker, marker_new;
|
|
|
|
|
|
2012-06-15 11:03:23 +00:00
|
|
|
marker = BKE_tracking_marker_get(track, ref_frame);
|
2012-03-25 23:19:21 +00:00
|
|
|
marker_new = *marker;
|
2011-11-07 12:55:18 +00:00
|
|
|
|
|
|
|
|
MEM_freeN(track->markers);
|
2012-03-25 23:19:21 +00:00
|
|
|
track->markers = NULL;
|
|
|
|
|
track->markersnr = 0;
|
2011-11-07 12:55:18 +00:00
|
|
|
|
2012-06-15 11:03:23 +00:00
|
|
|
BKE_tracking_marker_insert(track, &marker_new);
|
2011-11-07 12:55:18 +00:00
|
|
|
|
2012-06-15 11:03:23 +00:00
|
|
|
tracking_marker_insert_disabled(track, &marker_new, TRUE, TRUE);
|
|
|
|
|
tracking_marker_insert_disabled(track, &marker_new, FALSE, TRUE);
|
2011-11-07 12:55:18 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2012-10-15 10:43:10 +00:00
|
|
|
void BKE_tracking_tracks_join(MovieTracking *tracking, MovieTrackingTrack *dst_track, MovieTrackingTrack *src_track)
|
2011-11-07 12:55:18 +00:00
|
|
|
{
|
2012-03-25 23:19:21 +00:00
|
|
|
int i = 0, a = 0, b = 0, tot;
|
2011-11-07 12:55:18 +00:00
|
|
|
MovieTrackingMarker *markers;
|
|
|
|
|
|
2012-03-25 23:19:21 +00:00
|
|
|
tot = dst_track->markersnr + src_track->markersnr;
|
|
|
|
|
markers = MEM_callocN(tot * sizeof(MovieTrackingMarker), "tmp tracking joined tracks");
|
2011-11-07 12:55:18 +00:00
|
|
|
|
2012-03-16 14:06:43 +00:00
|
|
|
while (a < src_track->markersnr || b < dst_track->markersnr) {
|
2012-03-25 23:19:21 +00:00
|
|
|
if (b >= dst_track->markersnr) {
|
|
|
|
|
markers[i] = src_track->markers[a++];
|
2011-11-07 12:55:18 +00:00
|
|
|
}
|
2012-03-25 23:19:21 +00:00
|
|
|
else if (a >= src_track->markersnr) {
|
|
|
|
|
markers[i] = dst_track->markers[b++];
|
2011-11-07 12:55:18 +00:00
|
|
|
}
|
2012-03-25 23:19:21 +00:00
|
|
|
else if (src_track->markers[a].framenr < dst_track->markers[b].framenr) {
|
|
|
|
|
markers[i] = src_track->markers[a++];
|
2012-03-24 06:18:31 +00:00
|
|
|
}
|
2012-03-25 23:19:21 +00:00
|
|
|
else if (src_track->markers[a].framenr > dst_track->markers[b].framenr) {
|
|
|
|
|
markers[i] = dst_track->markers[b++];
|
2012-03-24 06:18:31 +00:00
|
|
|
}
|
|
|
|
|
else {
|
2012-05-07 08:53:59 +00:00
|
|
|
if ((src_track->markers[a].flag & MARKER_DISABLED) == 0) {
|
|
|
|
|
if ((dst_track->markers[b].flag & MARKER_DISABLED) == 0) {
|
2012-03-21 17:21:27 +00:00
|
|
|
/* both tracks are enabled on this frame, so find the whole segment
|
|
|
|
|
* on which tracks are intersecting and blend tracks using linear
|
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
|
|
|
* interpolation to prevent jumps
|
|
|
|
|
*/
|
2012-03-16 14:06:43 +00:00
|
|
|
|
2012-03-21 17:21:27 +00:00
|
|
|
MovieTrackingMarker *marker_a, *marker_b;
|
|
|
|
|
int start_a = a, start_b = b, len = 0, frame = src_track->markers[a].framenr;
|
|
|
|
|
int j, inverse = 0;
|
|
|
|
|
|
|
|
|
|
inverse = (b == 0) ||
|
2012-05-07 08:53:59 +00:00
|
|
|
(dst_track->markers[b - 1].flag & MARKER_DISABLED) ||
|
|
|
|
|
(dst_track->markers[b - 1].framenr != frame - 1);
|
2012-03-21 17:21:27 +00:00
|
|
|
|
2012-03-25 23:19:21 +00:00
|
|
|
/* find length of intersection */
|
2012-03-21 17:21:27 +00:00
|
|
|
while (a < src_track->markersnr && b < dst_track->markersnr) {
|
|
|
|
|
marker_a = &src_track->markers[a];
|
|
|
|
|
marker_b = &dst_track->markers[b];
|
|
|
|
|
|
|
|
|
|
if (marker_a->flag & MARKER_DISABLED || marker_b->flag & MARKER_DISABLED)
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
if (marker_a->framenr != frame || marker_b->framenr != frame)
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
frame++;
|
|
|
|
|
len++;
|
|
|
|
|
a++;
|
|
|
|
|
b++;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
a = start_a;
|
|
|
|
|
b = start_b;
|
|
|
|
|
|
2012-03-25 23:19:21 +00:00
|
|
|
/* linear interpolation for intersecting frames */
|
2012-03-21 17:21:27 +00:00
|
|
|
for (j = 0; j < len; j++) {
|
|
|
|
|
float fac = 0.5f;
|
|
|
|
|
|
|
|
|
|
if (len > 1)
|
|
|
|
|
fac = 1.0f / (len - 1) * j;
|
|
|
|
|
|
|
|
|
|
if (inverse)
|
|
|
|
|
fac = 1.0f - fac;
|
|
|
|
|
|
|
|
|
|
marker_a = &src_track->markers[a];
|
|
|
|
|
marker_b = &dst_track->markers[b];
|
|
|
|
|
|
2012-03-25 23:19:21 +00:00
|
|
|
markers[i] = dst_track->markers[b];
|
2012-03-21 17:21:27 +00:00
|
|
|
interp_v2_v2v2(markers[i].pos, marker_b->pos, marker_a->pos, fac);
|
|
|
|
|
a++;
|
|
|
|
|
b++;
|
|
|
|
|
i++;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* this values will be incremented at the end of the loop cycle */
|
|
|
|
|
a--; b--; i--;
|
2012-03-16 14:06:43 +00:00
|
|
|
}
|
2012-06-15 11:03:23 +00:00
|
|
|
else {
|
|
|
|
|
markers[i] = src_track->markers[a];
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
markers[i] = dst_track->markers[b];
|
2012-03-16 14:06:43 +00:00
|
|
|
}
|
2011-11-07 12:55:18 +00:00
|
|
|
|
|
|
|
|
a++;
|
|
|
|
|
b++;
|
|
|
|
|
}
|
2012-03-16 14:06:43 +00:00
|
|
|
|
|
|
|
|
i++;
|
2011-11-07 12:55:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
MEM_freeN(dst_track->markers);
|
|
|
|
|
|
2012-06-10 19:59:02 +00:00
|
|
|
dst_track->markers = MEM_callocN(i * sizeof(MovieTrackingMarker), "tracking joined tracks");
|
|
|
|
|
memcpy(dst_track->markers, markers, i * sizeof(MovieTrackingMarker));
|
2012-03-16 14:06:43 +00:00
|
|
|
|
2012-03-25 23:19:21 +00:00
|
|
|
dst_track->markersnr = i;
|
2012-03-16 14:06:43 +00:00
|
|
|
|
|
|
|
|
MEM_freeN(markers);
|
2012-10-15 10:43:10 +00:00
|
|
|
|
|
|
|
|
BKE_tracking_dopesheet_tag_update(tracking);
|
2011-11-07 12:55:18 +00:00
|
|
|
}
|
|
|
|
|
|
2012-06-15 11:03:23 +00:00
|
|
|
MovieTrackingTrack *BKE_tracking_track_get_named(MovieTracking *tracking, MovieTrackingObject *object, const char *name)
|
2011-11-07 12:55:18 +00:00
|
|
|
{
|
2012-06-15 11:03:23 +00:00
|
|
|
ListBase *tracksbase = BKE_tracking_object_get_tracks(tracking, object);
|
|
|
|
|
MovieTrackingTrack *track = tracksbase->first;
|
2011-11-07 12:55:18 +00:00
|
|
|
|
2012-06-15 11:03:23 +00:00
|
|
|
while (track) {
|
|
|
|
|
if (!strcmp(track->name, name))
|
|
|
|
|
return track;
|
2011-12-05 18:57:17 +00:00
|
|
|
|
2012-06-15 11:03:23 +00:00
|
|
|
track = track->next;
|
|
|
|
|
}
|
2011-12-05 18:57:17 +00:00
|
|
|
|
2012-06-15 11:03:23 +00:00
|
|
|
return NULL;
|
2011-12-05 18:57:17 +00:00
|
|
|
}
|
|
|
|
|
|
2012-06-15 11:03:23 +00:00
|
|
|
MovieTrackingTrack *BKE_tracking_track_get_indexed(MovieTracking *tracking, int tracknr, ListBase **tracksbase_r)
|
2011-12-05 18:57:17 +00:00
|
|
|
{
|
|
|
|
|
MovieTrackingObject *object;
|
2012-06-15 11:03:23 +00:00
|
|
|
int cur = 1;
|
2011-12-05 18:57:17 +00:00
|
|
|
|
2012-06-15 11:03:23 +00:00
|
|
|
object = tracking->objects.first;
|
|
|
|
|
while (object) {
|
|
|
|
|
ListBase *tracksbase = BKE_tracking_object_get_tracks(tracking, object);
|
|
|
|
|
MovieTrackingTrack *track = tracksbase->first;
|
2011-11-07 12:55:18 +00:00
|
|
|
|
2012-06-15 11:03:23 +00:00
|
|
|
while (track) {
|
|
|
|
|
if (track->flag & TRACK_HAS_BUNDLE) {
|
|
|
|
|
if (cur == tracknr) {
|
|
|
|
|
*tracksbase_r = tracksbase;
|
|
|
|
|
return track;
|
|
|
|
|
}
|
2011-11-07 12:55:18 +00:00
|
|
|
|
2012-06-15 11:03:23 +00:00
|
|
|
cur++;
|
|
|
|
|
}
|
2012-05-03 17:52:34 +00:00
|
|
|
|
2012-06-15 11:03:23 +00:00
|
|
|
track = track->next;
|
2012-05-03 17:52:34 +00:00
|
|
|
}
|
|
|
|
|
|
2012-06-15 11:03:23 +00:00
|
|
|
object = object->next;
|
2012-05-03 17:52:34 +00:00
|
|
|
}
|
|
|
|
|
|
2012-06-15 11:03:23 +00:00
|
|
|
*tracksbase_r = NULL;
|
2012-05-03 17:52:34 +00:00
|
|
|
|
2012-06-15 11:03:23 +00:00
|
|
|
return NULL;
|
2012-04-30 16:19:20 +00:00
|
|
|
}
|
|
|
|
|
|
2012-06-15 11:03:23 +00:00
|
|
|
MovieTrackingTrack *BKE_tracking_track_get_active(MovieTracking *tracking)
|
2011-12-05 18:57:17 +00:00
|
|
|
{
|
2012-06-15 11:03:23 +00:00
|
|
|
ListBase *tracksbase;
|
2011-11-07 12:55:18 +00:00
|
|
|
|
2012-06-15 11:03:23 +00:00
|
|
|
if (!tracking->act_track)
|
|
|
|
|
return NULL;
|
2011-11-07 12:55:18 +00:00
|
|
|
|
2012-06-15 11:03:23 +00:00
|
|
|
tracksbase = BKE_tracking_get_active_tracks(tracking);
|
2012-04-30 16:19:20 +00:00
|
|
|
|
2012-06-15 11:03:23 +00:00
|
|
|
/* check that active track is in current tracks list */
|
|
|
|
|
if (BLI_findindex(tracksbase, tracking->act_track) >= 0)
|
|
|
|
|
return tracking->act_track;
|
|
|
|
|
|
|
|
|
|
return NULL;
|
2011-11-07 12:55:18 +00:00
|
|
|
}
|
|
|
|
|
|
2012-06-15 11:03:23 +00:00
|
|
|
static bGPDlayer *track_mask_gpencil_layer_get(MovieTrackingTrack *track)
|
2012-01-09 20:18:48 +00:00
|
|
|
{
|
2012-06-15 11:03:23 +00:00
|
|
|
bGPDlayer *layer;
|
2012-01-09 20:18:48 +00:00
|
|
|
|
2012-06-15 11:03:23 +00:00
|
|
|
if (!track->gpd)
|
|
|
|
|
return NULL;
|
2012-01-09 20:18:48 +00:00
|
|
|
|
2012-06-15 11:03:23 +00:00
|
|
|
layer = track->gpd->layers.first;
|
2012-01-09 20:18:48 +00:00
|
|
|
|
2012-06-15 11:03:23 +00:00
|
|
|
while (layer) {
|
|
|
|
|
if (layer->flag & GP_LAYER_ACTIVE) {
|
|
|
|
|
bGPDframe *frame = layer->frames.first;
|
|
|
|
|
int ok = FALSE;
|
2012-01-09 20:18:48 +00:00
|
|
|
|
2012-06-15 11:03:23 +00:00
|
|
|
while (frame) {
|
|
|
|
|
if (frame->strokes.first) {
|
|
|
|
|
ok = TRUE;
|
|
|
|
|
}
|
2012-05-03 17:02:33 +00:00
|
|
|
|
2012-06-15 11:03:23 +00:00
|
|
|
frame = frame->next;
|
|
|
|
|
}
|
2012-01-09 20:18:48 +00:00
|
|
|
|
2012-06-15 11:03:23 +00:00
|
|
|
if (ok)
|
|
|
|
|
return layer;
|
2012-01-09 20:18:48 +00:00
|
|
|
}
|
|
|
|
|
|
2012-06-15 11:03:23 +00:00
|
|
|
layer = layer->next;
|
2012-01-09 20:18:48 +00:00
|
|
|
}
|
|
|
|
|
|
2012-06-15 11:03:23 +00:00
|
|
|
return NULL;
|
2012-01-09 20:18:48 +00:00
|
|
|
}
|
|
|
|
|
|
2012-06-15 11:03:23 +00:00
|
|
|
static void track_mask_gpencil_layer_rasterize(int frame_width, int frame_height,
|
2012-06-15 16:07:23 +00:00
|
|
|
MovieTrackingMarker *marker, bGPDlayer *layer,
|
2012-06-15 11:03:23 +00:00
|
|
|
float *mask, int mask_width, int mask_height)
|
2012-01-09 20:18:48 +00:00
|
|
|
{
|
2012-06-15 11:03:23 +00:00
|
|
|
bGPDframe *frame = layer->frames.first;
|
2012-01-09 20:18:48 +00:00
|
|
|
|
2012-06-15 11:03:23 +00:00
|
|
|
while (frame) {
|
|
|
|
|
bGPDstroke *stroke = frame->strokes.first;
|
2012-01-09 20:18:48 +00:00
|
|
|
|
2012-06-15 11:03:23 +00:00
|
|
|
while (stroke) {
|
|
|
|
|
bGPDspoint *stroke_points = stroke->points;
|
|
|
|
|
float *mask_points, *fp;
|
|
|
|
|
int i;
|
2012-01-09 20:18:48 +00:00
|
|
|
|
2012-06-15 11:03:23 +00:00
|
|
|
if (stroke->flag & GP_STROKE_2DSPACE) {
|
|
|
|
|
fp = mask_points = MEM_callocN(2 * stroke->totpoints * sizeof(float),
|
|
|
|
|
"track mask rasterization points");
|
2011-11-07 12:55:18 +00:00
|
|
|
|
2012-06-15 11:03:23 +00:00
|
|
|
for (i = 0; i < stroke->totpoints; i++, fp += 2) {
|
|
|
|
|
fp[0] = (stroke_points[i].x - marker->search_min[0]) * frame_width / mask_width;
|
|
|
|
|
fp[1] = (stroke_points[i].y - marker->search_min[1]) * frame_height / mask_height;
|
|
|
|
|
}
|
2011-12-05 18:57:17 +00:00
|
|
|
|
2012-07-26 17:41:09 +00:00
|
|
|
/* TODO: add an option to control whether AA is enabled or not */
|
2012-09-15 23:05:34 +00:00
|
|
|
PLX_raskterize((float (*)[2])mask_points, stroke->totpoints, mask, mask_width, mask_height);
|
2011-11-27 19:17:59 +00:00
|
|
|
|
2012-06-15 11:03:23 +00:00
|
|
|
MEM_freeN(mask_points);
|
|
|
|
|
}
|
2011-11-27 19:17:59 +00:00
|
|
|
|
2012-06-15 11:03:23 +00:00
|
|
|
stroke = stroke->next;
|
|
|
|
|
}
|
2011-11-27 19:17:59 +00:00
|
|
|
|
2012-06-15 11:03:23 +00:00
|
|
|
frame = frame->next;
|
|
|
|
|
}
|
|
|
|
|
}
|
2011-11-27 19:17:59 +00:00
|
|
|
|
2012-06-15 11:03:23 +00:00
|
|
|
float *BKE_tracking_track_get_mask(int frame_width, int frame_height,
|
|
|
|
|
MovieTrackingTrack *track, MovieTrackingMarker *marker)
|
2011-11-27 19:17:59 +00:00
|
|
|
{
|
2012-06-15 11:03:23 +00:00
|
|
|
float *mask = NULL;
|
|
|
|
|
bGPDlayer *layer = track_mask_gpencil_layer_get(track);
|
|
|
|
|
int mask_width, mask_height;
|
2011-11-27 19:17:59 +00:00
|
|
|
|
2012-06-15 11:03:23 +00:00
|
|
|
mask_width = (marker->search_max[0] - marker->search_min[0]) * frame_width;
|
|
|
|
|
mask_height = (marker->search_max[1] - marker->search_min[1]) * frame_height;
|
2011-11-27 19:17:59 +00:00
|
|
|
|
2012-06-15 11:03:23 +00:00
|
|
|
if (layer) {
|
|
|
|
|
mask = MEM_callocN(mask_width * mask_height * sizeof(float), "track mask");
|
2011-11-27 19:17:59 +00:00
|
|
|
|
2012-06-15 11:03:23 +00:00
|
|
|
track_mask_gpencil_layer_rasterize(frame_width, frame_height, marker, layer,
|
|
|
|
|
mask, mask_width, mask_height);
|
|
|
|
|
}
|
2011-11-27 19:17:59 +00:00
|
|
|
|
2012-06-15 11:03:23 +00:00
|
|
|
return mask;
|
2011-11-27 19:17:59 +00:00
|
|
|
}
|
|
|
|
|
|
2012-06-15 11:03:23 +00:00
|
|
|
/* area - which part of marker should be selected. see TRACK_AREA_* constants */
|
|
|
|
|
void BKE_tracking_track_select(ListBase *tracksbase, MovieTrackingTrack *track, int area, int extend)
|
2011-11-27 19:17:59 +00:00
|
|
|
{
|
2012-06-15 11:03:23 +00:00
|
|
|
if (extend) {
|
|
|
|
|
BKE_tracking_track_flag_set(track, area, SELECT);
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
MovieTrackingTrack *cur = tracksbase->first;
|
2011-11-27 19:17:59 +00:00
|
|
|
|
2012-06-15 11:03:23 +00:00
|
|
|
while (cur) {
|
|
|
|
|
if ((cur->flag & TRACK_HIDDEN) == 0) {
|
|
|
|
|
if (cur == track) {
|
|
|
|
|
BKE_tracking_track_flag_clear(cur, TRACK_AREA_ALL, SELECT);
|
|
|
|
|
BKE_tracking_track_flag_set(cur, area, SELECT);
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
BKE_tracking_track_flag_clear(cur, TRACK_AREA_ALL, SELECT);
|
|
|
|
|
}
|
|
|
|
|
}
|
2011-11-27 19:17:59 +00:00
|
|
|
|
2012-06-15 11:03:23 +00:00
|
|
|
cur = cur->next;
|
|
|
|
|
}
|
|
|
|
|
}
|
2011-11-27 19:17:59 +00:00
|
|
|
}
|
|
|
|
|
|
2012-06-15 11:03:23 +00:00
|
|
|
void BKE_tracking_track_deselect(MovieTrackingTrack *track, int area)
|
2011-11-27 19:17:59 +00:00
|
|
|
{
|
2012-06-15 11:03:23 +00:00
|
|
|
BKE_tracking_track_flag_clear(track, area, SELECT);
|
|
|
|
|
}
|
2011-11-27 19:17:59 +00:00
|
|
|
|
2012-07-27 10:12:58 +00:00
|
|
|
/*********************** Marker *************************/
|
2011-11-27 19:17:59 +00:00
|
|
|
|
2012-06-15 11:03:23 +00:00
|
|
|
MovieTrackingMarker *BKE_tracking_marker_insert(MovieTrackingTrack *track, MovieTrackingMarker *marker)
|
|
|
|
|
{
|
|
|
|
|
MovieTrackingMarker *old_marker = NULL;
|
2011-11-27 19:17:59 +00:00
|
|
|
|
2012-06-15 11:03:23 +00:00
|
|
|
if (track->markersnr)
|
|
|
|
|
old_marker = BKE_tracking_marker_get_exact(track, marker->framenr);
|
2011-11-27 19:17:59 +00:00
|
|
|
|
2012-06-15 11:03:23 +00:00
|
|
|
if (old_marker) {
|
|
|
|
|
/* simply replace settings for already allocated marker */
|
|
|
|
|
*old_marker = *marker;
|
2011-11-27 19:17:59 +00:00
|
|
|
|
2012-06-15 11:03:23 +00:00
|
|
|
return old_marker;
|
2012-03-24 06:18:31 +00:00
|
|
|
}
|
|
|
|
|
else {
|
2012-06-15 11:03:23 +00:00
|
|
|
int a = track->markersnr;
|
2011-12-05 18:57:17 +00:00
|
|
|
|
2012-06-15 11:03:23 +00:00
|
|
|
/* find position in array where to add new marker */
|
|
|
|
|
while (a--) {
|
|
|
|
|
if (track->markers[a].framenr < marker->framenr)
|
|
|
|
|
break;
|
2011-12-05 18:57:17 +00:00
|
|
|
}
|
|
|
|
|
|
2012-06-15 11:03:23 +00:00
|
|
|
track->markersnr++;
|
2011-11-07 12:55:18 +00:00
|
|
|
|
2012-06-15 11:03:23 +00:00
|
|
|
if (track->markers)
|
|
|
|
|
track->markers = MEM_reallocN(track->markers, sizeof(MovieTrackingMarker) * track->markersnr);
|
|
|
|
|
else
|
|
|
|
|
track->markers = MEM_callocN(sizeof(MovieTrackingMarker), "MovieTracking markers");
|
2011-11-27 19:17:59 +00:00
|
|
|
|
2012-06-15 11:03:23 +00:00
|
|
|
/* shift array to "free" space for new marker */
|
|
|
|
|
memmove(track->markers + a + 2, track->markers + a + 1,
|
|
|
|
|
(track->markersnr - a - 2) * sizeof(MovieTrackingMarker));
|
2011-11-27 19:17:59 +00:00
|
|
|
|
2012-06-15 11:03:23 +00:00
|
|
|
/* put new marker */
|
|
|
|
|
track->markers[a + 1] = *marker;
|
2011-11-27 19:17:59 +00:00
|
|
|
|
2012-06-15 11:03:23 +00:00
|
|
|
track->last_marker = a + 1;
|
2011-11-27 19:17:59 +00:00
|
|
|
|
2012-06-15 11:03:23 +00:00
|
|
|
return &track->markers[a + 1];
|
|
|
|
|
}
|
|
|
|
|
}
|
2011-11-27 19:17:59 +00:00
|
|
|
|
2012-06-15 11:03:23 +00:00
|
|
|
void BKE_tracking_marker_delete(MovieTrackingTrack *track, int framenr)
|
|
|
|
|
{
|
|
|
|
|
int a = 0;
|
2011-11-27 19:17:59 +00:00
|
|
|
|
2012-06-15 11:03:23 +00:00
|
|
|
while (a < track->markersnr) {
|
|
|
|
|
if (track->markers[a].framenr == framenr) {
|
|
|
|
|
if (track->markersnr > 1) {
|
|
|
|
|
memmove(track->markers + a, track->markers + a + 1,
|
|
|
|
|
(track->markersnr - a - 1) * sizeof(MovieTrackingMarker));
|
|
|
|
|
track->markersnr--;
|
|
|
|
|
track->markers = MEM_reallocN(track->markers, sizeof(MovieTrackingMarker) * track->markersnr);
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
MEM_freeN(track->markers);
|
|
|
|
|
track->markers = NULL;
|
|
|
|
|
track->markersnr = 0;
|
2011-11-27 19:17:59 +00:00
|
|
|
}
|
|
|
|
|
|
2012-06-15 11:03:23 +00:00
|
|
|
break;
|
|
|
|
|
}
|
2011-11-27 19:17:59 +00:00
|
|
|
|
2012-06-15 11:03:23 +00:00
|
|
|
a++;
|
|
|
|
|
}
|
|
|
|
|
}
|
2011-11-27 19:17:59 +00:00
|
|
|
|
2012-06-15 11:03:23 +00:00
|
|
|
void BKE_tracking_marker_clamp(MovieTrackingMarker *marker, int event)
|
|
|
|
|
{
|
|
|
|
|
int a;
|
|
|
|
|
float pat_min[2], pat_max[2];
|
2011-11-27 19:17:59 +00:00
|
|
|
|
2012-06-15 11:03:23 +00:00
|
|
|
BKE_tracking_marker_pattern_minmax(marker, pat_min, pat_max);
|
2012-02-16 13:15:01 +00:00
|
|
|
|
2012-06-15 11:03:23 +00:00
|
|
|
if (event == CLAMP_PAT_DIM) {
|
|
|
|
|
for (a = 0; a < 2; a++) {
|
|
|
|
|
/* search shouldn't be resized smaller than pattern */
|
2012-10-23 13:28:22 +00:00
|
|
|
marker->search_min[a] = min_ff(pat_min[a], marker->search_min[a]);
|
|
|
|
|
marker->search_max[a] = max_ff(pat_max[a], marker->search_max[a]);
|
2012-06-15 11:03:23 +00:00
|
|
|
}
|
2011-11-27 19:17:59 +00:00
|
|
|
}
|
2012-06-15 11:03:23 +00:00
|
|
|
else if (event == CLAMP_PAT_POS) {
|
|
|
|
|
float dim[2];
|
2011-11-27 19:17:59 +00:00
|
|
|
|
2012-06-15 11:03:23 +00:00
|
|
|
sub_v2_v2v2(dim, pat_max, pat_min);
|
2011-11-27 19:17:59 +00:00
|
|
|
|
2012-06-15 11:03:23 +00:00
|
|
|
for (a = 0; a < 2; a++) {
|
|
|
|
|
int b;
|
|
|
|
|
/* pattern shouldn't be moved outside of search */
|
|
|
|
|
if (pat_min[a] < marker->search_min[a]) {
|
|
|
|
|
for (b = 0; b < 4; b++)
|
|
|
|
|
marker->pattern_corners[b][a] += marker->search_min[a] - pat_min[a];
|
|
|
|
|
}
|
|
|
|
|
if (pat_max[a] > marker->search_max[a]) {
|
|
|
|
|
for (b = 0; b < 4; b++)
|
|
|
|
|
marker->pattern_corners[b][a] -= pat_max[a] - marker->search_max[a];
|
|
|
|
|
}
|
|
|
|
|
}
|
2011-11-27 19:17:59 +00:00
|
|
|
}
|
2012-06-15 11:03:23 +00:00
|
|
|
else if (event == CLAMP_SEARCH_DIM) {
|
|
|
|
|
for (a = 0; a < 2; a++) {
|
|
|
|
|
/* search shouldn't be resized smaller than pattern */
|
2012-10-23 13:28:22 +00:00
|
|
|
marker->search_min[a] = min_ff(pat_min[a], marker->search_min[a]);
|
|
|
|
|
marker->search_max[a] = max_ff(pat_max[a], marker->search_max[a]);
|
2012-06-15 11:03:23 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else if (event == CLAMP_SEARCH_POS) {
|
|
|
|
|
float dim[2];
|
2011-11-27 19:17:59 +00:00
|
|
|
|
2012-06-15 11:03:23 +00:00
|
|
|
sub_v2_v2v2(dim, marker->search_max, marker->search_min);
|
2011-11-27 19:17:59 +00:00
|
|
|
|
2012-06-15 11:03:23 +00:00
|
|
|
for (a = 0; a < 2; a++) {
|
|
|
|
|
/* search shouldn't be moved inside pattern */
|
|
|
|
|
if (marker->search_min[a] > pat_min[a]) {
|
|
|
|
|
marker->search_min[a] = pat_min[a];
|
|
|
|
|
marker->search_max[a] = marker->search_min[a] + dim[a];
|
|
|
|
|
}
|
|
|
|
|
if (marker->search_max[a] < pat_max[a]) {
|
|
|
|
|
marker->search_max[a] = pat_max[a];
|
|
|
|
|
marker->search_min[a] = marker->search_max[a] - dim[a];
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2011-11-27 19:17:59 +00:00
|
|
|
}
|
|
|
|
|
|
2012-06-15 11:03:23 +00:00
|
|
|
MovieTrackingMarker *BKE_tracking_marker_get(MovieTrackingTrack *track, int framenr)
|
2011-11-27 19:17:59 +00:00
|
|
|
{
|
2012-06-15 11:03:23 +00:00
|
|
|
int a = track->markersnr - 1;
|
2011-11-27 19:17:59 +00:00
|
|
|
|
2012-06-15 11:03:23 +00:00
|
|
|
if (!track->markersnr)
|
|
|
|
|
return NULL;
|
2011-11-27 19:17:59 +00:00
|
|
|
|
2012-06-15 11:03:23 +00:00
|
|
|
/* approximate pre-first framenr marker with first marker */
|
|
|
|
|
if (framenr < track->markers[0].framenr)
|
|
|
|
|
return &track->markers[0];
|
2011-11-27 19:17:59 +00:00
|
|
|
|
2012-06-15 11:03:23 +00:00
|
|
|
if (track->last_marker < track->markersnr)
|
|
|
|
|
a = track->last_marker;
|
2011-11-27 19:17:59 +00:00
|
|
|
|
2012-06-15 11:03:23 +00:00
|
|
|
if (track->markers[a].framenr <= framenr) {
|
|
|
|
|
while (a < track->markersnr && track->markers[a].framenr <= framenr) {
|
|
|
|
|
if (track->markers[a].framenr == framenr) {
|
|
|
|
|
track->last_marker = a;
|
2011-11-27 19:17:59 +00:00
|
|
|
|
2012-06-15 11:03:23 +00:00
|
|
|
return &track->markers[a];
|
|
|
|
|
}
|
|
|
|
|
a++;
|
|
|
|
|
}
|
2011-11-27 19:17:59 +00:00
|
|
|
|
2012-06-15 11:03:23 +00:00
|
|
|
/* if there's no marker for exact position, use nearest marker from left side */
|
|
|
|
|
return &track->markers[a - 1];
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
while (a >= 0 && track->markers[a].framenr >= framenr) {
|
|
|
|
|
if (track->markers[a].framenr == framenr) {
|
|
|
|
|
track->last_marker = a;
|
2011-11-27 19:17:59 +00:00
|
|
|
|
2012-06-15 11:03:23 +00:00
|
|
|
return &track->markers[a];
|
|
|
|
|
}
|
2011-11-07 12:55:18 +00:00
|
|
|
|
2012-06-15 11:03:23 +00:00
|
|
|
a--;
|
|
|
|
|
}
|
2012-06-12 11:13:53 +00:00
|
|
|
|
2012-06-15 11:03:23 +00:00
|
|
|
/* if there's no marker for exact position, use nearest marker from left side */
|
|
|
|
|
return &track->markers[a];
|
|
|
|
|
}
|
2011-11-07 12:55:18 +00:00
|
|
|
|
2012-06-15 11:03:23 +00:00
|
|
|
return NULL;
|
|
|
|
|
}
|
2011-11-07 12:55:18 +00:00
|
|
|
|
2012-06-15 11:03:23 +00:00
|
|
|
MovieTrackingMarker *BKE_tracking_marker_get_exact(MovieTrackingTrack *track, int framenr)
|
|
|
|
|
{
|
|
|
|
|
MovieTrackingMarker *marker = BKE_tracking_marker_get(track, framenr);
|
2011-11-07 12:55:18 +00:00
|
|
|
|
2012-06-15 11:03:23 +00:00
|
|
|
if (marker->framenr != framenr)
|
|
|
|
|
return NULL;
|
2011-11-07 12:55:18 +00:00
|
|
|
|
2012-06-15 11:03:23 +00:00
|
|
|
return marker;
|
|
|
|
|
}
|
2011-11-07 12:55:18 +00:00
|
|
|
|
2012-06-15 11:03:23 +00:00
|
|
|
MovieTrackingMarker *BKE_tracking_marker_ensure(MovieTrackingTrack *track, int framenr)
|
2011-11-07 12:55:18 +00:00
|
|
|
{
|
2012-06-15 11:03:23 +00:00
|
|
|
MovieTrackingMarker *marker = BKE_tracking_marker_get(track, framenr);
|
2011-11-07 12:55:18 +00:00
|
|
|
|
2012-06-15 11:03:23 +00:00
|
|
|
if (marker->framenr != framenr) {
|
|
|
|
|
MovieTrackingMarker marker_new;
|
2011-11-07 12:55:18 +00:00
|
|
|
|
2012-06-15 11:03:23 +00:00
|
|
|
marker_new = *marker;
|
|
|
|
|
marker_new.framenr = framenr;
|
2011-11-07 12:55:18 +00:00
|
|
|
|
2012-06-15 11:03:23 +00:00
|
|
|
BKE_tracking_marker_insert(track, &marker_new);
|
|
|
|
|
marker = BKE_tracking_marker_get(track, framenr);
|
2011-11-07 12:55:18 +00:00
|
|
|
}
|
|
|
|
|
|
2012-06-15 11:03:23 +00:00
|
|
|
return marker;
|
|
|
|
|
}
|
2011-11-07 12:55:18 +00:00
|
|
|
|
2012-06-15 11:03:23 +00:00
|
|
|
void BKE_tracking_marker_pattern_minmax(const MovieTrackingMarker *marker, float min[2], float max[2])
|
|
|
|
|
{
|
|
|
|
|
INIT_MINMAX2(min, max);
|
2011-11-27 19:17:59 +00:00
|
|
|
|
2012-11-15 22:20:18 +00:00
|
|
|
minmax_v2v2_v2(min, max, marker->pattern_corners[0]);
|
|
|
|
|
minmax_v2v2_v2(min, max, marker->pattern_corners[1]);
|
|
|
|
|
minmax_v2v2_v2(min, max, marker->pattern_corners[2]);
|
|
|
|
|
minmax_v2v2_v2(min, max, marker->pattern_corners[3]);
|
2012-06-15 11:03:23 +00:00
|
|
|
}
|
2011-11-07 12:55:18 +00:00
|
|
|
|
2012-07-27 10:12:58 +00:00
|
|
|
void BKE_tracking_marker_get_subframe_position(MovieTrackingTrack *track, float framenr, float pos[2])
|
|
|
|
|
{
|
|
|
|
|
MovieTrackingMarker *marker = BKE_tracking_marker_get(track, (int) framenr);
|
|
|
|
|
MovieTrackingMarker *marker_last = track->markers + (track->markersnr - 1);
|
|
|
|
|
|
|
|
|
|
if (marker != marker_last) {
|
|
|
|
|
MovieTrackingMarker *marker_next = marker + 1;
|
|
|
|
|
|
|
|
|
|
if (marker_next->framenr == marker->framenr + 1) {
|
|
|
|
|
/* currently only do subframing inside tracked ranges, do not extrapolate tracked segments
|
|
|
|
|
* could be changed when / if mask parent would be interpolating position in-between
|
|
|
|
|
* tracked segments
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
float fac = (framenr - (int) framenr) / (marker_next->framenr - marker->framenr);
|
|
|
|
|
|
|
|
|
|
interp_v2_v2v2(pos, marker->pos, marker_next->pos, fac);
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
copy_v2_v2(pos, marker->pos);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
copy_v2_v2(pos, marker->pos);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* currently track offset is always wanted to be applied here, could be made an option later */
|
|
|
|
|
add_v2_v2(pos, track->offset);
|
|
|
|
|
}
|
|
|
|
|
|
2012-06-15 11:03:23 +00:00
|
|
|
/*********************** Object *************************/
|
2011-11-07 12:55:18 +00:00
|
|
|
|
2012-06-15 11:03:23 +00:00
|
|
|
MovieTrackingObject *BKE_tracking_object_add(MovieTracking *tracking, const char *name)
|
|
|
|
|
{
|
|
|
|
|
MovieTrackingObject *object = MEM_callocN(sizeof(MovieTrackingObject), "tracking object");
|
2011-11-07 12:55:18 +00:00
|
|
|
|
2012-06-15 11:03:23 +00:00
|
|
|
if (tracking->tot_object == 0) {
|
|
|
|
|
/* first object is always camera */
|
|
|
|
|
BLI_strncpy(object->name, "Camera", sizeof(object->name));
|
|
|
|
|
|
|
|
|
|
object->flag |= TRACKING_OBJECT_CAMERA;
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
BLI_strncpy(object->name, name, sizeof(object->name));
|
2011-11-07 12:55:18 +00:00
|
|
|
}
|
|
|
|
|
|
2012-06-15 11:03:23 +00:00
|
|
|
BLI_addtail(&tracking->objects, object);
|
2011-12-27 10:52:23 +00:00
|
|
|
|
2012-06-15 11:03:23 +00:00
|
|
|
tracking->tot_object++;
|
|
|
|
|
tracking->objectnr = BLI_countlist(&tracking->objects) - 1;
|
2011-12-27 10:52:23 +00:00
|
|
|
|
2012-06-15 11:03:23 +00:00
|
|
|
object->scale = 1.0f;
|
2012-10-09 10:33:18 +00:00
|
|
|
object->keyframe1 = 1;
|
|
|
|
|
object->keyframe2 = 30;
|
2011-11-07 12:55:18 +00:00
|
|
|
|
2012-06-15 11:03:23 +00:00
|
|
|
BKE_tracking_object_unique_name(tracking, object);
|
2011-12-13 10:07:22 +00:00
|
|
|
|
2012-06-15 11:03:23 +00:00
|
|
|
return object;
|
2011-11-07 12:55:18 +00:00
|
|
|
}
|
|
|
|
|
|
2012-11-02 09:41:26 +00:00
|
|
|
int BKE_tracking_object_delete(MovieTracking *tracking, MovieTrackingObject *object)
|
2011-11-07 12:55:18 +00:00
|
|
|
{
|
2012-06-15 11:03:23 +00:00
|
|
|
MovieTrackingTrack *track;
|
|
|
|
|
int index = BLI_findindex(&tracking->objects, object);
|
2011-11-07 12:55:18 +00:00
|
|
|
|
2012-11-02 09:41:26 +00:00
|
|
|
if (index == -1)
|
|
|
|
|
return FALSE;
|
2011-11-07 12:55:18 +00:00
|
|
|
|
2012-06-15 11:03:23 +00:00
|
|
|
if (object->flag & TRACKING_OBJECT_CAMERA) {
|
|
|
|
|
/* object used for camera solving can't be deleted */
|
2012-11-02 09:41:26 +00:00
|
|
|
return FALSE;
|
2012-06-15 11:03:23 +00:00
|
|
|
}
|
2012-06-12 11:13:53 +00:00
|
|
|
|
2012-06-15 11:03:23 +00:00
|
|
|
track = object->tracks.first;
|
|
|
|
|
while (track) {
|
|
|
|
|
if (track == tracking->act_track)
|
|
|
|
|
tracking->act_track = NULL;
|
2011-11-07 12:55:18 +00:00
|
|
|
|
2012-06-15 11:03:23 +00:00
|
|
|
track = track->next;
|
|
|
|
|
}
|
2011-12-13 10:07:22 +00:00
|
|
|
|
2012-06-15 11:03:23 +00:00
|
|
|
tracking_object_free(object);
|
|
|
|
|
BLI_freelinkN(&tracking->objects, object);
|
2011-11-07 12:55:18 +00:00
|
|
|
|
2012-06-15 11:03:23 +00:00
|
|
|
tracking->tot_object--;
|
|
|
|
|
|
2012-11-02 09:41:26 +00:00
|
|
|
if (index != 0)
|
2012-06-15 11:03:23 +00:00
|
|
|
tracking->objectnr = index - 1;
|
|
|
|
|
else
|
|
|
|
|
tracking->objectnr = 0;
|
2012-11-02 09:41:26 +00:00
|
|
|
return TRUE;
|
2011-11-07 12:55:18 +00:00
|
|
|
}
|
|
|
|
|
|
2012-06-15 11:03:23 +00:00
|
|
|
void BKE_tracking_object_unique_name(MovieTracking *tracking, MovieTrackingObject *object)
|
2011-11-07 12:55:18 +00:00
|
|
|
{
|
2012-06-15 11:03:23 +00:00
|
|
|
BLI_uniquename(&tracking->objects, object, "Object", '.',
|
|
|
|
|
offsetof(MovieTrackingObject, name), sizeof(object->name));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
MovieTrackingObject *BKE_tracking_object_get_named(MovieTracking *tracking, const char *name)
|
|
|
|
|
{
|
|
|
|
|
MovieTrackingObject *object = tracking->objects.first;
|
|
|
|
|
|
|
|
|
|
while (object) {
|
|
|
|
|
if (!strcmp(object->name, name))
|
|
|
|
|
return object;
|
|
|
|
|
|
|
|
|
|
object = object->next;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
MovieTrackingObject *BKE_tracking_object_get_active(MovieTracking *tracking)
|
|
|
|
|
{
|
|
|
|
|
return BLI_findlink(&tracking->objects, tracking->objectnr);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
MovieTrackingObject *BKE_tracking_object_get_camera(MovieTracking *tracking)
|
|
|
|
|
{
|
|
|
|
|
MovieTrackingObject *object = tracking->objects.first;
|
|
|
|
|
|
|
|
|
|
while (object) {
|
|
|
|
|
if (object->flag & TRACKING_OBJECT_CAMERA)
|
|
|
|
|
return object;
|
|
|
|
|
|
|
|
|
|
object = object->next;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ListBase *BKE_tracking_object_get_tracks(MovieTracking *tracking, MovieTrackingObject *object)
|
|
|
|
|
{
|
|
|
|
|
if (object->flag & TRACKING_OBJECT_CAMERA) {
|
|
|
|
|
return &tracking->tracks;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return &object->tracks;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
MovieTrackingReconstruction *BKE_tracking_object_get_reconstruction(MovieTracking *tracking,
|
|
|
|
|
MovieTrackingObject *object)
|
|
|
|
|
{
|
|
|
|
|
if (object->flag & TRACKING_OBJECT_CAMERA) {
|
|
|
|
|
return &tracking->reconstruction;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return &object->reconstruction;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*********************** Camera *************************/
|
|
|
|
|
|
|
|
|
|
static int reconstructed_camera_index_get(MovieTrackingReconstruction *reconstruction, int framenr, int nearest)
|
|
|
|
|
{
|
|
|
|
|
MovieReconstructedCamera *cameras = reconstruction->cameras;
|
|
|
|
|
int a = 0, d = 1;
|
|
|
|
|
|
|
|
|
|
if (!reconstruction->camnr)
|
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
|
|
if (framenr < cameras[0].framenr) {
|
|
|
|
|
if (nearest)
|
|
|
|
|
return 0;
|
|
|
|
|
else
|
|
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (framenr > cameras[reconstruction->camnr - 1].framenr) {
|
|
|
|
|
if (nearest)
|
|
|
|
|
return reconstruction->camnr - 1;
|
|
|
|
|
else
|
|
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (reconstruction->last_camera < reconstruction->camnr)
|
|
|
|
|
a = reconstruction->last_camera;
|
|
|
|
|
|
|
|
|
|
if (cameras[a].framenr >= framenr)
|
|
|
|
|
d = -1;
|
|
|
|
|
|
|
|
|
|
while (a >= 0 && a < reconstruction->camnr) {
|
|
|
|
|
int cfra = cameras[a].framenr;
|
|
|
|
|
|
|
|
|
|
/* check if needed framenr was "skipped" -- no data for requested frame */
|
|
|
|
|
|
|
|
|
|
if (d > 0 && cfra > framenr) {
|
|
|
|
|
/* interpolate with previous position */
|
|
|
|
|
if (nearest)
|
|
|
|
|
return a - 1;
|
|
|
|
|
else
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (d < 0 && cfra < framenr) {
|
|
|
|
|
/* interpolate with next position */
|
|
|
|
|
if (nearest)
|
|
|
|
|
return a;
|
|
|
|
|
else
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (cfra == framenr) {
|
|
|
|
|
reconstruction->last_camera = a;
|
|
|
|
|
|
|
|
|
|
return a;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
a += d;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void reconstructed_camera_scale_set(MovieTrackingObject *object, float mat[4][4])
|
|
|
|
|
{
|
|
|
|
|
if ((object->flag & TRACKING_OBJECT_CAMERA) == 0) {
|
|
|
|
|
float smat[4][4];
|
|
|
|
|
|
|
|
|
|
scale_m4_fl(smat, 1.0f / object->scale);
|
|
|
|
|
mult_m4_m4m4(mat, mat, smat);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* converts principal offset from center to offset of blender's camera */
|
|
|
|
|
void BKE_tracking_camera_shift_get(MovieTracking *tracking, int winx, int winy, float *shiftx, float *shifty)
|
|
|
|
|
{
|
|
|
|
|
/* indeed in both of cases it should be winx -- it's just how camera shift works for blender's camera */
|
|
|
|
|
*shiftx = (0.5f * winx - tracking->camera.principal[0]) / winx;
|
|
|
|
|
*shifty = (0.5f * winy - tracking->camera.principal[1]) / winx;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void BKE_tracking_camera_to_blender(MovieTracking *tracking, Scene *scene, Camera *camera, int width, int height)
|
|
|
|
|
{
|
|
|
|
|
float focal = tracking->camera.focal;
|
|
|
|
|
|
|
|
|
|
camera->sensor_x = tracking->camera.sensor_width;
|
|
|
|
|
camera->sensor_fit = CAMERA_SENSOR_FIT_AUTO;
|
|
|
|
|
camera->lens = focal * camera->sensor_x / width;
|
|
|
|
|
|
|
|
|
|
scene->r.xsch = width * tracking->camera.pixel_aspect;
|
|
|
|
|
scene->r.ysch = height;
|
|
|
|
|
|
|
|
|
|
scene->r.xasp = 1.0f;
|
|
|
|
|
scene->r.yasp = 1.0f;
|
|
|
|
|
|
|
|
|
|
BKE_tracking_camera_shift_get(tracking, width, height, &camera->shiftx, &camera->shifty);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
MovieReconstructedCamera *BKE_tracking_camera_get_reconstructed(MovieTracking *tracking,
|
|
|
|
|
MovieTrackingObject *object, int framenr)
|
|
|
|
|
{
|
|
|
|
|
MovieTrackingReconstruction *reconstruction;
|
|
|
|
|
int a;
|
|
|
|
|
|
|
|
|
|
reconstruction = BKE_tracking_object_get_reconstruction(tracking, object);
|
|
|
|
|
a = reconstructed_camera_index_get(reconstruction, framenr, FALSE);
|
|
|
|
|
|
|
|
|
|
if (a == -1)
|
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
|
|
return &reconstruction->cameras[a];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void BKE_tracking_camera_get_reconstructed_interpolate(MovieTracking *tracking, MovieTrackingObject *object,
|
|
|
|
|
int framenr, float mat[4][4])
|
|
|
|
|
{
|
|
|
|
|
MovieTrackingReconstruction *reconstruction;
|
|
|
|
|
MovieReconstructedCamera *cameras;
|
|
|
|
|
int a;
|
|
|
|
|
|
|
|
|
|
reconstruction = BKE_tracking_object_get_reconstruction(tracking, object);
|
|
|
|
|
cameras = reconstruction->cameras;
|
|
|
|
|
a = reconstructed_camera_index_get(reconstruction, framenr, 1);
|
|
|
|
|
|
|
|
|
|
if (a == -1) {
|
|
|
|
|
unit_m4(mat);
|
2011-11-07 12:55:18 +00:00
|
|
|
|
|
|
|
|
return;
|
2012-06-15 11:03:23 +00:00
|
|
|
}
|
2011-11-07 12:55:18 +00:00
|
|
|
|
2012-06-15 11:03:23 +00:00
|
|
|
if (cameras[a].framenr != framenr && a > 0 && a < reconstruction->camnr - 1) {
|
|
|
|
|
float t = ((float)framenr - cameras[a].framenr) / (cameras[a + 1].framenr - cameras[a].framenr);
|
2011-12-04 06:02:09 +00:00
|
|
|
|
2012-06-15 11:03:23 +00:00
|
|
|
blend_m4_m4m4(mat, cameras[a].mat, cameras[a + 1].mat, t);
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
copy_m4_m4(mat, cameras[a].mat);
|
|
|
|
|
}
|
2011-11-07 12:55:18 +00:00
|
|
|
|
2012-06-15 11:03:23 +00:00
|
|
|
reconstructed_camera_scale_set(object, mat);
|
|
|
|
|
}
|
2012-03-25 23:19:21 +00:00
|
|
|
|
2012-06-15 11:03:23 +00:00
|
|
|
/*********************** Distortion/Undistortion *************************/
|
2012-03-25 23:19:21 +00:00
|
|
|
|
2012-12-10 16:38:28 +00:00
|
|
|
#ifdef WITH_LIBMV
|
|
|
|
|
static void cameraIntrinscisOptionsFromTracking(libmv_cameraIntrinsicsOptions *camera_intrinsics_options,
|
|
|
|
|
MovieTracking *tracking, int calibration_width, int calibration_height)
|
|
|
|
|
{
|
|
|
|
|
MovieTrackingCamera *camera = &tracking->camera;
|
|
|
|
|
float aspy = 1.0f / tracking->camera.pixel_aspect;
|
|
|
|
|
|
|
|
|
|
camera_intrinsics_options->focal_length = camera->focal;
|
|
|
|
|
|
|
|
|
|
camera_intrinsics_options->principal_point_x = camera->principal[0];
|
|
|
|
|
camera_intrinsics_options->principal_point_y = camera->principal[1] * aspy;
|
|
|
|
|
|
|
|
|
|
camera_intrinsics_options->k1 = camera->k1;
|
|
|
|
|
camera_intrinsics_options->k2 = camera->k2;
|
|
|
|
|
camera_intrinsics_options->k3 = camera->k3;
|
|
|
|
|
|
|
|
|
|
camera_intrinsics_options->image_width = calibration_width;
|
|
|
|
|
camera_intrinsics_options->image_height = (double) calibration_height * aspy;
|
|
|
|
|
}
|
|
|
|
|
#endif
|
|
|
|
|
|
2012-06-15 11:03:23 +00:00
|
|
|
MovieDistortion *BKE_tracking_distortion_new(void)
|
|
|
|
|
{
|
|
|
|
|
MovieDistortion *distortion;
|
|
|
|
|
|
|
|
|
|
distortion = MEM_callocN(sizeof(MovieDistortion), "BKE_tracking_distortion_create");
|
|
|
|
|
|
|
|
|
|
return distortion;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void BKE_tracking_distortion_update(MovieDistortion *distortion, MovieTracking *tracking,
|
|
|
|
|
int calibration_width, int calibration_height)
|
|
|
|
|
{
|
|
|
|
|
#ifdef WITH_LIBMV
|
2012-12-10 16:38:28 +00:00
|
|
|
libmv_cameraIntrinsicsOptions camera_intrinsics_options;
|
|
|
|
|
|
|
|
|
|
cameraIntrinscisOptionsFromTracking(&camera_intrinsics_options, tracking,
|
|
|
|
|
calibration_width, calibration_height);
|
|
|
|
|
|
2012-06-15 11:03:23 +00:00
|
|
|
if (!distortion->intrinsics) {
|
2012-12-10 16:38:28 +00:00
|
|
|
distortion->intrinsics = libmv_CameraIntrinsicsNew(&camera_intrinsics_options);
|
2012-06-15 11:03:23 +00:00
|
|
|
}
|
|
|
|
|
else {
|
2012-12-10 16:38:28 +00:00
|
|
|
libmv_CameraIntrinsicsUpdate(distortion->intrinsics, &camera_intrinsics_options);
|
2012-06-15 11:03:23 +00:00
|
|
|
}
|
|
|
|
|
#else
|
|
|
|
|
(void) distortion;
|
2013-02-25 13:15:42 +00:00
|
|
|
(void) tracking;
|
2012-06-15 14:40:01 +00:00
|
|
|
(void) calibration_width;
|
|
|
|
|
(void) calibration_height;
|
2012-06-15 11:03:23 +00:00
|
|
|
#endif
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
MovieDistortion *BKE_tracking_distortion_copy(MovieDistortion *distortion)
|
|
|
|
|
{
|
|
|
|
|
MovieDistortion *new_distortion;
|
|
|
|
|
|
|
|
|
|
new_distortion = MEM_callocN(sizeof(MovieDistortion), "BKE_tracking_distortion_create");
|
|
|
|
|
|
|
|
|
|
#ifdef WITH_LIBMV
|
|
|
|
|
new_distortion->intrinsics = libmv_CameraIntrinsicsCopy(distortion->intrinsics);
|
|
|
|
|
#else
|
|
|
|
|
(void) distortion;
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
return new_distortion;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ImBuf *BKE_tracking_distortion_exec(MovieDistortion *distortion, MovieTracking *tracking, ImBuf *ibuf,
|
|
|
|
|
int calibration_width, int calibration_height, float overscan, int undistort)
|
|
|
|
|
{
|
|
|
|
|
ImBuf *resibuf;
|
|
|
|
|
|
|
|
|
|
BKE_tracking_distortion_update(distortion, tracking, calibration_width, calibration_height);
|
|
|
|
|
|
|
|
|
|
resibuf = IMB_dupImBuf(ibuf);
|
|
|
|
|
|
|
|
|
|
#ifdef WITH_LIBMV
|
|
|
|
|
if (ibuf->rect_float) {
|
|
|
|
|
if (undistort) {
|
|
|
|
|
libmv_CameraIntrinsicsUndistortFloat(distortion->intrinsics,
|
|
|
|
|
ibuf->rect_float, resibuf->rect_float,
|
|
|
|
|
ibuf->x, ibuf->y, overscan, ibuf->channels);
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
libmv_CameraIntrinsicsDistortFloat(distortion->intrinsics,
|
|
|
|
|
ibuf->rect_float, resibuf->rect_float,
|
|
|
|
|
ibuf->x, ibuf->y, overscan, ibuf->channels);
|
|
|
|
|
}
|
|
|
|
|
|
2012-10-15 07:47:38 +00:00
|
|
|
if (ibuf->rect)
|
|
|
|
|
imb_freerectImBuf(ibuf);
|
2012-06-15 11:03:23 +00:00
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
if (undistort) {
|
|
|
|
|
libmv_CameraIntrinsicsUndistortByte(distortion->intrinsics,
|
|
|
|
|
(unsigned char *)ibuf->rect, (unsigned char *)resibuf->rect,
|
|
|
|
|
ibuf->x, ibuf->y, overscan, ibuf->channels);
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
libmv_CameraIntrinsicsDistortByte(distortion->intrinsics,
|
|
|
|
|
(unsigned char *)ibuf->rect, (unsigned char *)resibuf->rect,
|
|
|
|
|
ibuf->x, ibuf->y, overscan, ibuf->channels);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
#else
|
|
|
|
|
(void) overscan;
|
|
|
|
|
(void) undistort;
|
|
|
|
|
|
2012-10-15 07:47:38 +00:00
|
|
|
if (ibuf->rect_float && ibuf->rect)
|
|
|
|
|
imb_freerectImBuf(ibuf);
|
2012-06-15 11:03:23 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
return resibuf;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void BKE_tracking_distortion_free(MovieDistortion *distortion)
|
|
|
|
|
{
|
|
|
|
|
#ifdef WITH_LIBMV
|
|
|
|
|
libmv_CameraIntrinsicsDestroy(distortion->intrinsics);
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
MEM_freeN(distortion);
|
|
|
|
|
}
|
|
|
|
|
|
2012-07-31 22:01:44 +00:00
|
|
|
void BKE_tracking_distort_v2(MovieTracking *tracking, const float co[2], float r_co[2])
|
2012-06-15 11:03:23 +00:00
|
|
|
{
|
|
|
|
|
MovieTrackingCamera *camera = &tracking->camera;
|
|
|
|
|
|
|
|
|
|
#ifdef WITH_LIBMV
|
2012-12-10 16:38:28 +00:00
|
|
|
libmv_cameraIntrinsicsOptions camera_intrinsics_options;
|
2012-06-15 11:03:23 +00:00
|
|
|
double x, y;
|
|
|
|
|
float aspy = 1.0f / tracking->camera.pixel_aspect;
|
|
|
|
|
|
2012-12-10 16:38:28 +00:00
|
|
|
cameraIntrinscisOptionsFromTracking(&camera_intrinsics_options, tracking, 0, 0);
|
|
|
|
|
|
2012-06-15 11:03:23 +00:00
|
|
|
/* normalize coords */
|
|
|
|
|
x = (co[0] - camera->principal[0]) / camera->focal;
|
|
|
|
|
y = (co[1] - camera->principal[1] * aspy) / camera->focal;
|
|
|
|
|
|
2012-12-10 16:38:28 +00:00
|
|
|
libmv_applyCameraIntrinsics(&camera_intrinsics_options, x, y, &x, &y);
|
2012-06-15 11:03:23 +00:00
|
|
|
|
|
|
|
|
/* result is in image coords already */
|
2012-07-31 22:01:44 +00:00
|
|
|
r_co[0] = x;
|
|
|
|
|
r_co[1] = y;
|
2012-06-15 11:03:23 +00:00
|
|
|
#else
|
|
|
|
|
(void) camera;
|
|
|
|
|
(void) co;
|
2012-07-31 22:01:44 +00:00
|
|
|
zero_v2(r_co);
|
2012-06-15 11:03:23 +00:00
|
|
|
#endif
|
|
|
|
|
}
|
|
|
|
|
|
2012-07-31 22:01:44 +00:00
|
|
|
void BKE_tracking_undistort_v2(MovieTracking *tracking, const float co[2], float r_co[2])
|
2012-06-15 11:03:23 +00:00
|
|
|
{
|
|
|
|
|
MovieTrackingCamera *camera = &tracking->camera;
|
|
|
|
|
|
|
|
|
|
#ifdef WITH_LIBMV
|
2012-12-10 16:38:28 +00:00
|
|
|
libmv_cameraIntrinsicsOptions camera_intrinsics_options;
|
2012-06-15 11:03:23 +00:00
|
|
|
double x = co[0], y = co[1];
|
|
|
|
|
float aspy = 1.0f / tracking->camera.pixel_aspect;
|
|
|
|
|
|
2012-12-10 16:38:28 +00:00
|
|
|
cameraIntrinscisOptionsFromTracking(&camera_intrinsics_options, tracking, 0, 0);
|
|
|
|
|
|
|
|
|
|
libmv_InvertIntrinsics(&camera_intrinsics_options, x, y, &x, &y);
|
2012-06-15 11:03:23 +00:00
|
|
|
|
2012-07-31 22:01:44 +00:00
|
|
|
r_co[0] = x * camera->focal + camera->principal[0];
|
|
|
|
|
r_co[1] = y * camera->focal + camera->principal[1] * aspy;
|
2012-06-15 11:03:23 +00:00
|
|
|
#else
|
|
|
|
|
(void) camera;
|
|
|
|
|
(void) co;
|
2012-07-31 22:01:44 +00:00
|
|
|
zero_v2(r_co);
|
2012-06-15 11:03:23 +00:00
|
|
|
#endif
|
|
|
|
|
}
|
2012-03-25 23:19:21 +00:00
|
|
|
|
2012-06-15 11:03:23 +00:00
|
|
|
ImBuf *BKE_tracking_undistort_frame(MovieTracking *tracking, ImBuf *ibuf, int calibration_width,
|
|
|
|
|
int calibration_height, float overscan)
|
|
|
|
|
{
|
|
|
|
|
MovieTrackingCamera *camera = &tracking->camera;
|
2012-03-25 23:19:21 +00:00
|
|
|
|
2012-06-15 11:03:23 +00:00
|
|
|
if (camera->intrinsics == NULL)
|
|
|
|
|
camera->intrinsics = BKE_tracking_distortion_new();
|
2012-04-07 16:59:06 +00:00
|
|
|
|
2012-06-15 11:03:23 +00:00
|
|
|
return BKE_tracking_distortion_exec(camera->intrinsics, tracking, ibuf, calibration_width,
|
2012-06-16 09:18:00 +00:00
|
|
|
calibration_height, overscan, TRUE);
|
2012-06-15 11:03:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ImBuf *BKE_tracking_distort_frame(MovieTracking *tracking, ImBuf *ibuf, int calibration_width,
|
|
|
|
|
int calibration_height, float overscan)
|
|
|
|
|
{
|
|
|
|
|
MovieTrackingCamera *camera = &tracking->camera;
|
|
|
|
|
|
|
|
|
|
if (camera->intrinsics == NULL)
|
|
|
|
|
camera->intrinsics = BKE_tracking_distortion_new();
|
|
|
|
|
|
|
|
|
|
return BKE_tracking_distortion_exec(camera->intrinsics, tracking, ibuf, calibration_width,
|
2012-06-16 09:18:00 +00:00
|
|
|
calibration_height, overscan, FALSE);
|
2011-11-07 12:55:18 +00:00
|
|
|
}
|
|
|
|
|
|
2013-02-18 10:12:44 +00:00
|
|
|
void BKE_tracking_max_undistortion_delta_across_bound(MovieTracking *tracking, rcti *rect, float delta[2])
|
|
|
|
|
{
|
|
|
|
|
int a;
|
|
|
|
|
float pos[2], warped_pos[2];
|
|
|
|
|
const int coord_delta = 5;
|
|
|
|
|
|
|
|
|
|
delta[0] = delta[1] = -FLT_MAX;
|
|
|
|
|
|
|
|
|
|
for (a = rect->xmin; a <= rect->xmax + coord_delta; a += coord_delta) {
|
|
|
|
|
if (a > rect->xmax)
|
|
|
|
|
a = rect->xmax;
|
|
|
|
|
|
|
|
|
|
/* bottom edge */
|
|
|
|
|
pos[0] = a;
|
|
|
|
|
pos[1] = rect->ymin;
|
|
|
|
|
|
|
|
|
|
BKE_tracking_undistort_v2(tracking, pos, warped_pos);
|
|
|
|
|
|
|
|
|
|
delta[0] = max_ff(delta[0], fabs(pos[0] - warped_pos[0]));
|
|
|
|
|
delta[1] = max_ff(delta[1], fabs(pos[1] - warped_pos[1]));
|
|
|
|
|
|
|
|
|
|
/* top edge */
|
|
|
|
|
pos[0] = a;
|
|
|
|
|
pos[1] = rect->ymax;
|
|
|
|
|
|
|
|
|
|
BKE_tracking_undistort_v2(tracking, pos, warped_pos);
|
|
|
|
|
|
|
|
|
|
delta[0] = max_ff(delta[0], fabs(pos[0] - warped_pos[0]));
|
|
|
|
|
delta[1] = max_ff(delta[1], fabs(pos[1] - warped_pos[1]));
|
|
|
|
|
|
|
|
|
|
if (a >= rect->xmax)
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
for (a = rect->ymin; a <= rect->ymax + coord_delta; a += coord_delta) {
|
|
|
|
|
if (a > rect->ymax)
|
|
|
|
|
a = rect->ymax;
|
|
|
|
|
|
|
|
|
|
/* left edge */
|
|
|
|
|
pos[0] = rect->xmin;
|
|
|
|
|
pos[1] = a;
|
|
|
|
|
|
|
|
|
|
BKE_tracking_undistort_v2(tracking, pos, warped_pos);
|
|
|
|
|
|
|
|
|
|
delta[0] = max_ff(delta[0], fabs(pos[0] - warped_pos[0]));
|
|
|
|
|
delta[1] = max_ff(delta[1], fabs(pos[1] - warped_pos[1]));
|
|
|
|
|
|
|
|
|
|
/* right edge */
|
|
|
|
|
pos[0] = rect->xmax;
|
|
|
|
|
pos[1] = a;
|
|
|
|
|
|
|
|
|
|
BKE_tracking_undistort_v2(tracking, pos, warped_pos);
|
|
|
|
|
|
|
|
|
|
delta[0] = max_ff(delta[0], fabs(pos[0] - warped_pos[0]));
|
|
|
|
|
delta[1] = max_ff(delta[1], fabs(pos[1] - warped_pos[1]));
|
|
|
|
|
|
|
|
|
|
if (a >= rect->ymax)
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2012-06-15 11:03:23 +00:00
|
|
|
/*********************** Image sampling *************************/
|
|
|
|
|
|
2012-01-15 13:31:58 +00:00
|
|
|
static void disable_imbuf_channels(ImBuf *ibuf, MovieTrackingTrack *track, int grayscale)
|
|
|
|
|
{
|
2012-06-15 11:03:23 +00:00
|
|
|
BKE_tracking_disable_channels(ibuf, track->flag & TRACK_DISABLE_RED,
|
2012-06-16 09:18:00 +00:00
|
|
|
track->flag & TRACK_DISABLE_GREEN,
|
|
|
|
|
track->flag & TRACK_DISABLE_BLUE, grayscale);
|
2012-01-15 13:31:58 +00:00
|
|
|
}
|
|
|
|
|
|
2012-06-15 11:03:23 +00:00
|
|
|
ImBuf *BKE_tracking_sample_pattern(int frame_width, int frame_height, ImBuf *search_ibuf,
|
2012-06-16 09:18:00 +00:00
|
|
|
MovieTrackingTrack *track, MovieTrackingMarker *marker,
|
2013-03-04 18:30:48 +00:00
|
|
|
int from_anchor, int use_mask, int num_samples_x, int num_samples_y,
|
2012-06-16 09:18:00 +00:00
|
|
|
float pos[2])
|
2011-11-07 12:55:18 +00:00
|
|
|
{
|
2012-06-10 16:16:02 +00:00
|
|
|
#ifdef WITH_LIBMV
|
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
|
|
|
ImBuf *pattern_ibuf;
|
|
|
|
|
double src_pixel_x[5], src_pixel_y[5];
|
|
|
|
|
double warped_position_x, warped_position_y;
|
2012-06-12 11:13:53 +00:00
|
|
|
float *mask = NULL;
|
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
|
|
|
|
2012-11-07 11:18:42 +00:00
|
|
|
if (num_samples_x <= 0 || num_samples_y <= 0)
|
|
|
|
|
return NULL;
|
|
|
|
|
|
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
|
|
|
pattern_ibuf = IMB_allocImBuf(num_samples_x, num_samples_y, 32, IB_rectfloat);
|
|
|
|
|
|
|
|
|
|
if (!search_ibuf->rect_float) {
|
|
|
|
|
IMB_float_from_rect(search_ibuf);
|
|
|
|
|
}
|
2011-11-07 12:55:18 +00:00
|
|
|
|
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
|
|
|
get_marker_coords_for_tracking(frame_width, frame_height, marker, src_pixel_x, src_pixel_y);
|
2011-11-07 12:55:18 +00:00
|
|
|
|
2013-03-04 18:30:48 +00:00
|
|
|
/* from_anchor means search buffer was obtained for an anchored position,
|
|
|
|
|
* which means applying track offset rounded to pixel space (we could not
|
|
|
|
|
* store search buffer with sub-pixel precision)
|
|
|
|
|
*
|
|
|
|
|
* in this case we need to alter coordinates a bit, to compensate rounded
|
|
|
|
|
* fractional part of offset
|
|
|
|
|
*/
|
|
|
|
|
if (from_anchor) {
|
|
|
|
|
int a;
|
|
|
|
|
|
|
|
|
|
for (a = 0; a < 5; a++) {
|
|
|
|
|
src_pixel_x[a] += ((track->offset[0] * frame_width) - ((int) (track->offset[0] * frame_width)));
|
|
|
|
|
src_pixel_y[a] += ((track->offset[1] * frame_height) - ((int) (track->offset[1] * frame_height)));
|
|
|
|
|
|
|
|
|
|
/* when offset is negative, rounding happens in opposite direction */
|
|
|
|
|
if (track->offset[0] < 0.0f)
|
|
|
|
|
src_pixel_x[a] += 1.0f;
|
|
|
|
|
if (track->offset[1] < 0.0f)
|
|
|
|
|
src_pixel_y[a] += 1.0f;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2012-06-12 11:13:53 +00:00
|
|
|
if (use_mask) {
|
2012-06-15 11:03:23 +00:00
|
|
|
mask = BKE_tracking_track_get_mask(frame_width, frame_height, track, marker);
|
2012-06-12 11:13:53 +00:00
|
|
|
}
|
|
|
|
|
|
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
|
|
|
libmv_samplePlanarPatch(search_ibuf->rect_float, search_ibuf->x, search_ibuf->y, 4,
|
|
|
|
|
src_pixel_x, src_pixel_y, num_samples_x,
|
2012-06-12 11:13:53 +00:00
|
|
|
num_samples_y, mask, pattern_ibuf->rect_float,
|
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
|
|
|
&warped_position_x, &warped_position_y);
|
2012-01-04 15:25:43 +00:00
|
|
|
|
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
|
|
|
if (pos) {
|
|
|
|
|
pos[0] = warped_position_x;
|
|
|
|
|
pos[1] = warped_position_y;
|
|
|
|
|
}
|
2011-11-07 12:55:18 +00:00
|
|
|
|
2012-06-12 11:13:53 +00:00
|
|
|
if (mask) {
|
|
|
|
|
MEM_freeN(mask);
|
|
|
|
|
}
|
|
|
|
|
|
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
|
|
|
return pattern_ibuf;
|
2012-06-10 16:16:02 +00:00
|
|
|
#else
|
|
|
|
|
ImBuf *pattern_ibuf;
|
|
|
|
|
|
|
|
|
|
/* real sampling requires libmv, but areas are supposing pattern would be
|
|
|
|
|
* sampled if search area does exists, so we'll need to create empty
|
|
|
|
|
* pattern area here to prevent adding NULL-checks all over just to deal
|
2013-01-12 14:28:23 +00:00
|
|
|
* with situation when libmv is disabled
|
2012-06-10 16:16:02 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
(void) frame_width;
|
|
|
|
|
(void) frame_height;
|
|
|
|
|
(void) search_ibuf;
|
|
|
|
|
(void) marker;
|
2012-06-12 20:04:55 +00:00
|
|
|
(void) track;
|
|
|
|
|
(void) use_mask;
|
2012-06-10 16:16:02 +00:00
|
|
|
|
|
|
|
|
pattern_ibuf = IMB_allocImBuf(num_samples_x, num_samples_y, 32, IB_rectfloat);
|
|
|
|
|
|
|
|
|
|
pos[0] = num_samples_x / 2.0f;
|
|
|
|
|
pos[1] = num_samples_y / 2.0f;
|
|
|
|
|
|
|
|
|
|
return pattern_ibuf;
|
|
|
|
|
#endif
|
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
|
|
|
}
|
2012-01-04 15:25:43 +00:00
|
|
|
|
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
|
|
|
ImBuf *BKE_tracking_get_pattern_imbuf(ImBuf *ibuf, MovieTrackingTrack *track, MovieTrackingMarker *marker,
|
2012-06-10 19:59:02 +00:00
|
|
|
int anchored, int disable_channels)
|
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
|
|
|
{
|
|
|
|
|
ImBuf *pattern_ibuf, *search_ibuf;
|
|
|
|
|
float pat_min[2], pat_max[2];
|
|
|
|
|
int num_samples_x, num_samples_y;
|
2011-11-07 12:55:18 +00:00
|
|
|
|
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
|
|
|
BKE_tracking_marker_pattern_minmax(marker, pat_min, pat_max);
|
2012-01-09 22:18:04 +00:00
|
|
|
|
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
|
|
|
num_samples_x = (pat_max[0] - pat_min[0]) * ibuf->x;
|
|
|
|
|
num_samples_y = (pat_max[1] - pat_min[1]) * ibuf->y;
|
|
|
|
|
|
|
|
|
|
search_ibuf = BKE_tracking_get_search_imbuf(ibuf, track, marker, anchored, disable_channels);
|
|
|
|
|
|
2012-11-07 11:18:42 +00:00
|
|
|
if (search_ibuf) {
|
|
|
|
|
pattern_ibuf = BKE_tracking_sample_pattern(ibuf->x, ibuf->y, search_ibuf, track, marker,
|
2013-03-04 18:30:48 +00:00
|
|
|
anchored, FALSE, num_samples_x, num_samples_y, NULL);
|
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
|
|
|
|
2012-11-07 11:18:42 +00:00
|
|
|
IMB_freeImBuf(search_ibuf);
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
pattern_ibuf = NULL;
|
|
|
|
|
}
|
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
|
|
|
|
|
|
|
|
return pattern_ibuf;
|
|
|
|
|
}
|
2012-05-09 08:33:11 +00:00
|
|
|
|
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
|
|
|
ImBuf *BKE_tracking_get_search_imbuf(ImBuf *ibuf, MovieTrackingTrack *track, MovieTrackingMarker *marker,
|
|
|
|
|
int anchored, int disable_channels)
|
|
|
|
|
{
|
|
|
|
|
ImBuf *searchibuf;
|
|
|
|
|
int x, y, w, h;
|
|
|
|
|
float search_origin[2];
|
2012-05-09 16:00:39 +00:00
|
|
|
|
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
|
|
|
get_search_origin_frame_pixel(ibuf->x, ibuf->y, marker, search_origin);
|
2011-11-07 12:55:18 +00:00
|
|
|
|
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
|
|
|
x = search_origin[0];
|
|
|
|
|
y = search_origin[1];
|
|
|
|
|
|
|
|
|
|
if (anchored) {
|
|
|
|
|
x += track->offset[0] * ibuf->x;
|
|
|
|
|
y += track->offset[1] * ibuf->y;
|
2011-11-07 12:55:18 +00:00
|
|
|
}
|
|
|
|
|
|
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
|
|
|
w = (marker->search_max[0] - marker->search_min[0]) * ibuf->x;
|
|
|
|
|
h = (marker->search_max[1] - marker->search_min[1]) * ibuf->y;
|
|
|
|
|
|
2012-11-07 11:18:42 +00:00
|
|
|
if (w <= 0 || h <= 0)
|
|
|
|
|
return NULL;
|
|
|
|
|
|
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
|
|
|
searchibuf = IMB_allocImBuf(w, h, 32, ibuf->rect_float ? IB_rectfloat : IB_rect);
|
|
|
|
|
|
|
|
|
|
IMB_rectcpy(searchibuf, ibuf, 0, 0, x, y, w, h);
|
|
|
|
|
|
|
|
|
|
if (disable_channels) {
|
|
|
|
|
if ((track->flag & TRACK_PREVIEW_GRAYSCALE) ||
|
|
|
|
|
(track->flag & TRACK_DISABLE_RED) ||
|
|
|
|
|
(track->flag & TRACK_DISABLE_GREEN) ||
|
|
|
|
|
(track->flag & TRACK_DISABLE_BLUE))
|
|
|
|
|
{
|
|
|
|
|
disable_imbuf_channels(searchibuf, track, TRUE);
|
|
|
|
|
}
|
2011-11-07 12:55:18 +00:00
|
|
|
}
|
|
|
|
|
|
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
|
|
|
return searchibuf;
|
|
|
|
|
}
|
|
|
|
|
|
2012-06-15 11:03:23 +00:00
|
|
|
/* zap channels from the imbuf that are disabled by the user. this can lead to
|
|
|
|
|
* better tracks sometimes. however, instead of simply zeroing the channels
|
|
|
|
|
* out, do a partial grayscale conversion so the display is better.
|
|
|
|
|
*/
|
|
|
|
|
void BKE_tracking_disable_channels(ImBuf *ibuf, int disable_red, int disable_green, int disable_blue,
|
2012-06-16 09:18:00 +00:00
|
|
|
int grayscale)
|
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
|
|
|
{
|
2012-06-15 11:03:23 +00:00
|
|
|
int x, y;
|
|
|
|
|
float scale;
|
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
|
|
|
|
2012-06-15 11:03:23 +00:00
|
|
|
if (!disable_red && !disable_green && !disable_blue && !grayscale)
|
|
|
|
|
return;
|
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
|
|
|
|
2012-06-15 11:03:23 +00:00
|
|
|
/* if only some components are selected, it's important to rescale the result
|
|
|
|
|
* appropriately so that e.g. if only blue is selected, it's not zeroed out.
|
|
|
|
|
*/
|
|
|
|
|
scale = (disable_red ? 0.0f : 0.2126f) +
|
|
|
|
|
(disable_green ? 0.0f : 0.7152f) +
|
|
|
|
|
(disable_blue ? 0.0f : 0.0722f);
|
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
|
|
|
|
2012-06-15 11:03:23 +00:00
|
|
|
for (y = 0; y < ibuf->y; y++) {
|
|
|
|
|
for (x = 0; x < ibuf->x; x++) {
|
|
|
|
|
int pixel = ibuf->x * y + x;
|
2012-06-12 11:13:53 +00:00
|
|
|
|
2012-06-15 11:03:23 +00:00
|
|
|
if (ibuf->rect_float) {
|
|
|
|
|
float *rrgbf = ibuf->rect_float + pixel * 4;
|
|
|
|
|
float r = disable_red ? 0.0f : rrgbf[0];
|
|
|
|
|
float g = disable_green ? 0.0f : rrgbf[1];
|
|
|
|
|
float b = disable_blue ? 0.0f : rrgbf[2];
|
2012-06-12 11:13:53 +00:00
|
|
|
|
2012-06-15 11:03:23 +00:00
|
|
|
if (grayscale) {
|
|
|
|
|
float gray = (0.2126f * r + 0.7152f * g + 0.0722f * b) / scale;
|
|
|
|
|
|
|
|
|
|
rrgbf[0] = rrgbf[1] = rrgbf[2] = gray;
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
rrgbf[0] = r;
|
|
|
|
|
rrgbf[1] = g;
|
|
|
|
|
rrgbf[2] = b;
|
|
|
|
|
}
|
2012-06-12 11:13:53 +00:00
|
|
|
}
|
2012-06-15 11:03:23 +00:00
|
|
|
else {
|
|
|
|
|
char *rrgb = (char *)ibuf->rect + pixel * 4;
|
|
|
|
|
char r = disable_red ? 0 : rrgb[0];
|
|
|
|
|
char g = disable_green ? 0 : rrgb[1];
|
|
|
|
|
char b = disable_blue ? 0 : rrgb[2];
|
2012-06-12 11:13:53 +00:00
|
|
|
|
2012-06-15 11:03:23 +00:00
|
|
|
if (grayscale) {
|
|
|
|
|
float gray = (0.2126f * r + 0.7152f * g + 0.0722f * b) / scale;
|
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
|
|
|
|
2012-06-15 11:03:23 +00:00
|
|
|
rrgb[0] = rrgb[1] = rrgb[2] = gray;
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
rrgb[0] = r;
|
|
|
|
|
rrgb[1] = g;
|
|
|
|
|
rrgb[2] = b;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2011-12-04 12:58:31 +00:00
|
|
|
}
|
2011-11-07 12:55:18 +00:00
|
|
|
|
2012-06-15 11:03:23 +00:00
|
|
|
if (ibuf->rect_float)
|
|
|
|
|
ibuf->userflags |= IB_RECT_INVALID;
|
2011-11-07 12:55:18 +00:00
|
|
|
}
|
|
|
|
|
|
2012-06-15 11:03:23 +00:00
|
|
|
/*********************** Tracks map *************************/
|
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
|
|
|
|
2012-06-15 11:03:23 +00:00
|
|
|
typedef struct TracksMap {
|
|
|
|
|
char object_name[MAX_NAME];
|
|
|
|
|
int is_camera;
|
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
|
|
|
|
2012-06-15 11:03:23 +00:00
|
|
|
int num_tracks;
|
|
|
|
|
int customdata_size;
|
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
|
|
|
|
2012-06-15 11:03:23 +00:00
|
|
|
char *customdata;
|
|
|
|
|
MovieTrackingTrack *tracks;
|
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
|
|
|
|
2012-06-15 11:03:23 +00:00
|
|
|
GHash *hash;
|
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
|
|
|
|
2012-06-15 11:03:23 +00:00
|
|
|
int ptr;
|
|
|
|
|
} TracksMap;
|
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
|
|
|
|
2012-06-15 11:03:23 +00:00
|
|
|
static TracksMap *tracks_map_new(const char *object_name, int is_camera, int num_tracks, int customdata_size)
|
|
|
|
|
{
|
|
|
|
|
TracksMap *map = MEM_callocN(sizeof(TracksMap), "TrackingsMap");
|
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
|
|
|
|
2012-06-15 11:03:23 +00:00
|
|
|
BLI_strncpy(map->object_name, object_name, sizeof(map->object_name));
|
|
|
|
|
map->is_camera = is_camera;
|
2011-11-07 12:55:18 +00:00
|
|
|
|
2012-06-15 11:03:23 +00:00
|
|
|
map->num_tracks = num_tracks;
|
|
|
|
|
map->customdata_size = customdata_size;
|
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
|
|
|
|
2012-06-15 11:03:23 +00:00
|
|
|
map->tracks = MEM_callocN(sizeof(MovieTrackingTrack) * num_tracks, "TrackingsMap tracks");
|
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
|
|
|
|
2012-06-15 11:03:23 +00:00
|
|
|
if (customdata_size)
|
|
|
|
|
map->customdata = MEM_callocN(customdata_size * num_tracks, "TracksMap customdata");
|
2012-06-12 11:13:53 +00:00
|
|
|
|
2012-06-15 11:03:23 +00:00
|
|
|
map->hash = BLI_ghash_ptr_new("TracksMap hash");
|
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
|
|
|
|
2012-06-15 11:03:23 +00:00
|
|
|
return map;
|
2011-11-07 12:55:18 +00:00
|
|
|
}
|
|
|
|
|
|
2012-06-15 11:03:23 +00:00
|
|
|
static int tracks_map_get_size(TracksMap *map)
|
2011-11-07 12:55:18 +00:00
|
|
|
{
|
2012-06-15 11:03:23 +00:00
|
|
|
return map->num_tracks;
|
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
|
|
|
}
|
2011-11-07 12:55:18 +00:00
|
|
|
|
2012-06-15 11:03:23 +00:00
|
|
|
static void tracks_map_get_indexed_element(TracksMap *map, int index, MovieTrackingTrack **track, void **customdata)
|
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
|
|
|
{
|
2012-06-15 11:03:23 +00:00
|
|
|
*track = &map->tracks[index];
|
2011-11-07 12:55:18 +00:00
|
|
|
|
2012-06-15 11:03:23 +00:00
|
|
|
if (map->customdata)
|
|
|
|
|
*customdata = &map->customdata[index * map->customdata_size];
|
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
|
|
|
}
|
2012-03-25 23:19:21 +00:00
|
|
|
|
2012-06-15 11:03:23 +00:00
|
|
|
static void tracks_map_insert(TracksMap *map, MovieTrackingTrack *track, void *customdata)
|
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
|
|
|
{
|
2012-06-15 11:03:23 +00:00
|
|
|
MovieTrackingTrack new_track = *track;
|
2012-03-25 23:19:21 +00:00
|
|
|
|
2012-06-15 11:03:23 +00:00
|
|
|
new_track.markers = MEM_dupallocN(new_track.markers);
|
2012-03-25 23:19:21 +00:00
|
|
|
|
2012-06-15 11:03:23 +00:00
|
|
|
map->tracks[map->ptr] = new_track;
|
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
|
|
|
|
2012-06-15 11:03:23 +00:00
|
|
|
if (customdata)
|
|
|
|
|
memcpy(&map->customdata[map->ptr * map->customdata_size], customdata, map->customdata_size);
|
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
|
|
|
|
2012-06-15 11:03:23 +00:00
|
|
|
BLI_ghash_insert(map->hash, &map->tracks[map->ptr], track);
|
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
|
|
|
|
2012-06-15 11:03:23 +00:00
|
|
|
map->ptr++;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void tracks_map_merge(TracksMap *map, MovieTracking *tracking)
|
|
|
|
|
{
|
|
|
|
|
MovieTrackingTrack *track;
|
|
|
|
|
MovieTrackingTrack *act_track = BKE_tracking_track_get_active(tracking);
|
|
|
|
|
MovieTrackingTrack *rot_track = tracking->stabilization.rot_track;
|
|
|
|
|
ListBase tracks = {NULL, NULL}, new_tracks = {NULL, NULL};
|
|
|
|
|
ListBase *old_tracks;
|
|
|
|
|
int a;
|
|
|
|
|
|
|
|
|
|
if (map->is_camera) {
|
|
|
|
|
old_tracks = &tracking->tracks;
|
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
|
|
|
}
|
|
|
|
|
else {
|
2012-06-15 11:03:23 +00:00
|
|
|
MovieTrackingObject *object = BKE_tracking_object_get_named(tracking, map->object_name);
|
2011-11-07 12:55:18 +00:00
|
|
|
|
2012-06-15 11:03:23 +00:00
|
|
|
if (!object) {
|
|
|
|
|
/* object was deleted by user, create new one */
|
|
|
|
|
object = BKE_tracking_object_add(tracking, map->object_name);
|
|
|
|
|
}
|
2011-11-07 12:55:18 +00:00
|
|
|
|
2012-06-15 11:03:23 +00:00
|
|
|
old_tracks = &object->tracks;
|
|
|
|
|
}
|
2011-11-07 12:55:18 +00:00
|
|
|
|
2012-06-15 11:03:23 +00:00
|
|
|
/* duplicate currently operating tracks to temporary list.
|
|
|
|
|
* this is needed to keep names in unique state and it's faster to change names
|
|
|
|
|
* of currently operating tracks (if needed)
|
|
|
|
|
*/
|
|
|
|
|
for (a = 0; a < map->num_tracks; a++) {
|
|
|
|
|
int replace_sel = 0, replace_rot = 0;
|
|
|
|
|
MovieTrackingTrack *new_track, *old;
|
2011-11-07 12:55:18 +00:00
|
|
|
|
2012-06-15 11:03:23 +00:00
|
|
|
track = &map->tracks[a];
|
2011-11-07 12:55:18 +00:00
|
|
|
|
2012-06-15 11:03:23 +00:00
|
|
|
/* find original of operating track in list of previously displayed tracks */
|
|
|
|
|
old = BLI_ghash_lookup(map->hash, track);
|
|
|
|
|
if (old) {
|
|
|
|
|
MovieTrackingTrack *cur = old_tracks->first;
|
2012-03-25 23:19:21 +00:00
|
|
|
|
2012-06-15 11:03:23 +00:00
|
|
|
while (cur) {
|
|
|
|
|
if (cur == old)
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
cur = cur->next;
|
2012-03-24 06:18:31 +00:00
|
|
|
}
|
2012-03-25 23:19:21 +00:00
|
|
|
|
2012-06-15 11:03:23 +00:00
|
|
|
/* original track was found, re-use flags and remove this track */
|
|
|
|
|
if (cur) {
|
|
|
|
|
if (cur == act_track)
|
|
|
|
|
replace_sel = 1;
|
|
|
|
|
if (cur == rot_track)
|
|
|
|
|
replace_rot = 1;
|
|
|
|
|
|
|
|
|
|
track->flag = cur->flag;
|
|
|
|
|
track->pat_flag = cur->pat_flag;
|
|
|
|
|
track->search_flag = cur->search_flag;
|
2012-03-25 23:19:21 +00:00
|
|
|
|
2012-06-15 11:03:23 +00:00
|
|
|
BKE_tracking_track_free(cur);
|
|
|
|
|
BLI_freelinkN(old_tracks, cur);
|
|
|
|
|
}
|
2011-11-07 12:55:18 +00:00
|
|
|
}
|
|
|
|
|
|
2012-06-15 11:03:23 +00:00
|
|
|
new_track = tracking_track_duplicate(track);
|
2011-11-07 12:55:18 +00:00
|
|
|
|
2012-06-15 11:03:23 +00:00
|
|
|
BLI_ghash_remove(map->hash, track, NULL, NULL); /* XXX: are we actually need this */
|
|
|
|
|
BLI_ghash_insert(map->hash, track, new_track);
|
2011-11-07 12:55:18 +00:00
|
|
|
|
2012-06-15 11:03:23 +00:00
|
|
|
if (replace_sel) /* update current selection in clip */
|
|
|
|
|
tracking->act_track = new_track;
|
2011-11-07 12:55:18 +00:00
|
|
|
|
2012-06-15 11:03:23 +00:00
|
|
|
if (replace_rot) /* update track used for rotation stabilization */
|
|
|
|
|
tracking->stabilization.rot_track = new_track;
|
2011-11-07 12:55:18 +00:00
|
|
|
|
2012-06-15 11:03:23 +00:00
|
|
|
BLI_addtail(&tracks, new_track);
|
|
|
|
|
}
|
2011-11-07 12:55:18 +00:00
|
|
|
|
2012-06-15 11:03:23 +00:00
|
|
|
/* move all tracks, which aren't operating */
|
|
|
|
|
track = old_tracks->first;
|
|
|
|
|
while (track) {
|
|
|
|
|
MovieTrackingTrack *next = track->next;
|
2011-11-07 12:55:18 +00:00
|
|
|
|
2012-06-15 11:03:23 +00:00
|
|
|
track->next = track->prev = NULL;
|
|
|
|
|
BLI_addtail(&new_tracks, track);
|
2011-11-07 12:55:18 +00:00
|
|
|
|
2012-06-15 11:03:23 +00:00
|
|
|
track = next;
|
|
|
|
|
}
|
2011-11-07 12:55:18 +00:00
|
|
|
|
2012-06-15 11:03:23 +00:00
|
|
|
/* now move all tracks which are currently operating and keep their names unique */
|
|
|
|
|
track = tracks.first;
|
|
|
|
|
while (track) {
|
|
|
|
|
MovieTrackingTrack *next = track->next;
|
2011-11-07 12:55:18 +00:00
|
|
|
|
2012-06-15 11:03:23 +00:00
|
|
|
BLI_remlink(&tracks, track);
|
2011-11-07 12:55:18 +00:00
|
|
|
|
2012-06-15 11:03:23 +00:00
|
|
|
track->next = track->prev = NULL;
|
|
|
|
|
BLI_addtail(&new_tracks, track);
|
2012-03-25 23:19:21 +00:00
|
|
|
|
2012-06-15 11:03:23 +00:00
|
|
|
BLI_uniquename(&new_tracks, track, "Track", '.', offsetof(MovieTrackingTrack, name), sizeof(track->name));
|
2011-11-07 12:55:18 +00:00
|
|
|
|
2012-06-15 11:03:23 +00:00
|
|
|
track = next;
|
2011-11-07 12:55:18 +00:00
|
|
|
}
|
|
|
|
|
|
2012-06-15 11:03:23 +00:00
|
|
|
*old_tracks = new_tracks;
|
2011-11-07 12:55:18 +00:00
|
|
|
}
|
|
|
|
|
|
2012-06-15 11:03:23 +00:00
|
|
|
static void tracks_map_free(TracksMap *map, void (*customdata_free)(void *customdata))
|
2011-11-07 12:55:18 +00:00
|
|
|
{
|
2012-06-15 11:03:23 +00:00
|
|
|
int i = 0;
|
2011-11-07 12:55:18 +00:00
|
|
|
|
2012-06-15 11:03:23 +00:00
|
|
|
BLI_ghash_free(map->hash, NULL, NULL);
|
2011-11-07 12:55:18 +00:00
|
|
|
|
2012-06-15 11:03:23 +00:00
|
|
|
for (i = 0; i < map->num_tracks; i++) {
|
|
|
|
|
if (map->customdata && customdata_free)
|
|
|
|
|
customdata_free(&map->customdata[i * map->customdata_size]);
|
2011-11-07 12:55:18 +00:00
|
|
|
|
2012-06-15 11:03:23 +00:00
|
|
|
BKE_tracking_track_free(&map->tracks[i]);
|
|
|
|
|
}
|
2011-11-07 12:55:18 +00:00
|
|
|
|
2012-06-15 11:03:23 +00:00
|
|
|
if (map->customdata)
|
|
|
|
|
MEM_freeN(map->customdata);
|
2012-06-11 11:40:54 +00:00
|
|
|
|
2012-06-15 11:03:23 +00:00
|
|
|
MEM_freeN(map->tracks);
|
|
|
|
|
MEM_freeN(map);
|
|
|
|
|
}
|
2012-06-11 11:40:54 +00:00
|
|
|
|
2012-06-15 11:03:23 +00:00
|
|
|
/*********************** 2D tracking *************************/
|
2012-06-11 11:40:54 +00:00
|
|
|
|
2012-06-15 11:03:23 +00:00
|
|
|
typedef struct TrackContext {
|
|
|
|
|
#ifdef WITH_LIBMV
|
|
|
|
|
/* the reference marker and cutout search area */
|
|
|
|
|
MovieTrackingMarker marker;
|
2012-06-11 11:40:54 +00:00
|
|
|
|
2012-06-15 11:03:23 +00:00
|
|
|
/* keyframed patch. This is the search area */
|
|
|
|
|
float *search_area;
|
|
|
|
|
int search_area_height;
|
|
|
|
|
int search_area_width;
|
|
|
|
|
int framenr;
|
2012-06-11 11:40:54 +00:00
|
|
|
|
2012-06-15 11:03:23 +00:00
|
|
|
float *mask;
|
|
|
|
|
#else
|
|
|
|
|
int pad;
|
2011-11-07 12:55:18 +00:00
|
|
|
#endif
|
2012-06-15 11:03:23 +00:00
|
|
|
} TrackContext;
|
2011-11-07 12:55:18 +00:00
|
|
|
|
2012-06-15 11:03:23 +00:00
|
|
|
typedef struct MovieTrackingContext {
|
|
|
|
|
MovieClipUser user;
|
|
|
|
|
MovieClip *clip;
|
|
|
|
|
int clip_flag;
|
2011-11-07 12:55:18 +00:00
|
|
|
|
2012-06-15 11:03:23 +00:00
|
|
|
int first_time, frames;
|
2012-04-30 16:19:20 +00:00
|
|
|
|
2012-06-15 11:03:23 +00:00
|
|
|
MovieTrackingSettings settings;
|
|
|
|
|
TracksMap *tracks_map;
|
2011-11-07 12:55:18 +00:00
|
|
|
|
2012-06-15 11:03:23 +00:00
|
|
|
short backwards, sequence;
|
|
|
|
|
int sync_frame;
|
|
|
|
|
} MovieTrackingContext;
|
2011-11-07 12:55:18 +00:00
|
|
|
|
2012-06-15 11:03:23 +00:00
|
|
|
static void track_context_free(void *customdata)
|
2011-11-07 12:55:18 +00:00
|
|
|
{
|
2012-06-15 11:03:23 +00:00
|
|
|
TrackContext *track_context = (TrackContext *)customdata;
|
2011-11-07 12:55:18 +00:00
|
|
|
|
2012-09-16 00:26:36 +00:00
|
|
|
#ifdef WITH_LIBMV
|
2012-06-15 11:03:23 +00:00
|
|
|
if (track_context->search_area)
|
|
|
|
|
MEM_freeN(track_context->search_area);
|
2011-11-07 12:55:18 +00:00
|
|
|
|
2012-06-15 11:03:23 +00:00
|
|
|
if (track_context->mask)
|
|
|
|
|
MEM_freeN(track_context->mask);
|
2011-11-07 12:55:18 +00:00
|
|
|
|
2012-06-15 11:03:23 +00:00
|
|
|
#else
|
|
|
|
|
(void)track_context;
|
|
|
|
|
#endif
|
|
|
|
|
}
|
2011-11-07 12:55:18 +00:00
|
|
|
|
2012-06-15 11:03:23 +00:00
|
|
|
MovieTrackingContext *BKE_tracking_context_new(MovieClip *clip, MovieClipUser *user, short backwards, short sequence)
|
|
|
|
|
{
|
|
|
|
|
MovieTrackingContext *context = MEM_callocN(sizeof(MovieTrackingContext), "trackingContext");
|
|
|
|
|
MovieTracking *tracking = &clip->tracking;
|
|
|
|
|
MovieTrackingSettings *settings = &tracking->settings;
|
|
|
|
|
ListBase *tracksbase = BKE_tracking_get_active_tracks(tracking);
|
|
|
|
|
MovieTrackingTrack *track;
|
|
|
|
|
MovieTrackingObject *object = BKE_tracking_object_get_active(tracking);
|
|
|
|
|
int num_tracks = 0;
|
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
|
|
|
|
2012-06-15 11:03:23 +00:00
|
|
|
context->clip = clip;
|
|
|
|
|
context->settings = *settings;
|
|
|
|
|
context->backwards = backwards;
|
|
|
|
|
context->sync_frame = user->framenr;
|
|
|
|
|
context->first_time = TRUE;
|
|
|
|
|
context->sequence = sequence;
|
2011-11-27 19:17:59 +00:00
|
|
|
|
2012-06-15 11:03:23 +00:00
|
|
|
/* count */
|
|
|
|
|
track = tracksbase->first;
|
|
|
|
|
while (track) {
|
|
|
|
|
if (TRACK_SELECTED(track) && (track->flag & (TRACK_LOCKED | TRACK_HIDDEN)) == 0) {
|
|
|
|
|
int framenr = BKE_movieclip_remap_scene_to_clip_frame(clip, user->framenr);
|
|
|
|
|
MovieTrackingMarker *marker = BKE_tracking_marker_get(track, framenr);
|
2011-11-27 19:17:59 +00:00
|
|
|
|
2012-06-15 11:03:23 +00:00
|
|
|
if ((marker->flag & MARKER_DISABLED) == 0)
|
|
|
|
|
num_tracks++;
|
|
|
|
|
}
|
2011-11-07 12:55:18 +00:00
|
|
|
|
2012-06-15 11:03:23 +00:00
|
|
|
track = track->next;
|
|
|
|
|
}
|
2011-11-07 12:55:18 +00:00
|
|
|
|
2012-06-15 11:03:23 +00:00
|
|
|
/* create tracking contextx for all tracks which would be tracked */
|
|
|
|
|
if (num_tracks) {
|
|
|
|
|
int width, height;
|
2011-11-07 12:55:18 +00:00
|
|
|
|
2012-06-15 11:03:23 +00:00
|
|
|
context->tracks_map = tracks_map_new(object->name, object->flag & TRACKING_OBJECT_CAMERA,
|
|
|
|
|
num_tracks, sizeof(TrackContext));
|
2011-11-07 12:55:18 +00:00
|
|
|
|
2012-06-15 11:03:23 +00:00
|
|
|
BKE_movieclip_get_size(clip, user, &width, &height);
|
2011-11-07 12:55:18 +00:00
|
|
|
|
2012-06-15 11:03:23 +00:00
|
|
|
/* create tracking data */
|
|
|
|
|
track = tracksbase->first;
|
|
|
|
|
while (track) {
|
|
|
|
|
if (TRACK_SELECTED(track) && (track->flag & (TRACK_HIDDEN | TRACK_LOCKED)) == 0) {
|
|
|
|
|
int framenr = BKE_movieclip_remap_scene_to_clip_frame(clip, user->framenr);
|
|
|
|
|
MovieTrackingMarker *marker = BKE_tracking_marker_get(track, framenr);
|
2011-11-07 12:55:18 +00:00
|
|
|
|
2012-06-15 11:03:23 +00:00
|
|
|
if ((marker->flag & MARKER_DISABLED) == 0) {
|
|
|
|
|
TrackContext track_context;
|
|
|
|
|
memset(&track_context, 0, sizeof(TrackContext));
|
|
|
|
|
tracks_map_insert(context->tracks_map, track, &track_context);
|
|
|
|
|
}
|
2011-11-07 12:55:18 +00:00
|
|
|
}
|
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
|
|
|
|
2012-06-15 11:03:23 +00:00
|
|
|
track = track->next;
|
|
|
|
|
}
|
|
|
|
|
}
|
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
|
|
|
|
2012-06-15 11:03:23 +00:00
|
|
|
/* store needed clip flags passing to get_buffer functions
|
|
|
|
|
* - MCLIP_USE_PROXY is needed to because timecode affects on movie clip
|
|
|
|
|
* only in case Proxy/Timecode flag is set, so store this flag to use
|
|
|
|
|
* timecodes properly but reset render size to SIZE_FULL so correct resolution
|
|
|
|
|
* would be used for images
|
|
|
|
|
* - MCLIP_USE_PROXY_CUSTOM_DIR is needed because proxy/timecode files might
|
|
|
|
|
* be stored in a different location
|
|
|
|
|
* ignore all the rest possible flags for now
|
|
|
|
|
*/
|
|
|
|
|
context->clip_flag = clip->flag & MCLIP_TIMECODE_FLAGS;
|
2011-11-07 12:55:18 +00:00
|
|
|
|
2012-06-15 11:03:23 +00:00
|
|
|
context->user = *user;
|
|
|
|
|
context->user.render_size = MCLIP_PROXY_RENDER_SIZE_FULL;
|
|
|
|
|
context->user.render_flag = 0;
|
2011-11-07 12:55:18 +00:00
|
|
|
|
2012-06-15 11:03:23 +00:00
|
|
|
if (!sequence)
|
|
|
|
|
BLI_begin_threaded_malloc();
|
2011-11-07 12:55:18 +00:00
|
|
|
|
2012-06-15 11:03:23 +00:00
|
|
|
return context;
|
|
|
|
|
}
|
2011-11-07 12:55:18 +00:00
|
|
|
|
2012-06-15 11:03:23 +00:00
|
|
|
void BKE_tracking_context_free(MovieTrackingContext *context)
|
|
|
|
|
{
|
|
|
|
|
if (!context->sequence)
|
|
|
|
|
BLI_end_threaded_malloc();
|
2012-06-12 11:13:53 +00:00
|
|
|
|
2012-06-15 11:03:23 +00:00
|
|
|
tracks_map_free(context->tracks_map, track_context_free);
|
2012-06-12 11:13:53 +00:00
|
|
|
|
2012-06-15 11:03:23 +00:00
|
|
|
MEM_freeN(context);
|
|
|
|
|
}
|
2011-11-07 12:55:18 +00:00
|
|
|
|
2012-06-15 11:03:23 +00:00
|
|
|
void BKE_tracking_context_sync(MovieTrackingContext *context)
|
|
|
|
|
{
|
|
|
|
|
MovieTracking *tracking = &context->clip->tracking;
|
|
|
|
|
int newframe;
|
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
|
|
|
|
2012-06-15 11:03:23 +00:00
|
|
|
tracks_map_merge(context->tracks_map, tracking);
|
2011-11-07 12:55:18 +00:00
|
|
|
|
2012-06-15 11:03:23 +00:00
|
|
|
if (context->backwards)
|
|
|
|
|
newframe = context->user.framenr + 1;
|
|
|
|
|
else
|
|
|
|
|
newframe = context->user.framenr - 1;
|
2011-11-07 12:55:18 +00:00
|
|
|
|
2012-06-15 11:03:23 +00:00
|
|
|
context->sync_frame = newframe;
|
2011-11-07 12:55:18 +00:00
|
|
|
|
2012-10-26 12:36:50 +00:00
|
|
|
BKE_tracking_dopesheet_tag_update(tracking);
|
2012-06-15 11:03:23 +00:00
|
|
|
}
|
2011-11-07 12:55:18 +00:00
|
|
|
|
2012-06-15 11:03:23 +00:00
|
|
|
void BKE_tracking_context_sync_user(const MovieTrackingContext *context, MovieClipUser *user)
|
|
|
|
|
{
|
|
|
|
|
user->framenr = context->sync_frame;
|
|
|
|
|
}
|
2012-06-12 11:13:53 +00:00
|
|
|
|
2012-06-15 11:03:23 +00:00
|
|
|
#ifdef WITH_LIBMV
|
|
|
|
|
/* **** utility functions for tracking **** */
|
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
|
|
|
|
2012-06-15 11:03:23 +00:00
|
|
|
/* convert from float and byte RGBA to grayscale. Supports different coefficients for RGB. */
|
|
|
|
|
static void float_rgba_to_gray(const float *rgba, float *gray, int num_pixels,
|
|
|
|
|
float weight_red, float weight_green, float weight_blue)
|
|
|
|
|
{
|
|
|
|
|
int i;
|
|
|
|
|
|
|
|
|
|
for (i = 0; i < num_pixels; i++) {
|
|
|
|
|
const float *pixel = rgba + 4 * i;
|
2011-11-07 12:55:18 +00:00
|
|
|
|
2012-06-15 11:03:23 +00:00
|
|
|
gray[i] = weight_red * pixel[0] + weight_green * pixel[1] + weight_blue * pixel[2];
|
|
|
|
|
}
|
|
|
|
|
}
|
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
|
|
|
|
2012-06-15 11:03:23 +00:00
|
|
|
static void uint8_rgba_to_float_gray(const unsigned char *rgba, float *gray, int num_pixels,
|
|
|
|
|
float weight_red, float weight_green, float weight_blue)
|
|
|
|
|
{
|
|
|
|
|
int i;
|
2012-06-11 11:40:54 +00:00
|
|
|
|
2012-06-15 11:03:23 +00:00
|
|
|
for (i = 0; i < num_pixels; i++) {
|
|
|
|
|
const unsigned char *pixel = rgba + i * 4;
|
2012-06-11 08:06:42 +00:00
|
|
|
|
2012-06-15 11:03:23 +00:00
|
|
|
gray[i] = (weight_red * pixel[0] + weight_green * pixel[1] + weight_blue * pixel[2]) / 255.0f;
|
|
|
|
|
}
|
|
|
|
|
}
|
2011-11-07 12:55:18 +00:00
|
|
|
|
2012-06-15 11:03:23 +00:00
|
|
|
static float *track_get_search_floatbuf(ImBuf *ibuf, MovieTrackingTrack *track, MovieTrackingMarker *marker,
|
|
|
|
|
int *width_r, int *height_r)
|
|
|
|
|
{
|
|
|
|
|
ImBuf *searchibuf;
|
|
|
|
|
float *gray_pixels;
|
|
|
|
|
int width, height;
|
2011-11-07 12:55:18 +00:00
|
|
|
|
2012-06-15 11:03:23 +00:00
|
|
|
searchibuf = BKE_tracking_get_search_imbuf(ibuf, track, marker, FALSE, TRUE);
|
2011-11-07 12:55:18 +00:00
|
|
|
|
2012-11-07 11:18:42 +00:00
|
|
|
if (!searchibuf) {
|
|
|
|
|
*width_r = 0;
|
|
|
|
|
*height_r = 0;
|
|
|
|
|
return NULL;
|
|
|
|
|
}
|
|
|
|
|
|
2012-06-15 11:03:23 +00:00
|
|
|
width = searchibuf->x;
|
|
|
|
|
height = searchibuf->y;
|
2011-11-07 12:55:18 +00:00
|
|
|
|
2012-06-15 11:03:23 +00:00
|
|
|
gray_pixels = MEM_callocN(width * height * sizeof(float), "tracking floatBuf");
|
2011-11-07 12:55:18 +00:00
|
|
|
|
2012-06-15 11:03:23 +00:00
|
|
|
if (searchibuf->rect_float) {
|
|
|
|
|
float_rgba_to_gray(searchibuf->rect_float, gray_pixels, width * height,
|
|
|
|
|
0.2126f, 0.7152f, 0.0722f);
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
uint8_rgba_to_float_gray((unsigned char *)searchibuf->rect, gray_pixels, width * height,
|
|
|
|
|
0.2126f, 0.7152f, 0.0722f);
|
2011-11-07 12:55:18 +00:00
|
|
|
}
|
|
|
|
|
|
2012-06-15 11:03:23 +00:00
|
|
|
IMB_freeImBuf(searchibuf);
|
2011-11-07 12:55:18 +00:00
|
|
|
|
2012-06-15 11:03:23 +00:00
|
|
|
*width_r = width;
|
|
|
|
|
*height_r = height;
|
2011-11-07 12:55:18 +00:00
|
|
|
|
2012-06-15 11:03:23 +00:00
|
|
|
return gray_pixels;
|
2011-11-07 12:55:18 +00:00
|
|
|
}
|
|
|
|
|
|
2012-06-15 11:03:23 +00:00
|
|
|
static ImBuf *tracking_context_get_frame_ibuf(MovieTrackingContext *context, int framenr)
|
|
|
|
|
{
|
|
|
|
|
ImBuf *ibuf;
|
|
|
|
|
MovieClipUser user = context->user;
|
2011-11-28 13:49:42 +00:00
|
|
|
|
2012-06-15 11:03:23 +00:00
|
|
|
user.framenr = BKE_movieclip_remap_clip_to_scene_frame(context->clip, framenr);
|
2011-11-28 13:49:42 +00:00
|
|
|
|
2012-06-15 11:03:23 +00:00
|
|
|
ibuf = BKE_movieclip_get_ibuf_flag(context->clip, &user, context->clip_flag, MOVIECLIP_CACHE_SKIP);
|
2011-11-28 13:49:42 +00:00
|
|
|
|
2012-06-15 11:03:23 +00:00
|
|
|
return ibuf;
|
|
|
|
|
}
|
2011-11-28 13:49:42 +00:00
|
|
|
|
2012-09-15 05:01:52 +00:00
|
|
|
static MovieTrackingMarker *tracking_context_get_keyframed_marker(MovieTrackingContext *context, MovieTrackingTrack *track,
|
|
|
|
|
MovieTrackingMarker *marker)
|
2012-06-15 11:03:23 +00:00
|
|
|
{
|
|
|
|
|
int a = marker - track->markers;
|
|
|
|
|
MovieTrackingMarker *marker_keyed = marker;
|
2011-11-28 13:49:42 +00:00
|
|
|
|
2012-06-15 11:03:23 +00:00
|
|
|
while (a >= 0 && a < track->markersnr) {
|
|
|
|
|
int next = (context->backwards) ? a + 1 : a - 1;
|
|
|
|
|
int is_keyframed = FALSE;
|
|
|
|
|
MovieTrackingMarker *cur_marker = &track->markers[a];
|
|
|
|
|
MovieTrackingMarker *next_marker = NULL;
|
2011-11-28 13:49:42 +00:00
|
|
|
|
2012-06-15 11:03:23 +00:00
|
|
|
if (next >= 0 && next < track->markersnr)
|
|
|
|
|
next_marker = &track->markers[next];
|
2011-11-28 13:49:42 +00:00
|
|
|
|
2012-06-15 11:03:23 +00:00
|
|
|
/* if next mrker is disabled, stop searching keyframe and use current frame as keyframe */
|
|
|
|
|
if (next_marker && next_marker->flag & MARKER_DISABLED)
|
|
|
|
|
is_keyframed = TRUE;
|
2011-11-07 12:55:18 +00:00
|
|
|
|
2012-06-15 11:03:23 +00:00
|
|
|
is_keyframed |= (cur_marker->flag & MARKER_TRACKED) == 0;
|
2011-11-07 12:55:18 +00:00
|
|
|
|
2012-06-15 11:03:23 +00:00
|
|
|
if (is_keyframed) {
|
|
|
|
|
marker_keyed = cur_marker;
|
2011-11-07 12:55:18 +00:00
|
|
|
|
2012-06-15 11:03:23 +00:00
|
|
|
break;
|
2011-11-07 12:55:18 +00:00
|
|
|
}
|
|
|
|
|
|
2012-06-15 11:03:23 +00:00
|
|
|
a = next;
|
2011-11-07 12:55:18 +00:00
|
|
|
}
|
|
|
|
|
|
2012-06-15 11:03:23 +00:00
|
|
|
return marker_keyed;
|
2011-11-07 12:55:18 +00:00
|
|
|
}
|
|
|
|
|
|
2012-06-15 11:03:23 +00:00
|
|
|
static ImBuf *tracking_context_get_keyframed_ibuf(MovieTrackingContext *context, MovieTrackingTrack *track,
|
|
|
|
|
MovieTrackingMarker *marker, MovieTrackingMarker **marker_keyed_r)
|
Assorted camera tracker improvements
- Add support for refining the camera's intrinsic parameters
during a solve. Currently, refining supports only the following
combinations of intrinsic parameters:
f
f, cx, cy
f, cx, cy, k1, k2
f, k1
f, k1, k2
This is not the same as autocalibration, since the user must
still make a reasonable initial guess about the focal length and
other parameters, whereas true autocalibration would eliminate
the need for the user specify intrinsic parameters at all.
However, the solver works well with only rough guesses for the
focal length, so perhaps full autocalibation is not that
important.
Adding support for the last two combinations, (f, k1) and (f,
k1, k2) required changes to the library libmv depends on for
bundle adjustment, SSBA. These changes should get ported
upstream not just to libmv but to SSBA as well.
- Improved the region of convergence for bundle adjustment by
increasing the number of Levenberg-Marquardt iterations from 50
to 500. This way, the solver is able to crawl out of the bad
local minima it gets stuck in when changing from, for example,
bundling k1 and k2 to just k1 and resetting k2 to 0.
- Add several new region tracker implementations. A region tracker
is a libmv concept, which refers to tracking a template image
pattern through frames. The impact to end users is that tracking
should "just work better". I am reserving a more detailed
writeup, and maybe a paper, for later.
- Other libmv tweaks, such as detecting that a tracker is headed
outside of the image bounds.
This includes several changes made directly to the libmv extern
code rather expecting to get those changes through normal libmv
channels, because I, the libmv BDFL, decided it was faster to work
on libmv directly in Blender, then later reverse-port the libmv
changes from Blender back into libmv trunk. The interesting part
is that I added a full Levenberg-Marquardt loop to the region
tracking code, which should lead to a more stable solutions. I
also added a hacky implementation of "Efficient Second-Order
Minimization" for tracking, which works nicely. A more detailed
quantitative evaluation will follow.
Original patch by Keir, cleaned a bit by myself.
2011-11-14 06:41:23 +00:00
|
|
|
{
|
2012-06-15 11:03:23 +00:00
|
|
|
MovieTrackingMarker *marker_keyed;
|
|
|
|
|
int keyed_framenr;
|
Assorted camera tracker improvements
- Add support for refining the camera's intrinsic parameters
during a solve. Currently, refining supports only the following
combinations of intrinsic parameters:
f
f, cx, cy
f, cx, cy, k1, k2
f, k1
f, k1, k2
This is not the same as autocalibration, since the user must
still make a reasonable initial guess about the focal length and
other parameters, whereas true autocalibration would eliminate
the need for the user specify intrinsic parameters at all.
However, the solver works well with only rough guesses for the
focal length, so perhaps full autocalibation is not that
important.
Adding support for the last two combinations, (f, k1) and (f,
k1, k2) required changes to the library libmv depends on for
bundle adjustment, SSBA. These changes should get ported
upstream not just to libmv but to SSBA as well.
- Improved the region of convergence for bundle adjustment by
increasing the number of Levenberg-Marquardt iterations from 50
to 500. This way, the solver is able to crawl out of the bad
local minima it gets stuck in when changing from, for example,
bundling k1 and k2 to just k1 and resetting k2 to 0.
- Add several new region tracker implementations. A region tracker
is a libmv concept, which refers to tracking a template image
pattern through frames. The impact to end users is that tracking
should "just work better". I am reserving a more detailed
writeup, and maybe a paper, for later.
- Other libmv tweaks, such as detecting that a tracker is headed
outside of the image bounds.
This includes several changes made directly to the libmv extern
code rather expecting to get those changes through normal libmv
channels, because I, the libmv BDFL, decided it was faster to work
on libmv directly in Blender, then later reverse-port the libmv
changes from Blender back into libmv trunk. The interesting part
is that I added a full Levenberg-Marquardt loop to the region
tracking code, which should lead to a more stable solutions. I
also added a hacky implementation of "Efficient Second-Order
Minimization" for tracking, which works nicely. A more detailed
quantitative evaluation will follow.
Original patch by Keir, cleaned a bit by myself.
2011-11-14 06:41:23 +00:00
|
|
|
|
2012-06-15 11:03:23 +00:00
|
|
|
marker_keyed = tracking_context_get_keyframed_marker(context, track, marker);
|
|
|
|
|
keyed_framenr = marker_keyed->framenr;
|
Assorted camera tracker improvements
- Add support for refining the camera's intrinsic parameters
during a solve. Currently, refining supports only the following
combinations of intrinsic parameters:
f
f, cx, cy
f, cx, cy, k1, k2
f, k1
f, k1, k2
This is not the same as autocalibration, since the user must
still make a reasonable initial guess about the focal length and
other parameters, whereas true autocalibration would eliminate
the need for the user specify intrinsic parameters at all.
However, the solver works well with only rough guesses for the
focal length, so perhaps full autocalibation is not that
important.
Adding support for the last two combinations, (f, k1) and (f,
k1, k2) required changes to the library libmv depends on for
bundle adjustment, SSBA. These changes should get ported
upstream not just to libmv but to SSBA as well.
- Improved the region of convergence for bundle adjustment by
increasing the number of Levenberg-Marquardt iterations from 50
to 500. This way, the solver is able to crawl out of the bad
local minima it gets stuck in when changing from, for example,
bundling k1 and k2 to just k1 and resetting k2 to 0.
- Add several new region tracker implementations. A region tracker
is a libmv concept, which refers to tracking a template image
pattern through frames. The impact to end users is that tracking
should "just work better". I am reserving a more detailed
writeup, and maybe a paper, for later.
- Other libmv tweaks, such as detecting that a tracker is headed
outside of the image bounds.
This includes several changes made directly to the libmv extern
code rather expecting to get those changes through normal libmv
channels, because I, the libmv BDFL, decided it was faster to work
on libmv directly in Blender, then later reverse-port the libmv
changes from Blender back into libmv trunk. The interesting part
is that I added a full Levenberg-Marquardt loop to the region
tracking code, which should lead to a more stable solutions. I
also added a hacky implementation of "Efficient Second-Order
Minimization" for tracking, which works nicely. A more detailed
quantitative evaluation will follow.
Original patch by Keir, cleaned a bit by myself.
2011-11-14 06:41:23 +00:00
|
|
|
|
2012-06-15 11:03:23 +00:00
|
|
|
*marker_keyed_r = marker_keyed;
|
Assorted camera tracker improvements
- Add support for refining the camera's intrinsic parameters
during a solve. Currently, refining supports only the following
combinations of intrinsic parameters:
f
f, cx, cy
f, cx, cy, k1, k2
f, k1
f, k1, k2
This is not the same as autocalibration, since the user must
still make a reasonable initial guess about the focal length and
other parameters, whereas true autocalibration would eliminate
the need for the user specify intrinsic parameters at all.
However, the solver works well with only rough guesses for the
focal length, so perhaps full autocalibation is not that
important.
Adding support for the last two combinations, (f, k1) and (f,
k1, k2) required changes to the library libmv depends on for
bundle adjustment, SSBA. These changes should get ported
upstream not just to libmv but to SSBA as well.
- Improved the region of convergence for bundle adjustment by
increasing the number of Levenberg-Marquardt iterations from 50
to 500. This way, the solver is able to crawl out of the bad
local minima it gets stuck in when changing from, for example,
bundling k1 and k2 to just k1 and resetting k2 to 0.
- Add several new region tracker implementations. A region tracker
is a libmv concept, which refers to tracking a template image
pattern through frames. The impact to end users is that tracking
should "just work better". I am reserving a more detailed
writeup, and maybe a paper, for later.
- Other libmv tweaks, such as detecting that a tracker is headed
outside of the image bounds.
This includes several changes made directly to the libmv extern
code rather expecting to get those changes through normal libmv
channels, because I, the libmv BDFL, decided it was faster to work
on libmv directly in Blender, then later reverse-port the libmv
changes from Blender back into libmv trunk. The interesting part
is that I added a full Levenberg-Marquardt loop to the region
tracking code, which should lead to a more stable solutions. I
also added a hacky implementation of "Efficient Second-Order
Minimization" for tracking, which works nicely. A more detailed
quantitative evaluation will follow.
Original patch by Keir, cleaned a bit by myself.
2011-11-14 06:41:23 +00:00
|
|
|
|
2012-06-15 11:03:23 +00:00
|
|
|
return tracking_context_get_frame_ibuf(context, keyed_framenr);
|
Assorted camera tracker improvements
- Add support for refining the camera's intrinsic parameters
during a solve. Currently, refining supports only the following
combinations of intrinsic parameters:
f
f, cx, cy
f, cx, cy, k1, k2
f, k1
f, k1, k2
This is not the same as autocalibration, since the user must
still make a reasonable initial guess about the focal length and
other parameters, whereas true autocalibration would eliminate
the need for the user specify intrinsic parameters at all.
However, the solver works well with only rough guesses for the
focal length, so perhaps full autocalibation is not that
important.
Adding support for the last two combinations, (f, k1) and (f,
k1, k2) required changes to the library libmv depends on for
bundle adjustment, SSBA. These changes should get ported
upstream not just to libmv but to SSBA as well.
- Improved the region of convergence for bundle adjustment by
increasing the number of Levenberg-Marquardt iterations from 50
to 500. This way, the solver is able to crawl out of the bad
local minima it gets stuck in when changing from, for example,
bundling k1 and k2 to just k1 and resetting k2 to 0.
- Add several new region tracker implementations. A region tracker
is a libmv concept, which refers to tracking a template image
pattern through frames. The impact to end users is that tracking
should "just work better". I am reserving a more detailed
writeup, and maybe a paper, for later.
- Other libmv tweaks, such as detecting that a tracker is headed
outside of the image bounds.
This includes several changes made directly to the libmv extern
code rather expecting to get those changes through normal libmv
channels, because I, the libmv BDFL, decided it was faster to work
on libmv directly in Blender, then later reverse-port the libmv
changes from Blender back into libmv trunk. The interesting part
is that I added a full Levenberg-Marquardt loop to the region
tracking code, which should lead to a more stable solutions. I
also added a hacky implementation of "Efficient Second-Order
Minimization" for tracking, which works nicely. A more detailed
quantitative evaluation will follow.
Original patch by Keir, cleaned a bit by myself.
2011-11-14 06:41:23 +00:00
|
|
|
}
|
|
|
|
|
|
2012-06-15 11:03:23 +00:00
|
|
|
static ImBuf *tracking_context_get_reference_ibuf(MovieTrackingContext *context, MovieTrackingTrack *track,
|
|
|
|
|
MovieTrackingMarker *marker, int curfra,
|
|
|
|
|
MovieTrackingMarker **marker_keyed)
|
2011-11-07 12:55:18 +00:00
|
|
|
{
|
2012-06-15 11:03:23 +00:00
|
|
|
ImBuf *ibuf = NULL;
|
2011-11-18 14:42:18 +00:00
|
|
|
|
2012-06-15 11:03:23 +00:00
|
|
|
if (track->pattern_match == TRACK_MATCH_KEYFRAME) {
|
|
|
|
|
ibuf = tracking_context_get_keyframed_ibuf(context, track, marker, marker_keyed);
|
2011-12-05 18:57:17 +00:00
|
|
|
}
|
|
|
|
|
else {
|
2012-06-15 11:03:23 +00:00
|
|
|
ibuf = tracking_context_get_frame_ibuf(context, curfra);
|
2011-12-05 18:57:17 +00:00
|
|
|
|
2012-06-15 11:03:23 +00:00
|
|
|
/* use current marker as keyframed position */
|
|
|
|
|
*marker_keyed = marker;
|
2011-12-05 18:57:17 +00:00
|
|
|
}
|
|
|
|
|
|
2012-06-15 11:03:23 +00:00
|
|
|
return ibuf;
|
|
|
|
|
}
|
2011-11-07 12:55:18 +00:00
|
|
|
|
2012-09-19 12:43:32 +00:00
|
|
|
static int track_context_update_reference(MovieTrackingContext *context, TrackContext *track_context,
|
|
|
|
|
MovieTrackingTrack *track, MovieTrackingMarker *marker, int curfra,
|
|
|
|
|
int frame_width, int frame_height)
|
2012-06-15 11:03:23 +00:00
|
|
|
{
|
|
|
|
|
MovieTrackingMarker *marker_keyed = NULL;
|
|
|
|
|
ImBuf *reference_ibuf = NULL;
|
|
|
|
|
int width, height;
|
2011-11-07 12:55:18 +00:00
|
|
|
|
2012-06-15 11:03:23 +00:00
|
|
|
/* calculate patch for keyframed position */
|
|
|
|
|
reference_ibuf = tracking_context_get_reference_ibuf(context, track, marker, curfra, &marker_keyed);
|
2012-09-19 12:43:32 +00:00
|
|
|
|
|
|
|
|
if (!reference_ibuf)
|
|
|
|
|
return FALSE;
|
|
|
|
|
|
2012-06-15 11:03:23 +00:00
|
|
|
track_context->marker = *marker_keyed;
|
2011-11-07 12:55:18 +00:00
|
|
|
|
2012-06-15 11:03:23 +00:00
|
|
|
if (track_context->search_area) {
|
|
|
|
|
MEM_freeN(track_context->search_area);
|
|
|
|
|
}
|
2011-11-07 12:55:18 +00:00
|
|
|
|
2012-06-15 11:03:23 +00:00
|
|
|
track_context->search_area = track_get_search_floatbuf(reference_ibuf, track, marker_keyed, &width, &height);
|
|
|
|
|
track_context->search_area_height = height;
|
|
|
|
|
track_context->search_area_width = width;
|
2011-11-07 12:55:18 +00:00
|
|
|
|
2012-06-15 11:03:23 +00:00
|
|
|
if ((track->algorithm_flag & TRACK_ALGORITHM_FLAG_USE_MASK) != 0) {
|
|
|
|
|
if (track_context->mask)
|
|
|
|
|
MEM_freeN(track_context->mask);
|
|
|
|
|
|
|
|
|
|
track_context->mask = BKE_tracking_track_get_mask(frame_width, frame_height, track, marker);
|
2011-11-07 12:55:18 +00:00
|
|
|
}
|
|
|
|
|
|
2012-06-15 11:03:23 +00:00
|
|
|
IMB_freeImBuf(reference_ibuf);
|
2012-09-19 12:43:32 +00:00
|
|
|
|
|
|
|
|
return TRUE;
|
2012-06-15 11:03:23 +00:00
|
|
|
}
|
2011-11-07 12:55:18 +00:00
|
|
|
|
2012-06-15 11:03:23 +00:00
|
|
|
static void tracking_configure_tracker(TrackContext *track_context, MovieTrackingTrack *track,
|
|
|
|
|
struct libmv_trackRegionOptions *options)
|
|
|
|
|
{
|
|
|
|
|
options->motion_model = track->motion_model;
|
2011-11-07 12:55:18 +00:00
|
|
|
|
2012-06-15 11:03:23 +00:00
|
|
|
options->use_brute = ((track->algorithm_flag & TRACK_ALGORITHM_FLAG_USE_BRUTE) != 0);
|
2011-11-07 12:55:18 +00:00
|
|
|
|
2012-06-15 11:03:23 +00:00
|
|
|
options->use_normalization = ((track->algorithm_flag & TRACK_ALGORITHM_FLAG_USE_NORMALIZATION) != 0);
|
2011-11-07 12:55:18 +00:00
|
|
|
|
2012-06-15 11:03:23 +00:00
|
|
|
options->num_iterations = 50;
|
|
|
|
|
options->minimum_correlation = track->minimum_correlation;
|
|
|
|
|
options->sigma = 0.9;
|
2011-11-07 12:55:18 +00:00
|
|
|
|
2012-06-15 11:03:23 +00:00
|
|
|
if ((track->algorithm_flag & TRACK_ALGORITHM_FLAG_USE_MASK) != 0)
|
|
|
|
|
options->image1_mask = track_context->mask;
|
|
|
|
|
}
|
2011-11-07 12:55:18 +00:00
|
|
|
|
2012-06-15 11:03:23 +00:00
|
|
|
/* returns FALSE if marker crossed margin area from frame bounds */
|
|
|
|
|
static int tracking_check_marker_margin(MovieTrackingTrack *track, MovieTrackingMarker *marker,
|
|
|
|
|
int frame_width, int frame_height)
|
|
|
|
|
{
|
|
|
|
|
float pat_min[2], pat_max[2], dim[2], margin[2];
|
2011-11-07 12:55:18 +00:00
|
|
|
|
2012-06-15 11:03:23 +00:00
|
|
|
/* margin from frame boundaries */
|
|
|
|
|
BKE_tracking_marker_pattern_minmax(marker, pat_min, pat_max);
|
|
|
|
|
sub_v2_v2v2(dim, pat_max, pat_min);
|
2012-10-23 13:28:22 +00:00
|
|
|
margin[0] = margin[1] = max_ff(dim[0], dim[1]) / 2.0f;
|
2011-11-07 12:55:18 +00:00
|
|
|
|
2012-10-23 13:28:22 +00:00
|
|
|
margin[0] = max_ff(margin[0], (float)track->margin / frame_width);
|
|
|
|
|
margin[1] = max_ff(margin[1], (float)track->margin / frame_height);
|
2012-06-15 11:03:23 +00:00
|
|
|
|
|
|
|
|
/* do not track markers which are too close to boundary */
|
|
|
|
|
if (marker->pos[0] < margin[0] || marker->pos[0] > 1.0f - margin[0] ||
|
|
|
|
|
marker->pos[1] < margin[1] || marker->pos[1] > 1.0f - margin[1])
|
|
|
|
|
{
|
|
|
|
|
return FALSE;
|
2011-11-07 12:55:18 +00:00
|
|
|
}
|
|
|
|
|
|
2012-06-15 11:03:23 +00:00
|
|
|
return TRUE;
|
|
|
|
|
}
|
2011-11-07 12:55:18 +00:00
|
|
|
|
2012-06-15 11:03:23 +00:00
|
|
|
static void tracking_scale_marker_search(const MovieTrackingMarker *old_marker, MovieTrackingMarker *new_marker)
|
|
|
|
|
{
|
|
|
|
|
float old_pat_min[2], old_pat_max[2];
|
|
|
|
|
float new_pat_min[2], new_pat_max[2];
|
|
|
|
|
float scale_x, scale_y;
|
2011-11-07 12:55:18 +00:00
|
|
|
|
2012-06-15 11:03:23 +00:00
|
|
|
BKE_tracking_marker_pattern_minmax(old_marker, old_pat_min, old_pat_max);
|
|
|
|
|
BKE_tracking_marker_pattern_minmax(new_marker, new_pat_min, new_pat_max);
|
2011-11-07 12:55:18 +00:00
|
|
|
|
2012-06-15 11:03:23 +00:00
|
|
|
scale_x = (new_pat_max[0] - new_pat_min[0]) / (old_pat_max[0] - old_pat_min[0]);
|
|
|
|
|
scale_y = (new_pat_max[1] - new_pat_min[1]) / (old_pat_max[1] - old_pat_min[1]);
|
2011-11-07 12:55:18 +00:00
|
|
|
|
2012-06-15 11:03:23 +00:00
|
|
|
new_marker->search_min[0] *= scale_x;
|
|
|
|
|
new_marker->search_min[1] *= scale_y;
|
Assorted camera tracker improvements
- Add support for refining the camera's intrinsic parameters
during a solve. Currently, refining supports only the following
combinations of intrinsic parameters:
f
f, cx, cy
f, cx, cy, k1, k2
f, k1
f, k1, k2
This is not the same as autocalibration, since the user must
still make a reasonable initial guess about the focal length and
other parameters, whereas true autocalibration would eliminate
the need for the user specify intrinsic parameters at all.
However, the solver works well with only rough guesses for the
focal length, so perhaps full autocalibation is not that
important.
Adding support for the last two combinations, (f, k1) and (f,
k1, k2) required changes to the library libmv depends on for
bundle adjustment, SSBA. These changes should get ported
upstream not just to libmv but to SSBA as well.
- Improved the region of convergence for bundle adjustment by
increasing the number of Levenberg-Marquardt iterations from 50
to 500. This way, the solver is able to crawl out of the bad
local minima it gets stuck in when changing from, for example,
bundling k1 and k2 to just k1 and resetting k2 to 0.
- Add several new region tracker implementations. A region tracker
is a libmv concept, which refers to tracking a template image
pattern through frames. The impact to end users is that tracking
should "just work better". I am reserving a more detailed
writeup, and maybe a paper, for later.
- Other libmv tweaks, such as detecting that a tracker is headed
outside of the image bounds.
This includes several changes made directly to the libmv extern
code rather expecting to get those changes through normal libmv
channels, because I, the libmv BDFL, decided it was faster to work
on libmv directly in Blender, then later reverse-port the libmv
changes from Blender back into libmv trunk. The interesting part
is that I added a full Levenberg-Marquardt loop to the region
tracking code, which should lead to a more stable solutions. I
also added a hacky implementation of "Efficient Second-Order
Minimization" for tracking, which works nicely. A more detailed
quantitative evaluation will follow.
Original patch by Keir, cleaned a bit by myself.
2011-11-14 06:41:23 +00:00
|
|
|
|
2012-06-15 11:03:23 +00:00
|
|
|
new_marker->search_max[0] *= scale_x;
|
|
|
|
|
new_marker->search_max[1] *= scale_y;
|
Assorted camera tracker improvements
- Add support for refining the camera's intrinsic parameters
during a solve. Currently, refining supports only the following
combinations of intrinsic parameters:
f
f, cx, cy
f, cx, cy, k1, k2
f, k1
f, k1, k2
This is not the same as autocalibration, since the user must
still make a reasonable initial guess about the focal length and
other parameters, whereas true autocalibration would eliminate
the need for the user specify intrinsic parameters at all.
However, the solver works well with only rough guesses for the
focal length, so perhaps full autocalibation is not that
important.
Adding support for the last two combinations, (f, k1) and (f,
k1, k2) required changes to the library libmv depends on for
bundle adjustment, SSBA. These changes should get ported
upstream not just to libmv but to SSBA as well.
- Improved the region of convergence for bundle adjustment by
increasing the number of Levenberg-Marquardt iterations from 50
to 500. This way, the solver is able to crawl out of the bad
local minima it gets stuck in when changing from, for example,
bundling k1 and k2 to just k1 and resetting k2 to 0.
- Add several new region tracker implementations. A region tracker
is a libmv concept, which refers to tracking a template image
pattern through frames. The impact to end users is that tracking
should "just work better". I am reserving a more detailed
writeup, and maybe a paper, for later.
- Other libmv tweaks, such as detecting that a tracker is headed
outside of the image bounds.
This includes several changes made directly to the libmv extern
code rather expecting to get those changes through normal libmv
channels, because I, the libmv BDFL, decided it was faster to work
on libmv directly in Blender, then later reverse-port the libmv
changes from Blender back into libmv trunk. The interesting part
is that I added a full Levenberg-Marquardt loop to the region
tracking code, which should lead to a more stable solutions. I
also added a hacky implementation of "Efficient Second-Order
Minimization" for tracking, which works nicely. A more detailed
quantitative evaluation will follow.
Original patch by Keir, cleaned a bit by myself.
2011-11-14 06:41:23 +00:00
|
|
|
}
|
|
|
|
|
|
2012-06-15 11:03:23 +00:00
|
|
|
static void tracking_insert_new_marker(MovieTrackingContext *context, MovieTrackingTrack *track,
|
|
|
|
|
const MovieTrackingMarker *old_marker, int curfra, int tracked,
|
|
|
|
|
int frame_width, int frame_height,
|
|
|
|
|
double dst_pixel_x[5], double dst_pixel_y[5])
|
Assorted camera tracker improvements
- Add support for refining the camera's intrinsic parameters
during a solve. Currently, refining supports only the following
combinations of intrinsic parameters:
f
f, cx, cy
f, cx, cy, k1, k2
f, k1
f, k1, k2
This is not the same as autocalibration, since the user must
still make a reasonable initial guess about the focal length and
other parameters, whereas true autocalibration would eliminate
the need for the user specify intrinsic parameters at all.
However, the solver works well with only rough guesses for the
focal length, so perhaps full autocalibation is not that
important.
Adding support for the last two combinations, (f, k1) and (f,
k1, k2) required changes to the library libmv depends on for
bundle adjustment, SSBA. These changes should get ported
upstream not just to libmv but to SSBA as well.
- Improved the region of convergence for bundle adjustment by
increasing the number of Levenberg-Marquardt iterations from 50
to 500. This way, the solver is able to crawl out of the bad
local minima it gets stuck in when changing from, for example,
bundling k1 and k2 to just k1 and resetting k2 to 0.
- Add several new region tracker implementations. A region tracker
is a libmv concept, which refers to tracking a template image
pattern through frames. The impact to end users is that tracking
should "just work better". I am reserving a more detailed
writeup, and maybe a paper, for later.
- Other libmv tweaks, such as detecting that a tracker is headed
outside of the image bounds.
This includes several changes made directly to the libmv extern
code rather expecting to get those changes through normal libmv
channels, because I, the libmv BDFL, decided it was faster to work
on libmv directly in Blender, then later reverse-port the libmv
changes from Blender back into libmv trunk. The interesting part
is that I added a full Levenberg-Marquardt loop to the region
tracking code, which should lead to a more stable solutions. I
also added a hacky implementation of "Efficient Second-Order
Minimization" for tracking, which works nicely. A more detailed
quantitative evaluation will follow.
Original patch by Keir, cleaned a bit by myself.
2011-11-14 06:41:23 +00:00
|
|
|
{
|
2012-06-15 11:03:23 +00:00
|
|
|
MovieTrackingMarker new_marker;
|
|
|
|
|
int frame_delta = context->backwards ? -1 : 1;
|
|
|
|
|
int nextfra = curfra + frame_delta;
|
Assorted camera tracker improvements
- Add support for refining the camera's intrinsic parameters
during a solve. Currently, refining supports only the following
combinations of intrinsic parameters:
f
f, cx, cy
f, cx, cy, k1, k2
f, k1
f, k1, k2
This is not the same as autocalibration, since the user must
still make a reasonable initial guess about the focal length and
other parameters, whereas true autocalibration would eliminate
the need for the user specify intrinsic parameters at all.
However, the solver works well with only rough guesses for the
focal length, so perhaps full autocalibation is not that
important.
Adding support for the last two combinations, (f, k1) and (f,
k1, k2) required changes to the library libmv depends on for
bundle adjustment, SSBA. These changes should get ported
upstream not just to libmv but to SSBA as well.
- Improved the region of convergence for bundle adjustment by
increasing the number of Levenberg-Marquardt iterations from 50
to 500. This way, the solver is able to crawl out of the bad
local minima it gets stuck in when changing from, for example,
bundling k1 and k2 to just k1 and resetting k2 to 0.
- Add several new region tracker implementations. A region tracker
is a libmv concept, which refers to tracking a template image
pattern through frames. The impact to end users is that tracking
should "just work better". I am reserving a more detailed
writeup, and maybe a paper, for later.
- Other libmv tweaks, such as detecting that a tracker is headed
outside of the image bounds.
This includes several changes made directly to the libmv extern
code rather expecting to get those changes through normal libmv
channels, because I, the libmv BDFL, decided it was faster to work
on libmv directly in Blender, then later reverse-port the libmv
changes from Blender back into libmv trunk. The interesting part
is that I added a full Levenberg-Marquardt loop to the region
tracking code, which should lead to a more stable solutions. I
also added a hacky implementation of "Efficient Second-Order
Minimization" for tracking, which works nicely. A more detailed
quantitative evaluation will follow.
Original patch by Keir, cleaned a bit by myself.
2011-11-14 06:41:23 +00:00
|
|
|
|
2012-06-15 11:03:23 +00:00
|
|
|
new_marker = *old_marker;
|
Assorted camera tracker improvements
- Add support for refining the camera's intrinsic parameters
during a solve. Currently, refining supports only the following
combinations of intrinsic parameters:
f
f, cx, cy
f, cx, cy, k1, k2
f, k1
f, k1, k2
This is not the same as autocalibration, since the user must
still make a reasonable initial guess about the focal length and
other parameters, whereas true autocalibration would eliminate
the need for the user specify intrinsic parameters at all.
However, the solver works well with only rough guesses for the
focal length, so perhaps full autocalibation is not that
important.
Adding support for the last two combinations, (f, k1) and (f,
k1, k2) required changes to the library libmv depends on for
bundle adjustment, SSBA. These changes should get ported
upstream not just to libmv but to SSBA as well.
- Improved the region of convergence for bundle adjustment by
increasing the number of Levenberg-Marquardt iterations from 50
to 500. This way, the solver is able to crawl out of the bad
local minima it gets stuck in when changing from, for example,
bundling k1 and k2 to just k1 and resetting k2 to 0.
- Add several new region tracker implementations. A region tracker
is a libmv concept, which refers to tracking a template image
pattern through frames. The impact to end users is that tracking
should "just work better". I am reserving a more detailed
writeup, and maybe a paper, for later.
- Other libmv tweaks, such as detecting that a tracker is headed
outside of the image bounds.
This includes several changes made directly to the libmv extern
code rather expecting to get those changes through normal libmv
channels, because I, the libmv BDFL, decided it was faster to work
on libmv directly in Blender, then later reverse-port the libmv
changes from Blender back into libmv trunk. The interesting part
is that I added a full Levenberg-Marquardt loop to the region
tracking code, which should lead to a more stable solutions. I
also added a hacky implementation of "Efficient Second-Order
Minimization" for tracking, which works nicely. A more detailed
quantitative evaluation will follow.
Original patch by Keir, cleaned a bit by myself.
2011-11-14 06:41:23 +00:00
|
|
|
|
2012-06-15 11:03:23 +00:00
|
|
|
if (tracked) {
|
|
|
|
|
set_marker_coords_from_tracking(frame_width, frame_height, &new_marker, dst_pixel_x, dst_pixel_y);
|
|
|
|
|
new_marker.flag |= MARKER_TRACKED;
|
|
|
|
|
new_marker.framenr = nextfra;
|
Assorted camera tracker improvements
- Add support for refining the camera's intrinsic parameters
during a solve. Currently, refining supports only the following
combinations of intrinsic parameters:
f
f, cx, cy
f, cx, cy, k1, k2
f, k1
f, k1, k2
This is not the same as autocalibration, since the user must
still make a reasonable initial guess about the focal length and
other parameters, whereas true autocalibration would eliminate
the need for the user specify intrinsic parameters at all.
However, the solver works well with only rough guesses for the
focal length, so perhaps full autocalibation is not that
important.
Adding support for the last two combinations, (f, k1) and (f,
k1, k2) required changes to the library libmv depends on for
bundle adjustment, SSBA. These changes should get ported
upstream not just to libmv but to SSBA as well.
- Improved the region of convergence for bundle adjustment by
increasing the number of Levenberg-Marquardt iterations from 50
to 500. This way, the solver is able to crawl out of the bad
local minima it gets stuck in when changing from, for example,
bundling k1 and k2 to just k1 and resetting k2 to 0.
- Add several new region tracker implementations. A region tracker
is a libmv concept, which refers to tracking a template image
pattern through frames. The impact to end users is that tracking
should "just work better". I am reserving a more detailed
writeup, and maybe a paper, for later.
- Other libmv tweaks, such as detecting that a tracker is headed
outside of the image bounds.
This includes several changes made directly to the libmv extern
code rather expecting to get those changes through normal libmv
channels, because I, the libmv BDFL, decided it was faster to work
on libmv directly in Blender, then later reverse-port the libmv
changes from Blender back into libmv trunk. The interesting part
is that I added a full Levenberg-Marquardt loop to the region
tracking code, which should lead to a more stable solutions. I
also added a hacky implementation of "Efficient Second-Order
Minimization" for tracking, which works nicely. A more detailed
quantitative evaluation will follow.
Original patch by Keir, cleaned a bit by myself.
2011-11-14 06:41:23 +00:00
|
|
|
|
2012-06-15 11:03:23 +00:00
|
|
|
tracking_scale_marker_search(old_marker, &new_marker);
|
Assorted camera tracker improvements
- Add support for refining the camera's intrinsic parameters
during a solve. Currently, refining supports only the following
combinations of intrinsic parameters:
f
f, cx, cy
f, cx, cy, k1, k2
f, k1
f, k1, k2
This is not the same as autocalibration, since the user must
still make a reasonable initial guess about the focal length and
other parameters, whereas true autocalibration would eliminate
the need for the user specify intrinsic parameters at all.
However, the solver works well with only rough guesses for the
focal length, so perhaps full autocalibation is not that
important.
Adding support for the last two combinations, (f, k1) and (f,
k1, k2) required changes to the library libmv depends on for
bundle adjustment, SSBA. These changes should get ported
upstream not just to libmv but to SSBA as well.
- Improved the region of convergence for bundle adjustment by
increasing the number of Levenberg-Marquardt iterations from 50
to 500. This way, the solver is able to crawl out of the bad
local minima it gets stuck in when changing from, for example,
bundling k1 and k2 to just k1 and resetting k2 to 0.
- Add several new region tracker implementations. A region tracker
is a libmv concept, which refers to tracking a template image
pattern through frames. The impact to end users is that tracking
should "just work better". I am reserving a more detailed
writeup, and maybe a paper, for later.
- Other libmv tweaks, such as detecting that a tracker is headed
outside of the image bounds.
This includes several changes made directly to the libmv extern
code rather expecting to get those changes through normal libmv
channels, because I, the libmv BDFL, decided it was faster to work
on libmv directly in Blender, then later reverse-port the libmv
changes from Blender back into libmv trunk. The interesting part
is that I added a full Levenberg-Marquardt loop to the region
tracking code, which should lead to a more stable solutions. I
also added a hacky implementation of "Efficient Second-Order
Minimization" for tracking, which works nicely. A more detailed
quantitative evaluation will follow.
Original patch by Keir, cleaned a bit by myself.
2011-11-14 06:41:23 +00:00
|
|
|
|
2012-06-15 11:03:23 +00:00
|
|
|
if (context->first_time) {
|
|
|
|
|
/* check if there's no keyframe/tracked markers before tracking marker.
|
|
|
|
|
* if so -- create disabled marker before currently tracking "segment"
|
|
|
|
|
*/
|
Assorted camera tracker improvements
- Add support for refining the camera's intrinsic parameters
during a solve. Currently, refining supports only the following
combinations of intrinsic parameters:
f
f, cx, cy
f, cx, cy, k1, k2
f, k1
f, k1, k2
This is not the same as autocalibration, since the user must
still make a reasonable initial guess about the focal length and
other parameters, whereas true autocalibration would eliminate
the need for the user specify intrinsic parameters at all.
However, the solver works well with only rough guesses for the
focal length, so perhaps full autocalibation is not that
important.
Adding support for the last two combinations, (f, k1) and (f,
k1, k2) required changes to the library libmv depends on for
bundle adjustment, SSBA. These changes should get ported
upstream not just to libmv but to SSBA as well.
- Improved the region of convergence for bundle adjustment by
increasing the number of Levenberg-Marquardt iterations from 50
to 500. This way, the solver is able to crawl out of the bad
local minima it gets stuck in when changing from, for example,
bundling k1 and k2 to just k1 and resetting k2 to 0.
- Add several new region tracker implementations. A region tracker
is a libmv concept, which refers to tracking a template image
pattern through frames. The impact to end users is that tracking
should "just work better". I am reserving a more detailed
writeup, and maybe a paper, for later.
- Other libmv tweaks, such as detecting that a tracker is headed
outside of the image bounds.
This includes several changes made directly to the libmv extern
code rather expecting to get those changes through normal libmv
channels, because I, the libmv BDFL, decided it was faster to work
on libmv directly in Blender, then later reverse-port the libmv
changes from Blender back into libmv trunk. The interesting part
is that I added a full Levenberg-Marquardt loop to the region
tracking code, which should lead to a more stable solutions. I
also added a hacky implementation of "Efficient Second-Order
Minimization" for tracking, which works nicely. A more detailed
quantitative evaluation will follow.
Original patch by Keir, cleaned a bit by myself.
2011-11-14 06:41:23 +00:00
|
|
|
|
2012-09-27 14:47:23 +00:00
|
|
|
tracking_marker_insert_disabled(track, old_marker, !context->backwards, FALSE);
|
2012-06-15 11:03:23 +00:00
|
|
|
}
|
Assorted camera tracker improvements
- Add support for refining the camera's intrinsic parameters
during a solve. Currently, refining supports only the following
combinations of intrinsic parameters:
f
f, cx, cy
f, cx, cy, k1, k2
f, k1
f, k1, k2
This is not the same as autocalibration, since the user must
still make a reasonable initial guess about the focal length and
other parameters, whereas true autocalibration would eliminate
the need for the user specify intrinsic parameters at all.
However, the solver works well with only rough guesses for the
focal length, so perhaps full autocalibation is not that
important.
Adding support for the last two combinations, (f, k1) and (f,
k1, k2) required changes to the library libmv depends on for
bundle adjustment, SSBA. These changes should get ported
upstream not just to libmv but to SSBA as well.
- Improved the region of convergence for bundle adjustment by
increasing the number of Levenberg-Marquardt iterations from 50
to 500. This way, the solver is able to crawl out of the bad
local minima it gets stuck in when changing from, for example,
bundling k1 and k2 to just k1 and resetting k2 to 0.
- Add several new region tracker implementations. A region tracker
is a libmv concept, which refers to tracking a template image
pattern through frames. The impact to end users is that tracking
should "just work better". I am reserving a more detailed
writeup, and maybe a paper, for later.
- Other libmv tweaks, such as detecting that a tracker is headed
outside of the image bounds.
This includes several changes made directly to the libmv extern
code rather expecting to get those changes through normal libmv
channels, because I, the libmv BDFL, decided it was faster to work
on libmv directly in Blender, then later reverse-port the libmv
changes from Blender back into libmv trunk. The interesting part
is that I added a full Levenberg-Marquardt loop to the region
tracking code, which should lead to a more stable solutions. I
also added a hacky implementation of "Efficient Second-Order
Minimization" for tracking, which works nicely. A more detailed
quantitative evaluation will follow.
Original patch by Keir, cleaned a bit by myself.
2011-11-14 06:41:23 +00:00
|
|
|
|
2012-06-15 11:03:23 +00:00
|
|
|
/* insert currently tracked marker */
|
|
|
|
|
BKE_tracking_marker_insert(track, &new_marker);
|
Assorted camera tracker improvements
- Add support for refining the camera's intrinsic parameters
during a solve. Currently, refining supports only the following
combinations of intrinsic parameters:
f
f, cx, cy
f, cx, cy, k1, k2
f, k1
f, k1, k2
This is not the same as autocalibration, since the user must
still make a reasonable initial guess about the focal length and
other parameters, whereas true autocalibration would eliminate
the need for the user specify intrinsic parameters at all.
However, the solver works well with only rough guesses for the
focal length, so perhaps full autocalibation is not that
important.
Adding support for the last two combinations, (f, k1) and (f,
k1, k2) required changes to the library libmv depends on for
bundle adjustment, SSBA. These changes should get ported
upstream not just to libmv but to SSBA as well.
- Improved the region of convergence for bundle adjustment by
increasing the number of Levenberg-Marquardt iterations from 50
to 500. This way, the solver is able to crawl out of the bad
local minima it gets stuck in when changing from, for example,
bundling k1 and k2 to just k1 and resetting k2 to 0.
- Add several new region tracker implementations. A region tracker
is a libmv concept, which refers to tracking a template image
pattern through frames. The impact to end users is that tracking
should "just work better". I am reserving a more detailed
writeup, and maybe a paper, for later.
- Other libmv tweaks, such as detecting that a tracker is headed
outside of the image bounds.
This includes several changes made directly to the libmv extern
code rather expecting to get those changes through normal libmv
channels, because I, the libmv BDFL, decided it was faster to work
on libmv directly in Blender, then later reverse-port the libmv
changes from Blender back into libmv trunk. The interesting part
is that I added a full Levenberg-Marquardt loop to the region
tracking code, which should lead to a more stable solutions. I
also added a hacky implementation of "Efficient Second-Order
Minimization" for tracking, which works nicely. A more detailed
quantitative evaluation will follow.
Original patch by Keir, cleaned a bit by myself.
2011-11-14 06:41:23 +00:00
|
|
|
|
2012-06-15 11:03:23 +00:00
|
|
|
/* make currently tracked segment be finished with disabled marker */
|
|
|
|
|
tracking_marker_insert_disabled(track, &new_marker, context->backwards, FALSE);
|
Assorted camera tracker improvements
- Add support for refining the camera's intrinsic parameters
during a solve. Currently, refining supports only the following
combinations of intrinsic parameters:
f
f, cx, cy
f, cx, cy, k1, k2
f, k1
f, k1, k2
This is not the same as autocalibration, since the user must
still make a reasonable initial guess about the focal length and
other parameters, whereas true autocalibration would eliminate
the need for the user specify intrinsic parameters at all.
However, the solver works well with only rough guesses for the
focal length, so perhaps full autocalibation is not that
important.
Adding support for the last two combinations, (f, k1) and (f,
k1, k2) required changes to the library libmv depends on for
bundle adjustment, SSBA. These changes should get ported
upstream not just to libmv but to SSBA as well.
- Improved the region of convergence for bundle adjustment by
increasing the number of Levenberg-Marquardt iterations from 50
to 500. This way, the solver is able to crawl out of the bad
local minima it gets stuck in when changing from, for example,
bundling k1 and k2 to just k1 and resetting k2 to 0.
- Add several new region tracker implementations. A region tracker
is a libmv concept, which refers to tracking a template image
pattern through frames. The impact to end users is that tracking
should "just work better". I am reserving a more detailed
writeup, and maybe a paper, for later.
- Other libmv tweaks, such as detecting that a tracker is headed
outside of the image bounds.
This includes several changes made directly to the libmv extern
code rather expecting to get those changes through normal libmv
channels, because I, the libmv BDFL, decided it was faster to work
on libmv directly in Blender, then later reverse-port the libmv
changes from Blender back into libmv trunk. The interesting part
is that I added a full Levenberg-Marquardt loop to the region
tracking code, which should lead to a more stable solutions. I
also added a hacky implementation of "Efficient Second-Order
Minimization" for tracking, which works nicely. A more detailed
quantitative evaluation will follow.
Original patch by Keir, cleaned a bit by myself.
2011-11-14 06:41:23 +00:00
|
|
|
}
|
2012-06-15 11:03:23 +00:00
|
|
|
else {
|
|
|
|
|
new_marker.framenr = nextfra;
|
|
|
|
|
new_marker.flag |= MARKER_DISABLED;
|
Assorted camera tracker improvements
- Add support for refining the camera's intrinsic parameters
during a solve. Currently, refining supports only the following
combinations of intrinsic parameters:
f
f, cx, cy
f, cx, cy, k1, k2
f, k1
f, k1, k2
This is not the same as autocalibration, since the user must
still make a reasonable initial guess about the focal length and
other parameters, whereas true autocalibration would eliminate
the need for the user specify intrinsic parameters at all.
However, the solver works well with only rough guesses for the
focal length, so perhaps full autocalibation is not that
important.
Adding support for the last two combinations, (f, k1) and (f,
k1, k2) required changes to the library libmv depends on for
bundle adjustment, SSBA. These changes should get ported
upstream not just to libmv but to SSBA as well.
- Improved the region of convergence for bundle adjustment by
increasing the number of Levenberg-Marquardt iterations from 50
to 500. This way, the solver is able to crawl out of the bad
local minima it gets stuck in when changing from, for example,
bundling k1 and k2 to just k1 and resetting k2 to 0.
- Add several new region tracker implementations. A region tracker
is a libmv concept, which refers to tracking a template image
pattern through frames. The impact to end users is that tracking
should "just work better". I am reserving a more detailed
writeup, and maybe a paper, for later.
- Other libmv tweaks, such as detecting that a tracker is headed
outside of the image bounds.
This includes several changes made directly to the libmv extern
code rather expecting to get those changes through normal libmv
channels, because I, the libmv BDFL, decided it was faster to work
on libmv directly in Blender, then later reverse-port the libmv
changes from Blender back into libmv trunk. The interesting part
is that I added a full Levenberg-Marquardt loop to the region
tracking code, which should lead to a more stable solutions. I
also added a hacky implementation of "Efficient Second-Order
Minimization" for tracking, which works nicely. A more detailed
quantitative evaluation will follow.
Original patch by Keir, cleaned a bit by myself.
2011-11-14 06:41:23 +00:00
|
|
|
|
2012-06-15 11:03:23 +00:00
|
|
|
BKE_tracking_marker_insert(track, &new_marker);
|
|
|
|
|
}
|
Assorted camera tracker improvements
- Add support for refining the camera's intrinsic parameters
during a solve. Currently, refining supports only the following
combinations of intrinsic parameters:
f
f, cx, cy
f, cx, cy, k1, k2
f, k1
f, k1, k2
This is not the same as autocalibration, since the user must
still make a reasonable initial guess about the focal length and
other parameters, whereas true autocalibration would eliminate
the need for the user specify intrinsic parameters at all.
However, the solver works well with only rough guesses for the
focal length, so perhaps full autocalibation is not that
important.
Adding support for the last two combinations, (f, k1) and (f,
k1, k2) required changes to the library libmv depends on for
bundle adjustment, SSBA. These changes should get ported
upstream not just to libmv but to SSBA as well.
- Improved the region of convergence for bundle adjustment by
increasing the number of Levenberg-Marquardt iterations from 50
to 500. This way, the solver is able to crawl out of the bad
local minima it gets stuck in when changing from, for example,
bundling k1 and k2 to just k1 and resetting k2 to 0.
- Add several new region tracker implementations. A region tracker
is a libmv concept, which refers to tracking a template image
pattern through frames. The impact to end users is that tracking
should "just work better". I am reserving a more detailed
writeup, and maybe a paper, for later.
- Other libmv tweaks, such as detecting that a tracker is headed
outside of the image bounds.
This includes several changes made directly to the libmv extern
code rather expecting to get those changes through normal libmv
channels, because I, the libmv BDFL, decided it was faster to work
on libmv directly in Blender, then later reverse-port the libmv
changes from Blender back into libmv trunk. The interesting part
is that I added a full Levenberg-Marquardt loop to the region
tracking code, which should lead to a more stable solutions. I
also added a hacky implementation of "Efficient Second-Order
Minimization" for tracking, which works nicely. A more detailed
quantitative evaluation will follow.
Original patch by Keir, cleaned a bit by myself.
2011-11-14 06:41:23 +00:00
|
|
|
}
|
2012-06-15 11:03:23 +00:00
|
|
|
|
2011-11-07 12:55:18 +00:00
|
|
|
#endif
|
|
|
|
|
|
2012-06-15 11:03:23 +00:00
|
|
|
int BKE_tracking_context_step(MovieTrackingContext *context)
|
Assorted camera tracker improvements
- Add support for refining the camera's intrinsic parameters
during a solve. Currently, refining supports only the following
combinations of intrinsic parameters:
f
f, cx, cy
f, cx, cy, k1, k2
f, k1
f, k1, k2
This is not the same as autocalibration, since the user must
still make a reasonable initial guess about the focal length and
other parameters, whereas true autocalibration would eliminate
the need for the user specify intrinsic parameters at all.
However, the solver works well with only rough guesses for the
focal length, so perhaps full autocalibation is not that
important.
Adding support for the last two combinations, (f, k1) and (f,
k1, k2) required changes to the library libmv depends on for
bundle adjustment, SSBA. These changes should get ported
upstream not just to libmv but to SSBA as well.
- Improved the region of convergence for bundle adjustment by
increasing the number of Levenberg-Marquardt iterations from 50
to 500. This way, the solver is able to crawl out of the bad
local minima it gets stuck in when changing from, for example,
bundling k1 and k2 to just k1 and resetting k2 to 0.
- Add several new region tracker implementations. A region tracker
is a libmv concept, which refers to tracking a template image
pattern through frames. The impact to end users is that tracking
should "just work better". I am reserving a more detailed
writeup, and maybe a paper, for later.
- Other libmv tweaks, such as detecting that a tracker is headed
outside of the image bounds.
This includes several changes made directly to the libmv extern
code rather expecting to get those changes through normal libmv
channels, because I, the libmv BDFL, decided it was faster to work
on libmv directly in Blender, then later reverse-port the libmv
changes from Blender back into libmv trunk. The interesting part
is that I added a full Levenberg-Marquardt loop to the region
tracking code, which should lead to a more stable solutions. I
also added a hacky implementation of "Efficient Second-Order
Minimization" for tracking, which works nicely. A more detailed
quantitative evaluation will follow.
Original patch by Keir, cleaned a bit by myself.
2011-11-14 06:41:23 +00:00
|
|
|
{
|
2012-06-15 11:03:23 +00:00
|
|
|
ImBuf *destination_ibuf;
|
|
|
|
|
int frame_delta = context->backwards ? -1 : 1;
|
|
|
|
|
int curfra = BKE_movieclip_remap_scene_to_clip_frame(context->clip, context->user.framenr);
|
2012-06-22 07:49:44 +00:00
|
|
|
/* int nextfra; */ /* UNUSED */
|
2012-06-15 11:03:23 +00:00
|
|
|
int a, ok = FALSE, map_size;
|
2011-12-05 18:57:17 +00:00
|
|
|
|
2012-06-15 11:03:23 +00:00
|
|
|
int frame_width, frame_height;
|
2012-03-25 23:19:21 +00:00
|
|
|
|
2012-06-15 11:03:23 +00:00
|
|
|
map_size = tracks_map_get_size(context->tracks_map);
|
Assorted camera tracker improvements
- Add support for refining the camera's intrinsic parameters
during a solve. Currently, refining supports only the following
combinations of intrinsic parameters:
f
f, cx, cy
f, cx, cy, k1, k2
f, k1
f, k1, k2
This is not the same as autocalibration, since the user must
still make a reasonable initial guess about the focal length and
other parameters, whereas true autocalibration would eliminate
the need for the user specify intrinsic parameters at all.
However, the solver works well with only rough guesses for the
focal length, so perhaps full autocalibation is not that
important.
Adding support for the last two combinations, (f, k1) and (f,
k1, k2) required changes to the library libmv depends on for
bundle adjustment, SSBA. These changes should get ported
upstream not just to libmv but to SSBA as well.
- Improved the region of convergence for bundle adjustment by
increasing the number of Levenberg-Marquardt iterations from 50
to 500. This way, the solver is able to crawl out of the bad
local minima it gets stuck in when changing from, for example,
bundling k1 and k2 to just k1 and resetting k2 to 0.
- Add several new region tracker implementations. A region tracker
is a libmv concept, which refers to tracking a template image
pattern through frames. The impact to end users is that tracking
should "just work better". I am reserving a more detailed
writeup, and maybe a paper, for later.
- Other libmv tweaks, such as detecting that a tracker is headed
outside of the image bounds.
This includes several changes made directly to the libmv extern
code rather expecting to get those changes through normal libmv
channels, because I, the libmv BDFL, decided it was faster to work
on libmv directly in Blender, then later reverse-port the libmv
changes from Blender back into libmv trunk. The interesting part
is that I added a full Levenberg-Marquardt loop to the region
tracking code, which should lead to a more stable solutions. I
also added a hacky implementation of "Efficient Second-Order
Minimization" for tracking, which works nicely. A more detailed
quantitative evaluation will follow.
Original patch by Keir, cleaned a bit by myself.
2011-11-14 06:41:23 +00:00
|
|
|
|
2012-06-15 11:03:23 +00:00
|
|
|
/* nothing to track, avoid unneeded frames reading to save time and memory */
|
|
|
|
|
if (!map_size)
|
|
|
|
|
return FALSE;
|
2012-03-25 23:19:21 +00:00
|
|
|
|
2012-06-15 11:03:23 +00:00
|
|
|
context->user.framenr += frame_delta;
|
Assorted camera tracker improvements
- Add support for refining the camera's intrinsic parameters
during a solve. Currently, refining supports only the following
combinations of intrinsic parameters:
f
f, cx, cy
f, cx, cy, k1, k2
f, k1
f, k1, k2
This is not the same as autocalibration, since the user must
still make a reasonable initial guess about the focal length and
other parameters, whereas true autocalibration would eliminate
the need for the user specify intrinsic parameters at all.
However, the solver works well with only rough guesses for the
focal length, so perhaps full autocalibation is not that
important.
Adding support for the last two combinations, (f, k1) and (f,
k1, k2) required changes to the library libmv depends on for
bundle adjustment, SSBA. These changes should get ported
upstream not just to libmv but to SSBA as well.
- Improved the region of convergence for bundle adjustment by
increasing the number of Levenberg-Marquardt iterations from 50
to 500. This way, the solver is able to crawl out of the bad
local minima it gets stuck in when changing from, for example,
bundling k1 and k2 to just k1 and resetting k2 to 0.
- Add several new region tracker implementations. A region tracker
is a libmv concept, which refers to tracking a template image
pattern through frames. The impact to end users is that tracking
should "just work better". I am reserving a more detailed
writeup, and maybe a paper, for later.
- Other libmv tweaks, such as detecting that a tracker is headed
outside of the image bounds.
This includes several changes made directly to the libmv extern
code rather expecting to get those changes through normal libmv
channels, because I, the libmv BDFL, decided it was faster to work
on libmv directly in Blender, then later reverse-port the libmv
changes from Blender back into libmv trunk. The interesting part
is that I added a full Levenberg-Marquardt loop to the region
tracking code, which should lead to a more stable solutions. I
also added a hacky implementation of "Efficient Second-Order
Minimization" for tracking, which works nicely. A more detailed
quantitative evaluation will follow.
Original patch by Keir, cleaned a bit by myself.
2011-11-14 06:41:23 +00:00
|
|
|
|
2012-06-15 11:03:23 +00:00
|
|
|
destination_ibuf = BKE_movieclip_get_ibuf_flag(context->clip, &context->user,
|
|
|
|
|
context->clip_flag, MOVIECLIP_CACHE_SKIP);
|
|
|
|
|
if (!destination_ibuf)
|
|
|
|
|
return FALSE;
|
Assorted camera tracker improvements
- Add support for refining the camera's intrinsic parameters
during a solve. Currently, refining supports only the following
combinations of intrinsic parameters:
f
f, cx, cy
f, cx, cy, k1, k2
f, k1
f, k1, k2
This is not the same as autocalibration, since the user must
still make a reasonable initial guess about the focal length and
other parameters, whereas true autocalibration would eliminate
the need for the user specify intrinsic parameters at all.
However, the solver works well with only rough guesses for the
focal length, so perhaps full autocalibation is not that
important.
Adding support for the last two combinations, (f, k1) and (f,
k1, k2) required changes to the library libmv depends on for
bundle adjustment, SSBA. These changes should get ported
upstream not just to libmv but to SSBA as well.
- Improved the region of convergence for bundle adjustment by
increasing the number of Levenberg-Marquardt iterations from 50
to 500. This way, the solver is able to crawl out of the bad
local minima it gets stuck in when changing from, for example,
bundling k1 and k2 to just k1 and resetting k2 to 0.
- Add several new region tracker implementations. A region tracker
is a libmv concept, which refers to tracking a template image
pattern through frames. The impact to end users is that tracking
should "just work better". I am reserving a more detailed
writeup, and maybe a paper, for later.
- Other libmv tweaks, such as detecting that a tracker is headed
outside of the image bounds.
This includes several changes made directly to the libmv extern
code rather expecting to get those changes through normal libmv
channels, because I, the libmv BDFL, decided it was faster to work
on libmv directly in Blender, then later reverse-port the libmv
changes from Blender back into libmv trunk. The interesting part
is that I added a full Levenberg-Marquardt loop to the region
tracking code, which should lead to a more stable solutions. I
also added a hacky implementation of "Efficient Second-Order
Minimization" for tracking, which works nicely. A more detailed
quantitative evaluation will follow.
Original patch by Keir, cleaned a bit by myself.
2011-11-14 06:41:23 +00:00
|
|
|
|
2012-06-22 07:49:44 +00:00
|
|
|
/* nextfra = curfra + frame_delta; */ /* UNUSED */
|
2011-11-28 13:49:42 +00:00
|
|
|
|
2012-06-15 11:03:23 +00:00
|
|
|
frame_width = destination_ibuf->x;
|
|
|
|
|
frame_height = destination_ibuf->y;
|
2011-12-05 18:57:17 +00:00
|
|
|
|
2012-08-11 22:12:32 +00:00
|
|
|
#pragma omp parallel for private(a) shared(destination_ibuf, ok) if (map_size > 1)
|
2012-06-15 11:03:23 +00:00
|
|
|
for (a = 0; a < map_size; a++) {
|
|
|
|
|
TrackContext *track_context = NULL;
|
|
|
|
|
MovieTrackingTrack *track;
|
|
|
|
|
MovieTrackingMarker *marker;
|
2011-12-05 18:57:17 +00:00
|
|
|
|
2012-06-15 11:03:23 +00:00
|
|
|
tracks_map_get_indexed_element(context->tracks_map, a, &track, (void **)&track_context);
|
2011-11-28 13:49:42 +00:00
|
|
|
|
2012-06-15 11:03:23 +00:00
|
|
|
marker = BKE_tracking_marker_get_exact(track, curfra);
|
2011-11-28 13:49:42 +00:00
|
|
|
|
2012-06-15 11:03:23 +00:00
|
|
|
if (marker && (marker->flag & MARKER_DISABLED) == 0) {
|
|
|
|
|
#ifdef WITH_LIBMV
|
|
|
|
|
int width, height, tracked = FALSE, need_readjust;
|
|
|
|
|
double dst_pixel_x[5], dst_pixel_y[5];
|
2011-11-28 13:49:42 +00:00
|
|
|
|
2012-06-15 11:03:23 +00:00
|
|
|
if (track->pattern_match == TRACK_MATCH_KEYFRAME)
|
|
|
|
|
need_readjust = context->first_time;
|
|
|
|
|
else
|
|
|
|
|
need_readjust = TRUE;
|
2011-11-28 13:49:42 +00:00
|
|
|
|
2012-06-15 11:03:23 +00:00
|
|
|
/* do not track markers which are too close to boundary */
|
|
|
|
|
if (tracking_check_marker_margin(track, marker, frame_width, frame_height)) {
|
|
|
|
|
/* to convert to the x/y split array format for libmv. */
|
|
|
|
|
double src_pixel_x[5], src_pixel_y[5];
|
2011-11-28 13:49:42 +00:00
|
|
|
|
2012-06-15 11:03:23 +00:00
|
|
|
/* settings for the tracker */
|
|
|
|
|
struct libmv_trackRegionOptions options = {0};
|
|
|
|
|
struct libmv_trackRegionResult result;
|
2011-11-28 13:49:42 +00:00
|
|
|
|
2012-06-15 11:03:23 +00:00
|
|
|
float *patch_new;
|
2011-11-28 13:49:42 +00:00
|
|
|
|
2012-06-15 11:03:23 +00:00
|
|
|
if (need_readjust) {
|
2012-09-19 12:43:32 +00:00
|
|
|
if (track_context_update_reference(context, track_context, track, marker,
|
|
|
|
|
curfra, frame_width, frame_height) == FALSE)
|
|
|
|
|
{
|
|
|
|
|
/* happens when reference frame fails to be loaded */
|
|
|
|
|
continue;
|
|
|
|
|
}
|
2012-06-15 11:03:23 +00:00
|
|
|
}
|
2011-11-07 12:55:18 +00:00
|
|
|
|
2012-06-15 11:03:23 +00:00
|
|
|
/* for now track to the same search area dimension as marker has got for current frame
|
|
|
|
|
* will make all tracked markers in currently tracked segment have the same search area
|
|
|
|
|
* size, but it's quite close to what is actually needed
|
|
|
|
|
*/
|
|
|
|
|
patch_new = track_get_search_floatbuf(destination_ibuf, track, marker, &width, &height);
|
2011-11-28 13:49:42 +00:00
|
|
|
|
2012-06-15 11:03:23 +00:00
|
|
|
/* configure the tracker */
|
|
|
|
|
tracking_configure_tracker(track_context, track, &options);
|
2011-11-28 13:49:42 +00:00
|
|
|
|
2012-06-15 11:03:23 +00:00
|
|
|
/* convert the marker corners and center into pixel coordinates in the search/destination images. */
|
|
|
|
|
get_marker_coords_for_tracking(frame_width, frame_height, &track_context->marker, src_pixel_x, src_pixel_y);
|
|
|
|
|
get_marker_coords_for_tracking(frame_width, frame_height, marker, dst_pixel_x, dst_pixel_y);
|
2011-11-28 13:49:42 +00:00
|
|
|
|
2012-11-07 11:18:42 +00:00
|
|
|
if (!patch_new || !track_context->search_area)
|
|
|
|
|
continue;
|
|
|
|
|
|
2012-06-15 11:03:23 +00:00
|
|
|
/* run the tracker! */
|
|
|
|
|
tracked = libmv_trackRegion(&options,
|
|
|
|
|
track_context->search_area,
|
2012-06-16 09:18:00 +00:00
|
|
|
track_context->search_area_width,
|
|
|
|
|
track_context->search_area_height,
|
|
|
|
|
patch_new, width, height,
|
2012-06-15 11:03:23 +00:00
|
|
|
src_pixel_x, src_pixel_y,
|
|
|
|
|
&result,
|
|
|
|
|
dst_pixel_x, dst_pixel_y);
|
|
|
|
|
MEM_freeN(patch_new);
|
|
|
|
|
}
|
2011-11-28 13:49:42 +00:00
|
|
|
|
2012-06-15 11:03:23 +00:00
|
|
|
#pragma omp critical
|
|
|
|
|
{
|
|
|
|
|
tracking_insert_new_marker(context, track, marker, curfra, tracked,
|
2012-06-16 09:18:00 +00:00
|
|
|
frame_width, frame_height, dst_pixel_x, dst_pixel_y);
|
2012-06-15 11:03:23 +00:00
|
|
|
}
|
2011-11-28 13:49:42 +00:00
|
|
|
|
2012-06-15 11:03:23 +00:00
|
|
|
ok = TRUE;
|
|
|
|
|
#else
|
|
|
|
|
(void)frame_height;
|
|
|
|
|
(void)frame_width;
|
2011-11-28 13:49:42 +00:00
|
|
|
#endif
|
2012-06-15 11:03:23 +00:00
|
|
|
}
|
|
|
|
|
}
|
2011-11-07 12:55:18 +00:00
|
|
|
|
2012-06-15 11:03:23 +00:00
|
|
|
IMB_freeImBuf(destination_ibuf);
|
2011-11-07 12:55:18 +00:00
|
|
|
|
2012-06-15 11:03:23 +00:00
|
|
|
context->first_time = FALSE;
|
|
|
|
|
context->frames++;
|
|
|
|
|
|
|
|
|
|
return ok;
|
2011-11-28 13:49:42 +00:00
|
|
|
}
|
2011-11-07 12:55:18 +00:00
|
|
|
|
2012-06-15 11:03:23 +00:00
|
|
|
/*********************** Camera solving *************************/
|
2011-11-07 12:55:18 +00:00
|
|
|
|
2012-06-15 11:03:23 +00:00
|
|
|
typedef struct MovieReconstructContext {
|
|
|
|
|
#ifdef WITH_LIBMV
|
|
|
|
|
struct libmv_Tracks *tracks;
|
|
|
|
|
int keyframe1, keyframe2;
|
|
|
|
|
short refine_flags;
|
2011-11-28 13:49:42 +00:00
|
|
|
|
2012-06-15 11:03:23 +00:00
|
|
|
struct libmv_Reconstruction *reconstruction;
|
2011-12-03 20:26:53 +00:00
|
|
|
#endif
|
2012-06-15 11:03:23 +00:00
|
|
|
char object_name[MAX_NAME];
|
|
|
|
|
int is_camera;
|
|
|
|
|
short motion_flag;
|
2011-11-28 13:49:42 +00:00
|
|
|
|
2012-06-15 11:03:23 +00:00
|
|
|
float focal_length;
|
|
|
|
|
float principal_point[2];
|
|
|
|
|
float k1, k2, k3;
|
2011-11-28 13:49:42 +00:00
|
|
|
|
2013-02-25 09:46:47 +00:00
|
|
|
int width, height;
|
|
|
|
|
|
2012-06-15 11:03:23 +00:00
|
|
|
float reprojection_error;
|
2011-11-28 13:49:42 +00:00
|
|
|
|
2012-06-15 11:03:23 +00:00
|
|
|
TracksMap *tracks_map;
|
|
|
|
|
|
2012-11-05 08:04:27 +00:00
|
|
|
float success_threshold;
|
|
|
|
|
int use_fallback_reconstruction;
|
|
|
|
|
|
2012-06-15 11:03:23 +00:00
|
|
|
int sfra, efra;
|
|
|
|
|
} MovieReconstructContext;
|
|
|
|
|
|
|
|
|
|
typedef struct ReconstructProgressData {
|
|
|
|
|
short *stop;
|
|
|
|
|
short *do_update;
|
|
|
|
|
float *progress;
|
|
|
|
|
char *stats_message;
|
|
|
|
|
int message_size;
|
|
|
|
|
} ReconstructProgressData;
|
2011-11-28 13:49:42 +00:00
|
|
|
|
|
|
|
|
#ifdef WITH_LIBMV
|
2012-06-15 11:03:23 +00:00
|
|
|
static struct libmv_Tracks *libmv_tracks_new(ListBase *tracksbase, int width, int height)
|
|
|
|
|
{
|
|
|
|
|
int tracknr = 0;
|
|
|
|
|
MovieTrackingTrack *track;
|
|
|
|
|
struct libmv_Tracks *tracks = libmv_tracksNew();
|
2011-11-28 13:49:42 +00:00
|
|
|
|
2012-06-15 11:03:23 +00:00
|
|
|
track = tracksbase->first;
|
|
|
|
|
while (track) {
|
|
|
|
|
int a = 0;
|
2011-11-28 13:49:42 +00:00
|
|
|
|
2012-06-15 11:03:23 +00:00
|
|
|
for (a = 0; a < track->markersnr; a++) {
|
|
|
|
|
MovieTrackingMarker *marker = &track->markers[a];
|
2011-11-28 13:49:42 +00:00
|
|
|
|
2012-06-15 11:03:23 +00:00
|
|
|
if ((marker->flag & MARKER_DISABLED) == 0) {
|
|
|
|
|
libmv_tracksInsert(tracks, marker->framenr, tracknr,
|
2012-06-25 16:36:12 +00:00
|
|
|
(marker->pos[0] + track->offset[0]) * width,
|
|
|
|
|
(marker->pos[1] + track->offset[1]) * height);
|
2012-06-15 11:03:23 +00:00
|
|
|
}
|
|
|
|
|
}
|
2011-11-28 13:49:42 +00:00
|
|
|
|
2012-06-15 11:03:23 +00:00
|
|
|
track = track->next;
|
|
|
|
|
tracknr++;
|
|
|
|
|
}
|
2011-11-28 13:49:42 +00:00
|
|
|
|
2012-06-15 11:03:23 +00:00
|
|
|
return tracks;
|
2011-11-28 13:49:42 +00:00
|
|
|
}
|
|
|
|
|
|
2012-06-15 11:03:23 +00:00
|
|
|
static void reconstruct_retrieve_libmv_intrinscis(MovieReconstructContext *context, MovieTracking *tracking)
|
2011-11-28 13:49:42 +00:00
|
|
|
{
|
2012-06-15 11:03:23 +00:00
|
|
|
struct libmv_Reconstruction *libmv_reconstruction = context->reconstruction;
|
|
|
|
|
struct libmv_CameraIntrinsics *libmv_intrinsics = libmv_ReconstructionExtractIntrinsics(libmv_reconstruction);
|
2011-12-05 18:57:17 +00:00
|
|
|
|
2012-06-15 11:03:23 +00:00
|
|
|
float aspy = 1.0f / tracking->camera.pixel_aspect;
|
|
|
|
|
|
|
|
|
|
double focal_length, principal_x, principal_y, k1, k2, k3;
|
|
|
|
|
int width, height;
|
|
|
|
|
|
|
|
|
|
libmv_CameraIntrinsicsExtract(libmv_intrinsics, &focal_length, &principal_x, &principal_y,
|
|
|
|
|
&k1, &k2, &k3, &width, &height);
|
|
|
|
|
|
|
|
|
|
tracking->camera.focal = focal_length;
|
|
|
|
|
|
2013-02-25 09:46:47 +00:00
|
|
|
tracking->camera.principal[0] = principal_x;
|
2012-06-15 11:03:23 +00:00
|
|
|
tracking->camera.principal[1] = principal_y / aspy;
|
2013-02-25 09:46:47 +00:00
|
|
|
|
2012-06-15 11:03:23 +00:00
|
|
|
tracking->camera.k1 = k1;
|
|
|
|
|
tracking->camera.k2 = k2;
|
2013-02-25 09:46:47 +00:00
|
|
|
tracking->camera.k3 = k3;
|
2012-06-15 11:03:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static int reconstruct_retrieve_libmv_tracks(MovieReconstructContext *context, MovieTracking *tracking)
|
|
|
|
|
{
|
|
|
|
|
struct libmv_Reconstruction *libmv_reconstruction = context->reconstruction;
|
|
|
|
|
MovieTrackingReconstruction *reconstruction = NULL;
|
|
|
|
|
MovieReconstructedCamera *reconstructed;
|
|
|
|
|
MovieTrackingTrack *track;
|
|
|
|
|
ListBase *tracksbase = NULL;
|
|
|
|
|
int ok = TRUE, tracknr = 0, a, origin_set = FALSE;
|
|
|
|
|
int sfra = context->sfra, efra = context->efra;
|
|
|
|
|
float imat[4][4];
|
2011-12-05 18:57:17 +00:00
|
|
|
|
2012-03-24 06:18:31 +00:00
|
|
|
if (context->is_camera) {
|
2012-06-15 11:03:23 +00:00
|
|
|
tracksbase = &tracking->tracks;
|
2012-03-25 23:19:21 +00:00
|
|
|
reconstruction = &tracking->reconstruction;
|
2011-12-05 18:57:17 +00:00
|
|
|
}
|
|
|
|
|
else {
|
2012-06-15 11:03:23 +00:00
|
|
|
MovieTrackingObject *object = BKE_tracking_object_get_named(tracking, context->object_name);
|
2011-12-05 18:57:17 +00:00
|
|
|
|
2012-06-15 11:03:23 +00:00
|
|
|
tracksbase = &object->tracks;
|
2012-03-25 23:19:21 +00:00
|
|
|
reconstruction = &object->reconstruction;
|
2011-12-05 18:57:17 +00:00
|
|
|
}
|
|
|
|
|
|
2012-06-15 11:03:23 +00:00
|
|
|
unit_m4(imat);
|
2011-11-28 13:49:42 +00:00
|
|
|
|
2012-06-15 11:03:23 +00:00
|
|
|
track = tracksbase->first;
|
|
|
|
|
while (track) {
|
|
|
|
|
double pos[3];
|
2011-11-07 12:55:18 +00:00
|
|
|
|
2012-06-15 11:03:23 +00:00
|
|
|
if (libmv_reporojectionPointForTrack(libmv_reconstruction, tracknr, pos)) {
|
|
|
|
|
track->bundle_pos[0] = pos[0];
|
|
|
|
|
track->bundle_pos[1] = pos[1];
|
|
|
|
|
track->bundle_pos[2] = pos[2];
|
2011-11-07 12:55:18 +00:00
|
|
|
|
2012-06-15 11:03:23 +00:00
|
|
|
track->flag |= TRACK_HAS_BUNDLE;
|
|
|
|
|
track->error = libmv_reporojectionErrorForTrack(libmv_reconstruction, tracknr);
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
track->flag &= ~TRACK_HAS_BUNDLE;
|
|
|
|
|
ok = FALSE;
|
2011-11-07 12:55:18 +00:00
|
|
|
|
2012-06-15 11:03:23 +00:00
|
|
|
printf("No bundle for track #%d '%s'\n", tracknr, track->name);
|
|
|
|
|
}
|
2011-11-07 12:55:18 +00:00
|
|
|
|
2012-03-25 23:19:21 +00:00
|
|
|
track = track->next;
|
2012-06-15 11:03:23 +00:00
|
|
|
tracknr++;
|
2011-11-07 12:55:18 +00:00
|
|
|
}
|
|
|
|
|
|
2012-06-15 11:03:23 +00:00
|
|
|
if (reconstruction->cameras)
|
|
|
|
|
MEM_freeN(reconstruction->cameras);
|
2011-11-07 12:55:18 +00:00
|
|
|
|
2012-06-15 11:03:23 +00:00
|
|
|
reconstruction->camnr = 0;
|
|
|
|
|
reconstruction->cameras = NULL;
|
|
|
|
|
reconstructed = MEM_callocN((efra - sfra + 1) * sizeof(MovieReconstructedCamera),
|
|
|
|
|
"temp reconstructed camera");
|
2011-11-07 12:55:18 +00:00
|
|
|
|
2012-06-15 11:03:23 +00:00
|
|
|
for (a = sfra; a <= efra; a++) {
|
|
|
|
|
double matd[4][4];
|
2011-11-07 12:55:18 +00:00
|
|
|
|
2012-06-15 11:03:23 +00:00
|
|
|
if (libmv_reporojectionCameraForImage(libmv_reconstruction, a, matd)) {
|
|
|
|
|
int i, j;
|
|
|
|
|
float mat[4][4];
|
|
|
|
|
float error = libmv_reporojectionErrorForImage(libmv_reconstruction, a);
|
2011-11-07 12:55:18 +00:00
|
|
|
|
2012-06-15 11:03:23 +00:00
|
|
|
for (i = 0; i < 4; i++)
|
|
|
|
|
for (j = 0; j < 4; j++)
|
|
|
|
|
mat[i][j] = matd[i][j];
|
2011-11-07 12:55:18 +00:00
|
|
|
|
2012-06-15 11:03:23 +00:00
|
|
|
if (!origin_set) {
|
|
|
|
|
copy_m4_m4(imat, mat);
|
|
|
|
|
invert_m4(imat);
|
|
|
|
|
origin_set = TRUE;
|
|
|
|
|
}
|
2011-11-07 12:55:18 +00:00
|
|
|
|
2012-06-15 11:03:23 +00:00
|
|
|
if (origin_set)
|
|
|
|
|
mult_m4_m4m4(mat, imat, mat);
|
2011-11-07 12:55:18 +00:00
|
|
|
|
2012-06-15 11:03:23 +00:00
|
|
|
copy_m4_m4(reconstructed[reconstruction->camnr].mat, mat);
|
|
|
|
|
reconstructed[reconstruction->camnr].framenr = a;
|
|
|
|
|
reconstructed[reconstruction->camnr].error = error;
|
|
|
|
|
reconstruction->camnr++;
|
2011-11-07 12:55:18 +00:00
|
|
|
}
|
2012-06-15 11:03:23 +00:00
|
|
|
else {
|
|
|
|
|
ok = FALSE;
|
|
|
|
|
printf("No camera for frame %d\n", a);
|
2011-11-07 12:55:18 +00:00
|
|
|
}
|
2012-06-15 11:03:23 +00:00
|
|
|
}
|
2011-11-07 12:55:18 +00:00
|
|
|
|
2012-06-15 11:03:23 +00:00
|
|
|
if (reconstruction->camnr) {
|
|
|
|
|
int size = reconstruction->camnr * sizeof(MovieReconstructedCamera);
|
|
|
|
|
reconstruction->cameras = MEM_callocN(size, "reconstructed camera");
|
|
|
|
|
memcpy(reconstruction->cameras, reconstructed, size);
|
|
|
|
|
}
|
2011-11-07 12:55:18 +00:00
|
|
|
|
2012-06-15 11:03:23 +00:00
|
|
|
if (origin_set) {
|
|
|
|
|
track = tracksbase->first;
|
|
|
|
|
while (track) {
|
|
|
|
|
if (track->flag & TRACK_HAS_BUNDLE)
|
|
|
|
|
mul_v3_m4v3(track->bundle_pos, imat, track->bundle_pos);
|
2011-11-07 12:55:18 +00:00
|
|
|
|
2012-06-15 11:03:23 +00:00
|
|
|
track = track->next;
|
|
|
|
|
}
|
2011-11-07 12:55:18 +00:00
|
|
|
}
|
|
|
|
|
|
2012-06-15 11:03:23 +00:00
|
|
|
MEM_freeN(reconstructed);
|
2011-12-19 15:12:33 +00:00
|
|
|
|
2012-06-15 11:03:23 +00:00
|
|
|
return ok;
|
2011-12-19 15:12:33 +00:00
|
|
|
}
|
|
|
|
|
|
2012-06-15 11:03:23 +00:00
|
|
|
static int reconstruct_retrieve_libmv(MovieReconstructContext *context, MovieTracking *tracking)
|
2011-11-07 12:55:18 +00:00
|
|
|
{
|
2012-06-15 11:03:23 +00:00
|
|
|
/* take the intrinscis back from libmv */
|
|
|
|
|
reconstruct_retrieve_libmv_intrinscis(context, tracking);
|
2011-11-07 12:55:18 +00:00
|
|
|
|
2012-06-15 11:03:23 +00:00
|
|
|
return reconstruct_retrieve_libmv_tracks(context, tracking);
|
2011-11-07 12:55:18 +00:00
|
|
|
}
|
|
|
|
|
|
2012-06-15 11:03:23 +00:00
|
|
|
static int reconstruct_refine_intrinsics_get_flags(MovieTracking *tracking, MovieTrackingObject *object)
|
2011-11-07 12:55:18 +00:00
|
|
|
{
|
2012-06-15 11:03:23 +00:00
|
|
|
int refine = tracking->settings.refine_camera_intrinsics;
|
|
|
|
|
int flags = 0;
|
2011-12-05 18:57:17 +00:00
|
|
|
|
2012-06-15 11:03:23 +00:00
|
|
|
if ((object->flag & TRACKING_OBJECT_CAMERA) == 0)
|
|
|
|
|
return 0;
|
2011-11-07 12:55:18 +00:00
|
|
|
|
2012-06-15 11:03:23 +00:00
|
|
|
if (refine & REFINE_FOCAL_LENGTH)
|
|
|
|
|
flags |= LIBMV_REFINE_FOCAL_LENGTH;
|
2012-03-25 23:19:21 +00:00
|
|
|
|
2012-06-15 11:03:23 +00:00
|
|
|
if (refine & REFINE_PRINCIPAL_POINT)
|
|
|
|
|
flags |= LIBMV_REFINE_PRINCIPAL_POINT;
|
2011-11-07 12:55:18 +00:00
|
|
|
|
2012-06-15 11:03:23 +00:00
|
|
|
if (refine & REFINE_RADIAL_DISTORTION_K1)
|
2013-02-26 11:46:38 +00:00
|
|
|
flags |= LIBMV_REFINE_RADIAL_DISTORTION_K1;
|
2011-11-07 12:55:18 +00:00
|
|
|
|
2012-06-15 11:03:23 +00:00
|
|
|
if (refine & REFINE_RADIAL_DISTORTION_K2)
|
2013-02-26 11:46:38 +00:00
|
|
|
flags |= LIBMV_REFINE_RADIAL_DISTORTION_K2;
|
2011-12-19 15:12:33 +00:00
|
|
|
|
2012-06-15 11:03:23 +00:00
|
|
|
return flags;
|
2011-11-07 12:55:18 +00:00
|
|
|
}
|
|
|
|
|
|
2012-10-09 10:33:18 +00:00
|
|
|
static int reconstruct_count_tracks_on_both_keyframes(MovieTracking *tracking, MovieTrackingObject *object)
|
2011-11-07 12:55:18 +00:00
|
|
|
{
|
2012-10-09 10:33:18 +00:00
|
|
|
ListBase *tracksbase = BKE_tracking_object_get_tracks(tracking, object);
|
2012-06-15 11:03:23 +00:00
|
|
|
int tot = 0;
|
2012-10-09 10:33:18 +00:00
|
|
|
int frame1 = object->keyframe1, frame2 = object->keyframe2;
|
2012-06-15 11:03:23 +00:00
|
|
|
MovieTrackingTrack *track;
|
|
|
|
|
|
|
|
|
|
track = tracksbase->first;
|
|
|
|
|
while (track) {
|
|
|
|
|
if (BKE_tracking_track_has_enabled_marker_at_frame(track, frame1)) {
|
|
|
|
|
if (BKE_tracking_track_has_enabled_marker_at_frame(track, frame2)) {
|
|
|
|
|
tot++;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
track = track->next;
|
2011-11-07 12:55:18 +00:00
|
|
|
}
|
|
|
|
|
|
2012-06-15 11:03:23 +00:00
|
|
|
return tot;
|
2011-11-07 12:55:18 +00:00
|
|
|
}
|
2012-06-15 11:03:23 +00:00
|
|
|
#endif
|
2011-11-07 12:55:18 +00:00
|
|
|
|
2012-06-15 11:03:23 +00:00
|
|
|
int BKE_tracking_reconstruction_check(MovieTracking *tracking, MovieTrackingObject *object, char *error_msg, int error_size)
|
2011-11-07 12:55:18 +00:00
|
|
|
{
|
2012-09-16 00:26:36 +00:00
|
|
|
#ifdef WITH_LIBMV
|
2012-06-15 11:03:23 +00:00
|
|
|
if (tracking->settings.motion_flag & TRACKING_MOTION_MODAL) {
|
|
|
|
|
/* TODO: check for number of tracks? */
|
|
|
|
|
return TRUE;
|
|
|
|
|
}
|
2012-10-09 10:33:18 +00:00
|
|
|
else if (reconstruct_count_tracks_on_both_keyframes(tracking, object) < 8) {
|
2012-10-26 17:32:50 +00:00
|
|
|
BLI_strncpy(error_msg, N_("At least 8 common tracks on both of keyframes are needed for reconstruction"),
|
2012-06-15 11:03:23 +00:00
|
|
|
error_size);
|
2011-11-07 12:55:18 +00:00
|
|
|
|
2012-06-15 11:03:23 +00:00
|
|
|
return FALSE;
|
|
|
|
|
}
|
2011-11-07 12:55:18 +00:00
|
|
|
|
2012-06-15 11:03:23 +00:00
|
|
|
return TRUE;
|
|
|
|
|
#else
|
2012-10-26 17:32:50 +00:00
|
|
|
BLI_strncpy(error_msg, N_("Blender is compiled without motion tracking library"), error_size);
|
2011-11-07 12:55:18 +00:00
|
|
|
|
2012-06-15 11:03:23 +00:00
|
|
|
(void) tracking;
|
|
|
|
|
(void) object;
|
2011-11-07 12:55:18 +00:00
|
|
|
|
2012-06-15 11:03:23 +00:00
|
|
|
return 0;
|
|
|
|
|
#endif
|
2011-11-07 12:55:18 +00:00
|
|
|
}
|
|
|
|
|
|
2012-06-15 11:03:23 +00:00
|
|
|
MovieReconstructContext *BKE_tracking_reconstruction_context_new(MovieTracking *tracking, MovieTrackingObject *object,
|
|
|
|
|
int keyframe1, int keyframe2, int width, int height)
|
2011-11-07 12:55:18 +00:00
|
|
|
{
|
2012-06-15 11:03:23 +00:00
|
|
|
MovieReconstructContext *context = MEM_callocN(sizeof(MovieReconstructContext), "MovieReconstructContext data");
|
|
|
|
|
MovieTrackingCamera *camera = &tracking->camera;
|
|
|
|
|
ListBase *tracksbase = BKE_tracking_object_get_tracks(tracking, object);
|
|
|
|
|
float aspy = 1.0f / tracking->camera.pixel_aspect;
|
|
|
|
|
int num_tracks = BLI_countlist(tracksbase);
|
|
|
|
|
int sfra = INT_MAX, efra = INT_MIN;
|
|
|
|
|
MovieTrackingTrack *track;
|
2011-11-07 12:55:18 +00:00
|
|
|
|
2012-06-15 11:03:23 +00:00
|
|
|
BLI_strncpy(context->object_name, object->name, sizeof(context->object_name));
|
|
|
|
|
context->is_camera = object->flag & TRACKING_OBJECT_CAMERA;
|
|
|
|
|
context->motion_flag = tracking->settings.motion_flag;
|
2011-11-07 12:55:18 +00:00
|
|
|
|
2012-06-15 11:03:23 +00:00
|
|
|
context->focal_length = camera->focal;
|
|
|
|
|
context->principal_point[0] = camera->principal[0];
|
|
|
|
|
context->principal_point[1] = camera->principal[1] * aspy;
|
2011-11-07 12:55:18 +00:00
|
|
|
|
2013-02-25 09:46:47 +00:00
|
|
|
context->width = width;
|
|
|
|
|
context->height = height;
|
|
|
|
|
|
2012-06-15 11:03:23 +00:00
|
|
|
context->k1 = camera->k1;
|
|
|
|
|
context->k2 = camera->k2;
|
|
|
|
|
context->k3 = camera->k3;
|
2011-11-07 12:55:18 +00:00
|
|
|
|
2012-11-05 08:04:27 +00:00
|
|
|
context->success_threshold = tracking->settings.reconstruction_success_threshold;
|
|
|
|
|
context->use_fallback_reconstruction = tracking->settings.reconstruction_flag & TRACKING_USE_FALLBACK_RECONSTRUCTION;
|
|
|
|
|
|
2012-06-15 11:03:23 +00:00
|
|
|
context->tracks_map = tracks_map_new(context->object_name, context->is_camera, num_tracks, 0);
|
2011-11-07 12:55:18 +00:00
|
|
|
|
2012-06-15 11:03:23 +00:00
|
|
|
track = tracksbase->first;
|
|
|
|
|
while (track) {
|
|
|
|
|
int first = 0, last = track->markersnr - 1;
|
|
|
|
|
MovieTrackingMarker *first_marker = &track->markers[0];
|
|
|
|
|
MovieTrackingMarker *last_marker = &track->markers[track->markersnr - 1];
|
2011-11-07 12:55:18 +00:00
|
|
|
|
2012-06-15 11:03:23 +00:00
|
|
|
/* find first not-disabled marker */
|
|
|
|
|
while (first <= track->markersnr - 1 && first_marker->flag & MARKER_DISABLED) {
|
|
|
|
|
first++;
|
|
|
|
|
first_marker++;
|
|
|
|
|
}
|
2011-11-07 12:55:18 +00:00
|
|
|
|
2012-06-15 11:03:23 +00:00
|
|
|
/* find last not-disabled marker */
|
|
|
|
|
while (last >= 0 && last_marker->flag & MARKER_DISABLED) {
|
|
|
|
|
last--;
|
|
|
|
|
last_marker--;
|
|
|
|
|
}
|
2011-11-07 12:55:18 +00:00
|
|
|
|
2012-06-15 11:03:23 +00:00
|
|
|
if (first < track->markersnr - 1)
|
2012-10-23 16:21:55 +00:00
|
|
|
sfra = min_ii(sfra, first_marker->framenr);
|
2011-12-05 18:57:17 +00:00
|
|
|
|
2012-06-15 11:03:23 +00:00
|
|
|
if (last >= 0)
|
2012-10-23 16:21:55 +00:00
|
|
|
efra = max_ii(efra, last_marker->framenr);
|
2011-11-07 12:55:18 +00:00
|
|
|
|
2012-06-15 11:03:23 +00:00
|
|
|
tracks_map_insert(context->tracks_map, track, NULL);
|
|
|
|
|
|
|
|
|
|
track = track->next;
|
2012-03-24 06:18:31 +00:00
|
|
|
}
|
2011-11-07 12:55:18 +00:00
|
|
|
|
2012-06-15 11:03:23 +00:00
|
|
|
context->sfra = sfra;
|
|
|
|
|
context->efra = efra;
|
2011-12-05 18:57:17 +00:00
|
|
|
|
2012-06-15 11:03:23 +00:00
|
|
|
#ifdef WITH_LIBMV
|
|
|
|
|
context->tracks = libmv_tracks_new(tracksbase, width, height * aspy);
|
|
|
|
|
context->keyframe1 = keyframe1;
|
|
|
|
|
context->keyframe2 = keyframe2;
|
|
|
|
|
context->refine_flags = reconstruct_refine_intrinsics_get_flags(tracking, object);
|
|
|
|
|
#else
|
|
|
|
|
(void) width;
|
|
|
|
|
(void) height;
|
|
|
|
|
(void) keyframe1;
|
|
|
|
|
(void) keyframe2;
|
|
|
|
|
#endif
|
2011-12-05 18:57:17 +00:00
|
|
|
|
2012-06-15 11:03:23 +00:00
|
|
|
return context;
|
2011-12-05 18:57:17 +00:00
|
|
|
}
|
|
|
|
|
|
2012-06-15 11:03:23 +00:00
|
|
|
void BKE_tracking_reconstruction_context_free(MovieReconstructContext *context)
|
2011-12-05 18:57:17 +00:00
|
|
|
{
|
2012-06-15 11:03:23 +00:00
|
|
|
#ifdef WITH_LIBMV
|
|
|
|
|
if (context->reconstruction)
|
|
|
|
|
libmv_destroyReconstruction(context->reconstruction);
|
2011-12-05 18:57:17 +00:00
|
|
|
|
2012-06-15 11:03:23 +00:00
|
|
|
libmv_tracksDestroy(context->tracks);
|
|
|
|
|
#endif
|
2011-12-05 18:57:17 +00:00
|
|
|
|
2012-06-15 11:03:23 +00:00
|
|
|
tracks_map_free(context->tracks_map, NULL);
|
2011-12-05 18:57:17 +00:00
|
|
|
|
2012-06-15 11:03:23 +00:00
|
|
|
MEM_freeN(context);
|
2011-12-05 18:57:17 +00:00
|
|
|
}
|
|
|
|
|
|
2012-06-15 11:03:23 +00:00
|
|
|
#ifdef WITH_LIBMV
|
|
|
|
|
static void reconstruct_update_solve_cb(void *customdata, double progress, const char *message)
|
2011-12-05 18:57:17 +00:00
|
|
|
{
|
2012-06-15 11:03:23 +00:00
|
|
|
ReconstructProgressData *progressdata = customdata;
|
2011-12-05 18:57:17 +00:00
|
|
|
|
2012-06-15 11:03:23 +00:00
|
|
|
if (progressdata->progress) {
|
|
|
|
|
*progressdata->progress = progress;
|
|
|
|
|
*progressdata->do_update = TRUE;
|
2011-12-05 18:57:17 +00:00
|
|
|
}
|
|
|
|
|
|
2012-06-15 11:03:23 +00:00
|
|
|
BLI_snprintf(progressdata->stats_message, progressdata->message_size, "Solving camera | %s", message);
|
2011-12-05 18:57:17 +00:00
|
|
|
}
|
2013-02-25 09:24:31 +00:00
|
|
|
|
|
|
|
|
static void camraIntrincicsOptionsFromContext(libmv_cameraIntrinsicsOptions *camera_intrinsics_options,
|
|
|
|
|
MovieReconstructContext *context)
|
|
|
|
|
{
|
|
|
|
|
camera_intrinsics_options->focal_length = context->focal_length;
|
|
|
|
|
|
|
|
|
|
camera_intrinsics_options->principal_point_x = context->principal_point[0];
|
|
|
|
|
camera_intrinsics_options->principal_point_y = context->principal_point[1];
|
|
|
|
|
|
|
|
|
|
camera_intrinsics_options->k1 = context->k1;
|
|
|
|
|
camera_intrinsics_options->k2 = context->k2;
|
|
|
|
|
camera_intrinsics_options->k3 = context->k3;
|
2012-12-10 16:38:28 +00:00
|
|
|
|
2013-02-25 09:46:47 +00:00
|
|
|
camera_intrinsics_options->image_width = context->width;
|
|
|
|
|
camera_intrinsics_options->image_height = context->height;
|
2013-02-25 09:24:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void reconstructionOptionsFromContext(libmv_reconstructionOptions *reconstruction_options,
|
|
|
|
|
MovieReconstructContext *context)
|
|
|
|
|
{
|
|
|
|
|
reconstruction_options->keyframe1 = context->keyframe1;
|
|
|
|
|
reconstruction_options->keyframe2 = context->keyframe2;
|
|
|
|
|
|
|
|
|
|
reconstruction_options->refine_intrinsics = context->refine_flags;
|
|
|
|
|
|
|
|
|
|
reconstruction_options->success_threshold = context->success_threshold;
|
|
|
|
|
reconstruction_options->use_fallback_reconstruction = context->use_fallback_reconstruction;
|
|
|
|
|
}
|
2012-06-15 11:03:23 +00:00
|
|
|
#endif
|
2011-12-05 18:57:17 +00:00
|
|
|
|
2012-06-15 11:03:23 +00:00
|
|
|
void BKE_tracking_reconstruction_solve(MovieReconstructContext *context, short *stop, short *do_update,
|
|
|
|
|
float *progress, char *stats_message, int message_size)
|
2011-12-05 18:57:17 +00:00
|
|
|
{
|
2012-06-15 11:03:23 +00:00
|
|
|
#ifdef WITH_LIBMV
|
|
|
|
|
float error;
|
2011-12-05 18:57:17 +00:00
|
|
|
|
2012-06-15 11:03:23 +00:00
|
|
|
ReconstructProgressData progressdata;
|
2011-11-07 12:55:18 +00:00
|
|
|
|
2013-02-25 09:24:31 +00:00
|
|
|
libmv_cameraIntrinsicsOptions camera_intrinsics_options;
|
|
|
|
|
libmv_reconstructionOptions reconstruction_options;
|
|
|
|
|
|
2012-06-15 11:03:23 +00:00
|
|
|
progressdata.stop = stop;
|
|
|
|
|
progressdata.do_update = do_update;
|
|
|
|
|
progressdata.progress = progress;
|
|
|
|
|
progressdata.stats_message = stats_message;
|
|
|
|
|
progressdata.message_size = message_size;
|
2011-11-07 12:55:18 +00:00
|
|
|
|
2013-02-25 09:24:31 +00:00
|
|
|
camraIntrincicsOptionsFromContext(&camera_intrinsics_options, context);
|
|
|
|
|
reconstructionOptionsFromContext(&reconstruction_options, context);
|
|
|
|
|
|
2012-06-15 11:03:23 +00:00
|
|
|
if (context->motion_flag & TRACKING_MOTION_MODAL) {
|
|
|
|
|
context->reconstruction = libmv_solveModal(context->tracks,
|
2013-02-25 09:24:31 +00:00
|
|
|
&camera_intrinsics_options,
|
2013-02-28 14:24:42 +00:00
|
|
|
&reconstruction_options,
|
2012-06-15 11:03:23 +00:00
|
|
|
reconstruct_update_solve_cb, &progressdata);
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
context->reconstruction = libmv_solveReconstruction(context->tracks,
|
2013-02-25 09:24:31 +00:00
|
|
|
&camera_intrinsics_options,
|
|
|
|
|
&reconstruction_options,
|
2012-06-15 11:03:23 +00:00
|
|
|
reconstruct_update_solve_cb, &progressdata);
|
|
|
|
|
}
|
2011-11-07 12:55:18 +00:00
|
|
|
|
2012-06-15 11:03:23 +00:00
|
|
|
error = libmv_reprojectionError(context->reconstruction);
|
2011-11-07 12:55:18 +00:00
|
|
|
|
2012-06-15 11:03:23 +00:00
|
|
|
context->reprojection_error = error;
|
2011-11-07 16:26:23 +00:00
|
|
|
#else
|
2012-06-15 11:03:23 +00:00
|
|
|
(void) context;
|
|
|
|
|
(void) stop;
|
|
|
|
|
(void) do_update;
|
|
|
|
|
(void) progress;
|
|
|
|
|
(void) stats_message;
|
|
|
|
|
(void) message_size;
|
2011-11-07 12:55:18 +00:00
|
|
|
#endif
|
|
|
|
|
}
|
|
|
|
|
|
2012-06-15 11:03:23 +00:00
|
|
|
int BKE_tracking_reconstruction_finish(MovieReconstructContext *context, MovieTracking *tracking)
|
2011-11-07 12:55:18 +00:00
|
|
|
{
|
2012-06-15 11:03:23 +00:00
|
|
|
MovieTrackingReconstruction *reconstruction;
|
2011-11-07 12:55:18 +00:00
|
|
|
|
2012-06-15 11:03:23 +00:00
|
|
|
tracks_map_merge(context->tracks_map, tracking);
|
2012-10-26 12:36:50 +00:00
|
|
|
BKE_tracking_dopesheet_tag_update(tracking);
|
2011-11-07 12:55:18 +00:00
|
|
|
|
2012-06-15 11:03:23 +00:00
|
|
|
if (context->is_camera) {
|
|
|
|
|
reconstruction = &tracking->reconstruction;
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
MovieTrackingObject *object;
|
2011-11-07 12:55:18 +00:00
|
|
|
|
2012-06-15 11:03:23 +00:00
|
|
|
object = BKE_tracking_object_get_named(tracking, context->object_name);
|
|
|
|
|
reconstruction = &object->reconstruction;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
reconstruction->error = context->reprojection_error;
|
|
|
|
|
reconstruction->flag |= TRACKING_RECONSTRUCTED;
|
|
|
|
|
|
|
|
|
|
#ifdef WITH_LIBMV
|
|
|
|
|
if (!reconstruct_retrieve_libmv(context, tracking))
|
|
|
|
|
return FALSE;
|
2011-11-07 12:55:18 +00:00
|
|
|
#endif
|
2012-06-15 11:03:23 +00:00
|
|
|
|
|
|
|
|
return TRUE;
|
2011-11-07 12:55:18 +00:00
|
|
|
}
|
|
|
|
|
|
2012-06-15 11:03:23 +00:00
|
|
|
/*********************** Feature detection *************************/
|
|
|
|
|
|
2011-11-07 16:26:23 +00:00
|
|
|
#ifdef WITH_LIBMV
|
2012-06-15 11:03:23 +00:00
|
|
|
static int check_point_in_stroke(bGPDstroke *stroke, float x, float y)
|
2011-11-07 12:55:18 +00:00
|
|
|
{
|
|
|
|
|
int i, prev;
|
2012-03-25 23:19:21 +00:00
|
|
|
int count = 0;
|
|
|
|
|
bGPDspoint *points = stroke->points;
|
2011-11-07 12:55:18 +00:00
|
|
|
|
2012-03-25 23:19:21 +00:00
|
|
|
prev = stroke->totpoints - 1;
|
2011-11-07 12:55:18 +00:00
|
|
|
|
2012-05-07 08:53:59 +00:00
|
|
|
for (i = 0; i < stroke->totpoints; i++) {
|
2012-03-25 23:19:21 +00:00
|
|
|
if ((points[i].y < y && points[prev].y >= y) || (points[prev].y < y && points[i].y >= y)) {
|
|
|
|
|
float fac = (y - points[i].y) / (points[prev].y - points[i].y);
|
2011-11-07 12:55:18 +00:00
|
|
|
|
2012-03-25 23:19:21 +00:00
|
|
|
if (points[i].x + fac * (points[prev].x - points[i].x) < x)
|
2011-11-07 12:55:18 +00:00
|
|
|
count++;
|
|
|
|
|
}
|
|
|
|
|
|
2012-05-03 23:47:39 +00:00
|
|
|
prev = i;
|
2011-11-07 12:55:18 +00:00
|
|
|
}
|
|
|
|
|
|
2012-03-25 23:19:21 +00:00
|
|
|
return count % 2;
|
2011-11-07 12:55:18 +00:00
|
|
|
}
|
|
|
|
|
|
2012-06-15 11:03:23 +00:00
|
|
|
static int check_point_in_layer(bGPDlayer *layer, float x, float y)
|
2011-11-07 12:55:18 +00:00
|
|
|
{
|
2012-03-25 23:19:21 +00:00
|
|
|
bGPDframe *frame = layer->frames.first;
|
2011-11-07 12:55:18 +00:00
|
|
|
|
2012-03-24 06:18:31 +00:00
|
|
|
while (frame) {
|
2012-03-25 23:19:21 +00:00
|
|
|
bGPDstroke *stroke = frame->strokes.first;
|
|
|
|
|
|
2012-03-24 06:18:31 +00:00
|
|
|
while (stroke) {
|
2012-06-15 11:03:23 +00:00
|
|
|
if (check_point_in_stroke(stroke, x, y))
|
2012-03-25 23:19:21 +00:00
|
|
|
return TRUE;
|
2011-11-07 12:55:18 +00:00
|
|
|
|
2012-03-25 23:19:21 +00:00
|
|
|
stroke = stroke->next;
|
2011-11-07 12:55:18 +00:00
|
|
|
}
|
2012-03-25 23:19:21 +00:00
|
|
|
frame = frame->next;
|
2011-11-07 12:55:18 +00:00
|
|
|
}
|
|
|
|
|
|
2012-03-25 23:19:21 +00:00
|
|
|
return FALSE;
|
2011-11-07 12:55:18 +00:00
|
|
|
}
|
|
|
|
|
|
2012-06-15 11:03:23 +00:00
|
|
|
static void detect_retrieve_libmv_features(MovieTracking *tracking, ListBase *tracksbase,
|
|
|
|
|
struct libmv_Features *features, int framenr, int width, int height,
|
|
|
|
|
bGPDlayer *layer, int place_outside_layer)
|
2011-11-07 12:55:18 +00:00
|
|
|
{
|
|
|
|
|
int a;
|
|
|
|
|
|
2012-03-25 23:19:21 +00:00
|
|
|
a = libmv_countFeatures(features);
|
2012-03-24 06:18:31 +00:00
|
|
|
while (a--) {
|
2011-11-07 12:55:18 +00:00
|
|
|
MovieTrackingTrack *track;
|
|
|
|
|
double x, y, size, score;
|
2012-03-25 23:19:21 +00:00
|
|
|
int ok = TRUE;
|
2011-11-07 12:55:18 +00:00
|
|
|
float xu, yu;
|
|
|
|
|
|
|
|
|
|
libmv_getFeature(features, a, &x, &y, &score, &size);
|
|
|
|
|
|
2012-06-15 11:03:23 +00:00
|
|
|
xu = x / width;
|
|
|
|
|
yu = y / height;
|
|
|
|
|
|
|
|
|
|
if (layer)
|
|
|
|
|
ok = check_point_in_layer(layer, xu, yu) != place_outside_layer;
|
|
|
|
|
|
|
|
|
|
if (ok) {
|
|
|
|
|
track = BKE_tracking_track_add(tracking, tracksbase, xu, yu, framenr, width, height);
|
|
|
|
|
track->flag |= SELECT;
|
|
|
|
|
track->pat_flag |= SELECT;
|
|
|
|
|
track->search_flag |= SELECT;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static unsigned char *detect_get_frame_ucharbuf(ImBuf *ibuf)
|
|
|
|
|
{
|
|
|
|
|
int x, y;
|
|
|
|
|
unsigned char *pixels, *cp;
|
|
|
|
|
|
|
|
|
|
cp = pixels = MEM_callocN(ibuf->x * ibuf->y * sizeof(unsigned char), "tracking ucharBuf");
|
|
|
|
|
for (y = 0; y < ibuf->y; y++) {
|
|
|
|
|
for (x = 0; x < ibuf->x; x++) {
|
|
|
|
|
int pixel = ibuf->x * y + x;
|
|
|
|
|
|
|
|
|
|
if (ibuf->rect_float) {
|
|
|
|
|
const float *rrgbf = ibuf->rect_float + pixel * 4;
|
2012-07-03 19:09:07 +00:00
|
|
|
const float gray_f = 0.2126f * rrgbf[0] + 0.7152f * rrgbf[1] + 0.0722f * rrgbf[2];
|
2012-06-15 11:03:23 +00:00
|
|
|
|
2012-07-03 19:09:07 +00:00
|
|
|
*cp = FTOCHAR(gray_f);
|
2012-06-15 11:03:23 +00:00
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
const unsigned char *rrgb = (unsigned char *)ibuf->rect + pixel * 4;
|
2011-11-07 12:55:18 +00:00
|
|
|
|
2012-06-15 11:03:23 +00:00
|
|
|
*cp = 0.2126f * rrgb[0] + 0.7152f * rrgb[1] + 0.0722f * rrgb[2];
|
|
|
|
|
}
|
2011-11-07 12:55:18 +00:00
|
|
|
|
2012-06-15 11:03:23 +00:00
|
|
|
cp++;
|
2011-11-07 12:55:18 +00:00
|
|
|
}
|
|
|
|
|
}
|
2012-06-15 11:03:23 +00:00
|
|
|
|
|
|
|
|
return pixels;
|
2011-11-07 12:55:18 +00:00
|
|
|
}
|
2011-11-07 16:26:23 +00:00
|
|
|
#endif
|
2011-11-07 12:55:18 +00:00
|
|
|
|
2011-12-05 18:57:17 +00:00
|
|
|
void BKE_tracking_detect_fast(MovieTracking *tracking, ListBase *tracksbase, ImBuf *ibuf,
|
2012-03-25 23:19:21 +00:00
|
|
|
int framenr, int margin, int min_trackness, int min_distance, bGPDlayer *layer,
|
|
|
|
|
int place_outside_layer)
|
2011-11-07 12:55:18 +00:00
|
|
|
{
|
|
|
|
|
#ifdef WITH_LIBMV
|
|
|
|
|
struct libmv_Features *features;
|
2012-06-15 11:03:23 +00:00
|
|
|
unsigned char *pixels = detect_get_frame_ucharbuf(ibuf);
|
2011-11-07 12:55:18 +00:00
|
|
|
|
2012-03-25 23:19:21 +00:00
|
|
|
features = libmv_detectFeaturesFAST(pixels, ibuf->x, ibuf->y, ibuf->x,
|
|
|
|
|
margin, min_trackness, min_distance);
|
2011-11-07 12:55:18 +00:00
|
|
|
|
|
|
|
|
MEM_freeN(pixels);
|
|
|
|
|
|
2012-06-15 11:03:23 +00:00
|
|
|
detect_retrieve_libmv_features(tracking, tracksbase, features, framenr,
|
2012-06-16 09:18:00 +00:00
|
|
|
ibuf->x, ibuf->y, layer, place_outside_layer);
|
2011-11-07 12:55:18 +00:00
|
|
|
|
|
|
|
|
libmv_destroyFeatures(features);
|
2011-11-07 16:26:23 +00:00
|
|
|
#else
|
2012-03-25 23:19:21 +00:00
|
|
|
(void) tracking;
|
|
|
|
|
(void) tracksbase;
|
|
|
|
|
(void) ibuf;
|
|
|
|
|
(void) framenr;
|
|
|
|
|
(void) margin;
|
|
|
|
|
(void) min_trackness;
|
|
|
|
|
(void) min_distance;
|
|
|
|
|
(void) layer;
|
|
|
|
|
(void) place_outside_layer;
|
2011-11-07 12:55:18 +00:00
|
|
|
#endif
|
|
|
|
|
}
|
|
|
|
|
|
2012-06-15 11:03:23 +00:00
|
|
|
/*********************** 2D stabilization *************************/
|
2011-12-15 16:10:49 +00:00
|
|
|
|
2012-06-15 11:03:23 +00:00
|
|
|
static int stabilization_median_point_get(MovieTracking *tracking, int framenr, float median[2])
|
2011-11-07 12:55:18 +00:00
|
|
|
{
|
2012-03-25 23:19:21 +00:00
|
|
|
int ok = FALSE;
|
2011-11-07 12:55:18 +00:00
|
|
|
float min[2], max[2];
|
|
|
|
|
MovieTrackingTrack *track;
|
|
|
|
|
|
|
|
|
|
INIT_MINMAX2(min, max);
|
|
|
|
|
|
2012-03-25 23:19:21 +00:00
|
|
|
track = tracking->tracks.first;
|
2012-03-24 06:18:31 +00:00
|
|
|
while (track) {
|
2012-03-25 23:19:21 +00:00
|
|
|
if (track->flag & TRACK_USE_2D_STAB) {
|
2012-06-15 11:03:23 +00:00
|
|
|
MovieTrackingMarker *marker = BKE_tracking_marker_get(track, framenr);
|
2011-11-07 12:55:18 +00:00
|
|
|
|
2012-11-15 22:20:18 +00:00
|
|
|
minmax_v2v2_v2(min, max, marker->pos);
|
2011-11-07 12:55:18 +00:00
|
|
|
|
2012-03-25 23:19:21 +00:00
|
|
|
ok = TRUE;
|
2011-11-07 12:55:18 +00:00
|
|
|
}
|
|
|
|
|
|
2012-03-25 23:19:21 +00:00
|
|
|
track = track->next;
|
2011-11-07 12:55:18 +00:00
|
|
|
}
|
|
|
|
|
|
2012-03-25 23:19:21 +00:00
|
|
|
median[0] = (max[0] + min[0]) / 2.0f;
|
|
|
|
|
median[1] = (max[1] + min[1]) / 2.0f;
|
2011-11-07 12:55:18 +00:00
|
|
|
|
|
|
|
|
return ok;
|
|
|
|
|
}
|
|
|
|
|
|
2012-06-15 11:03:23 +00:00
|
|
|
static void stabilization_calculate_data(MovieTracking *tracking, int framenr, float width, float height,
|
|
|
|
|
float firstmedian[2], float median[2], float loc[2],
|
|
|
|
|
float *scale, float *angle)
|
2011-11-07 12:55:18 +00:00
|
|
|
{
|
2012-03-25 23:19:21 +00:00
|
|
|
MovieTrackingStabilization *stab = &tracking->stabilization;
|
2011-11-07 12:55:18 +00:00
|
|
|
|
2012-03-25 23:19:21 +00:00
|
|
|
*scale = (stab->scale - 1.0f) * stab->scaleinf + 1.0f;
|
|
|
|
|
*angle = 0.0f;
|
2011-11-07 12:55:18 +00:00
|
|
|
|
2012-06-10 19:59:02 +00:00
|
|
|
loc[0] = (firstmedian[0] - median[0]) * width * (*scale);
|
|
|
|
|
loc[1] = (firstmedian[1] - median[1]) * height * (*scale);
|
2011-11-07 12:55:18 +00:00
|
|
|
|
|
|
|
|
mul_v2_fl(loc, stab->locinf);
|
|
|
|
|
|
2012-03-25 23:19:21 +00:00
|
|
|
if ((stab->flag & TRACKING_STABILIZE_ROTATION) && stab->rot_track && stab->rotinf) {
|
2011-11-07 12:55:18 +00:00
|
|
|
MovieTrackingMarker *marker;
|
|
|
|
|
float a[2], b[2];
|
2012-03-25 23:19:21 +00:00
|
|
|
float x0 = (float)width / 2.0f, y0 = (float)height / 2.0f;
|
|
|
|
|
float x = median[0] * width, y = median[1] * height;
|
2011-11-07 12:55:18 +00:00
|
|
|
|
2012-06-15 11:03:23 +00:00
|
|
|
marker = BKE_tracking_marker_get(stab->rot_track, 1);
|
2011-11-07 12:55:18 +00:00
|
|
|
sub_v2_v2v2(a, marker->pos, firstmedian);
|
2012-03-25 23:19:21 +00:00
|
|
|
a[0] *= width;
|
|
|
|
|
a[1] *= height;
|
2011-11-07 12:55:18 +00:00
|
|
|
|
2012-06-15 11:03:23 +00:00
|
|
|
marker = BKE_tracking_marker_get(stab->rot_track, framenr);
|
2011-11-07 12:55:18 +00:00
|
|
|
sub_v2_v2v2(b, marker->pos, median);
|
2012-03-25 23:19:21 +00:00
|
|
|
b[0] *= width;
|
|
|
|
|
b[1] *= height;
|
2011-11-07 12:55:18 +00:00
|
|
|
|
2012-05-07 08:53:59 +00:00
|
|
|
*angle = -atan2(a[0] * b[1] - a[1] * b[0], a[0] * b[0] + a[1] * b[1]);
|
2012-03-25 23:19:21 +00:00
|
|
|
*angle *= stab->rotinf;
|
2011-11-07 12:55:18 +00:00
|
|
|
|
|
|
|
|
/* convert to rotation around image center */
|
2012-03-25 23:19:21 +00:00
|
|
|
loc[0] -= (x0 + (x - x0) * cosf(*angle) - (y - y0) * sinf(*angle) - x) * (*scale);
|
|
|
|
|
loc[1] -= (y0 + (x - x0) * sinf(*angle) + (y - y0) * cosf(*angle) - y) * (*scale);
|
2011-11-07 12:55:18 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2012-06-15 11:03:23 +00:00
|
|
|
static float stabilization_calculate_autoscale_factor(MovieTracking *tracking, int width, int height)
|
2011-11-07 12:55:18 +00:00
|
|
|
{
|
|
|
|
|
float firstmedian[2];
|
2012-03-25 23:19:21 +00:00
|
|
|
MovieTrackingStabilization *stab = &tracking->stabilization;
|
|
|
|
|
float aspect = tracking->camera.pixel_aspect;
|
2011-11-07 12:55:18 +00:00
|
|
|
|
2012-03-24 06:18:31 +00:00
|
|
|
if (stab->ok)
|
2011-11-07 12:55:18 +00:00
|
|
|
return stab->scale;
|
|
|
|
|
|
2012-06-15 11:03:23 +00:00
|
|
|
if (stabilization_median_point_get(tracking, 1, firstmedian)) {
|
2012-03-25 23:19:21 +00:00
|
|
|
int sfra = INT_MAX, efra = INT_MIN, cfra;
|
|
|
|
|
float scale = 1.0f;
|
2011-11-07 12:55:18 +00:00
|
|
|
MovieTrackingTrack *track;
|
|
|
|
|
|
2012-03-25 23:19:21 +00:00
|
|
|
stab->scale = 1.0f;
|
2011-11-07 12:55:18 +00:00
|
|
|
|
2012-03-25 23:19:21 +00:00
|
|
|
track = tracking->tracks.first;
|
2012-03-24 06:18:31 +00:00
|
|
|
while (track) {
|
2012-03-25 23:19:21 +00:00
|
|
|
if (track->flag & TRACK_USE_2D_STAB ||
|
2012-06-10 19:59:02 +00:00
|
|
|
((stab->flag & TRACKING_STABILIZE_ROTATION) && track == stab->rot_track))
|
2012-03-25 23:19:21 +00:00
|
|
|
{
|
2012-10-23 16:21:55 +00:00
|
|
|
sfra = min_ii(sfra, track->markers[0].framenr);
|
|
|
|
|
efra = max_ii(efra, track->markers[track->markersnr - 1].framenr);
|
2011-11-07 12:55:18 +00:00
|
|
|
}
|
|
|
|
|
|
2012-03-25 23:19:21 +00:00
|
|
|
track = track->next;
|
2011-11-07 12:55:18 +00:00
|
|
|
}
|
|
|
|
|
|
2012-03-25 23:19:21 +00:00
|
|
|
for (cfra = sfra; cfra <= efra; cfra++) {
|
2012-03-09 13:37:42 +00:00
|
|
|
float median[2];
|
2012-03-10 16:31:12 +00:00
|
|
|
float loc[2], angle, tmp_scale;
|
2012-03-09 13:37:42 +00:00
|
|
|
int i;
|
|
|
|
|
float mat[4][4];
|
2012-03-25 23:19:21 +00:00
|
|
|
float points[4][2] = {{0.0f, 0.0f}, {0.0f, height}, {width, height}, {width, 0.0f}};
|
2012-03-10 16:31:12 +00:00
|
|
|
float si, co;
|
|
|
|
|
|
2012-06-15 11:03:23 +00:00
|
|
|
stabilization_median_point_get(tracking, cfra, median);
|
2011-11-07 12:55:18 +00:00
|
|
|
|
2012-06-15 11:03:23 +00:00
|
|
|
stabilization_calculate_data(tracking, cfra, width, height, firstmedian, median, loc, &tmp_scale, &angle);
|
2011-11-07 12:55:18 +00:00
|
|
|
|
2012-06-15 11:03:23 +00:00
|
|
|
BKE_tracking_stabilization_data_to_mat4(width, height, aspect, loc, 1.0f, angle, mat);
|
2012-03-10 16:31:12 +00:00
|
|
|
|
|
|
|
|
si = sin(angle);
|
|
|
|
|
co = cos(angle);
|
2011-11-07 12:55:18 +00:00
|
|
|
|
2012-03-25 23:19:21 +00:00
|
|
|
for (i = 0; i < 4; i++) {
|
2012-03-09 13:37:42 +00:00
|
|
|
int j;
|
2012-05-07 08:53:59 +00:00
|
|
|
float a[3] = {0.0f, 0.0f, 0.0f}, b[3] = {0.0f, 0.0f, 0.0f};
|
2011-11-07 12:55:18 +00:00
|
|
|
|
2012-03-09 13:37:42 +00:00
|
|
|
copy_v3_v3(a, points[i]);
|
2012-05-07 08:53:59 +00:00
|
|
|
copy_v3_v3(b, points[(i + 1) % 4]);
|
2011-11-07 12:55:18 +00:00
|
|
|
|
2012-03-09 13:37:42 +00:00
|
|
|
mul_m4_v3(mat, a);
|
|
|
|
|
mul_m4_v3(mat, b);
|
2011-11-07 12:55:18 +00:00
|
|
|
|
2012-03-25 23:19:21 +00:00
|
|
|
for (j = 0; j < 4; j++) {
|
|
|
|
|
float point[3] = {points[j][0], points[j][1], 0.0f};
|
2012-03-09 13:37:42 +00:00
|
|
|
float v1[3], v2[3];
|
2011-11-07 12:55:18 +00:00
|
|
|
|
2012-03-09 13:37:42 +00:00
|
|
|
sub_v3_v3v3(v1, b, a);
|
|
|
|
|
sub_v3_v3v3(v2, point, a);
|
2011-11-07 12:55:18 +00:00
|
|
|
|
2012-03-24 06:18:31 +00:00
|
|
|
if (cross_v2v2(v1, v2) >= 0.0f) {
|
2012-03-10 16:31:12 +00:00
|
|
|
const float rotDx[4][2] = {{1.0f, 0.0f}, {0.0f, -1.0f}, {-1.0f, 0.0f}, {0.0f, 1.0f}};
|
|
|
|
|
const float rotDy[4][2] = {{0.0f, 1.0f}, {1.0f, 0.0f}, {0.0f, -1.0f}, {-1.0f, 0.0f}};
|
|
|
|
|
|
|
|
|
|
float dx = loc[0] * rotDx[j][0] + loc[1] * rotDx[j][1],
|
|
|
|
|
dy = loc[0] * rotDy[j][0] + loc[1] * rotDy[j][1];
|
|
|
|
|
|
|
|
|
|
float w, h, E, F, G, H, I, J, K, S;
|
|
|
|
|
|
2012-03-24 06:18:31 +00:00
|
|
|
if (j % 2) {
|
2012-03-10 16:31:12 +00:00
|
|
|
w = (float)height / 2.0f;
|
|
|
|
|
h = (float)width / 2.0f;
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
w = (float)width / 2.0f;
|
|
|
|
|
h = (float)height / 2.0f;
|
2011-11-07 12:55:18 +00:00
|
|
|
}
|
2012-03-10 16:31:12 +00:00
|
|
|
|
2012-06-10 19:59:02 +00:00
|
|
|
E = -w * co + h * si;
|
|
|
|
|
F = -h * co - w * si;
|
2012-03-10 16:31:12 +00:00
|
|
|
|
|
|
|
|
if ((i % 2) == (j % 2)) {
|
2012-06-10 19:59:02 +00:00
|
|
|
G = -w * co - h * si;
|
|
|
|
|
H = h * co - w * si;
|
2012-03-10 16:31:12 +00:00
|
|
|
}
|
|
|
|
|
else {
|
2012-06-10 19:59:02 +00:00
|
|
|
G = w * co + h * si;
|
|
|
|
|
H = -h * co + w * si;
|
2012-03-10 16:31:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
I = F - H;
|
|
|
|
|
J = G - E;
|
2012-06-10 19:59:02 +00:00
|
|
|
K = G * F - E * H;
|
2012-03-10 16:31:12 +00:00
|
|
|
|
2012-06-10 19:59:02 +00:00
|
|
|
S = (-w * I - h * J) / (dx * I + dy * J + K);
|
2012-03-10 16:31:12 +00:00
|
|
|
|
2012-10-23 13:28:22 +00:00
|
|
|
scale = max_ff(scale, S);
|
2011-11-07 12:55:18 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2012-03-25 23:19:21 +00:00
|
|
|
stab->scale = scale;
|
2011-11-07 12:55:18 +00:00
|
|
|
|
2012-05-07 08:53:59 +00:00
|
|
|
if (stab->maxscale > 0.0f)
|
2012-10-23 13:28:22 +00:00
|
|
|
stab->scale = min_ff(stab->scale, stab->maxscale);
|
2012-03-24 06:18:31 +00:00
|
|
|
}
|
|
|
|
|
else {
|
2012-03-25 23:19:21 +00:00
|
|
|
stab->scale = 1.0f;
|
2011-11-07 12:55:18 +00:00
|
|
|
}
|
|
|
|
|
|
2012-03-25 23:19:21 +00:00
|
|
|
stab->ok = TRUE;
|
2011-11-07 12:55:18 +00:00
|
|
|
|
|
|
|
|
return stab->scale;
|
|
|
|
|
}
|
|
|
|
|
|
2012-06-15 11:03:23 +00:00
|
|
|
static ImBuf *stabilization_allocate_ibuf(ImBuf *cacheibuf, ImBuf *srcibuf, int fill)
|
2011-11-07 12:55:18 +00:00
|
|
|
{
|
|
|
|
|
int flags;
|
|
|
|
|
|
2012-03-24 06:18:31 +00:00
|
|
|
if (cacheibuf && (cacheibuf->x != srcibuf->x || cacheibuf->y != srcibuf->y)) {
|
2011-11-07 12:55:18 +00:00
|
|
|
IMB_freeImBuf(cacheibuf);
|
2012-03-25 23:19:21 +00:00
|
|
|
cacheibuf = NULL;
|
2011-11-07 12:55:18 +00:00
|
|
|
}
|
|
|
|
|
|
2012-03-25 23:19:21 +00:00
|
|
|
flags = IB_rect;
|
2011-11-07 12:55:18 +00:00
|
|
|
|
2012-03-24 06:18:31 +00:00
|
|
|
if (srcibuf->rect_float)
|
2012-03-25 23:19:21 +00:00
|
|
|
flags |= IB_rectfloat;
|
2011-11-07 12:55:18 +00:00
|
|
|
|
2012-03-24 06:18:31 +00:00
|
|
|
if (cacheibuf) {
|
|
|
|
|
if (fill) {
|
2012-03-25 23:19:21 +00:00
|
|
|
float col[4] = {0.0f, 0.0f, 0.0f, 0.0f};
|
|
|
|
|
|
2011-11-07 12:55:18 +00:00
|
|
|
IMB_rectfill(cacheibuf, col);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else {
|
2012-03-25 23:19:21 +00:00
|
|
|
cacheibuf = IMB_allocImBuf(srcibuf->x, srcibuf->y, srcibuf->planes, flags);
|
2011-11-07 12:55:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return cacheibuf;
|
|
|
|
|
}
|
|
|
|
|
|
2012-06-15 11:15:48 +00:00
|
|
|
/* NOTE: frame number should be in clip space, not scene space */
|
2012-06-15 11:03:23 +00:00
|
|
|
void BKE_tracking_stabilization_data_get(MovieTracking *tracking, int framenr, int width, int height,
|
|
|
|
|
float loc[2], float *scale, float *angle)
|
2011-11-07 12:55:18 +00:00
|
|
|
{
|
|
|
|
|
float firstmedian[2], median[2];
|
2012-03-25 23:19:21 +00:00
|
|
|
MovieTrackingStabilization *stab = &tracking->stabilization;
|
2011-11-07 12:55:18 +00:00
|
|
|
|
2012-03-25 23:19:21 +00:00
|
|
|
if ((stab->flag & TRACKING_2D_STABILIZATION) == 0) {
|
2011-11-07 12:55:18 +00:00
|
|
|
zero_v2(loc);
|
2012-05-03 23:47:39 +00:00
|
|
|
*scale = 1.0f;
|
|
|
|
|
*angle = 0.0f;
|
2011-11-07 12:55:18 +00:00
|
|
|
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2012-06-15 11:03:23 +00:00
|
|
|
if (stabilization_median_point_get(tracking, 1, firstmedian)) {
|
|
|
|
|
stabilization_median_point_get(tracking, framenr, median);
|
2011-11-07 12:55:18 +00:00
|
|
|
|
2012-03-25 23:19:21 +00:00
|
|
|
if ((stab->flag & TRACKING_AUTOSCALE) == 0)
|
|
|
|
|
stab->scale = 1.0f;
|
2011-11-07 12:55:18 +00:00
|
|
|
|
2012-03-24 06:18:31 +00:00
|
|
|
if (!stab->ok) {
|
2012-03-25 23:19:21 +00:00
|
|
|
if (stab->flag & TRACKING_AUTOSCALE)
|
2012-06-15 11:03:23 +00:00
|
|
|
stabilization_calculate_autoscale_factor(tracking, width, height);
|
2011-11-07 12:55:18 +00:00
|
|
|
|
2012-06-15 11:03:23 +00:00
|
|
|
stabilization_calculate_data(tracking, framenr, width, height, firstmedian, median, loc, scale, angle);
|
2011-11-07 12:55:18 +00:00
|
|
|
|
2012-03-25 23:19:21 +00:00
|
|
|
stab->ok = TRUE;
|
2012-03-24 06:18:31 +00:00
|
|
|
}
|
|
|
|
|
else {
|
2012-06-15 11:03:23 +00:00
|
|
|
stabilization_calculate_data(tracking, framenr, width, height, firstmedian, median, loc, scale, angle);
|
2011-11-07 12:55:18 +00:00
|
|
|
}
|
2012-03-24 06:18:31 +00:00
|
|
|
}
|
|
|
|
|
else {
|
2011-11-07 12:55:18 +00:00
|
|
|
zero_v2(loc);
|
2012-03-25 23:19:21 +00:00
|
|
|
*scale = 1.0f;
|
|
|
|
|
*angle = 0.0f;
|
2011-11-07 12:55:18 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2012-06-15 11:15:48 +00:00
|
|
|
/* NOTE: frame number should be in clip space, not scene space */
|
2012-06-15 11:03:23 +00:00
|
|
|
ImBuf *BKE_tracking_stabilize_frame(MovieTracking *tracking, int framenr, ImBuf *ibuf,
|
|
|
|
|
float loc[2], float *scale, float *angle)
|
2011-11-07 12:55:18 +00:00
|
|
|
{
|
|
|
|
|
float tloc[2], tscale, tangle;
|
2012-03-25 23:19:21 +00:00
|
|
|
MovieTrackingStabilization *stab = &tracking->stabilization;
|
2011-11-07 12:55:18 +00:00
|
|
|
ImBuf *tmpibuf;
|
2012-03-25 23:19:21 +00:00
|
|
|
float width = ibuf->x, height = ibuf->y;
|
|
|
|
|
float aspect = tracking->camera.pixel_aspect;
|
2011-11-07 12:55:18 +00:00
|
|
|
|
2012-03-25 23:19:21 +00:00
|
|
|
if (loc)
|
|
|
|
|
copy_v2_v2(tloc, loc);
|
2011-11-07 12:55:18 +00:00
|
|
|
|
2012-03-25 23:19:21 +00:00
|
|
|
if (scale)
|
|
|
|
|
tscale = *scale;
|
|
|
|
|
|
|
|
|
|
if ((stab->flag & TRACKING_2D_STABILIZATION) == 0) {
|
|
|
|
|
if (loc)
|
|
|
|
|
zero_v2(loc);
|
|
|
|
|
|
|
|
|
|
if (scale)
|
|
|
|
|
*scale = 1.0f;
|
2011-11-07 12:55:18 +00:00
|
|
|
|
|
|
|
|
return ibuf;
|
|
|
|
|
}
|
|
|
|
|
|
2012-06-15 11:03:23 +00:00
|
|
|
BKE_tracking_stabilization_data_get(tracking, framenr, width, height, tloc, &tscale, &tangle);
|
2011-11-07 12:55:18 +00:00
|
|
|
|
2012-06-15 11:03:23 +00:00
|
|
|
tmpibuf = stabilization_allocate_ibuf(NULL, ibuf, TRUE);
|
2011-11-07 12:55:18 +00:00
|
|
|
|
|
|
|
|
/* scale would be handled by matrix transformation when angle is non-zero */
|
2012-03-25 23:19:21 +00:00
|
|
|
if (tscale != 1.0f && tangle == 0.0f) {
|
2011-11-07 12:55:18 +00:00
|
|
|
ImBuf *scaleibuf;
|
|
|
|
|
|
2012-06-15 11:03:23 +00:00
|
|
|
stabilization_calculate_autoscale_factor(tracking, width, height);
|
2011-11-07 12:55:18 +00:00
|
|
|
|
2012-06-15 11:03:23 +00:00
|
|
|
scaleibuf = stabilization_allocate_ibuf(stab->scaleibuf, ibuf, 0);
|
2012-03-25 23:19:21 +00:00
|
|
|
stab->scaleibuf = scaleibuf;
|
2011-11-07 12:55:18 +00:00
|
|
|
|
|
|
|
|
IMB_rectcpy(scaleibuf, ibuf, 0, 0, 0, 0, ibuf->x, ibuf->y);
|
2012-06-10 19:59:02 +00:00
|
|
|
IMB_scalefastImBuf(scaleibuf, ibuf->x * tscale, ibuf->y * tscale);
|
2011-11-07 12:55:18 +00:00
|
|
|
|
2012-03-25 23:19:21 +00:00
|
|
|
ibuf = scaleibuf;
|
2011-11-07 12:55:18 +00:00
|
|
|
}
|
|
|
|
|
|
2012-03-25 23:19:21 +00:00
|
|
|
if (tangle == 0.0f) {
|
2011-11-07 12:55:18 +00:00
|
|
|
/* if angle is zero, then it's much faster to use rect copy
|
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
|
|
|
* but could be issues with subpixel precisions
|
|
|
|
|
*/
|
2012-03-25 23:19:21 +00:00
|
|
|
IMB_rectcpy(tmpibuf, ibuf,
|
|
|
|
|
tloc[0] - (tscale - 1.0f) * width / 2.0f,
|
|
|
|
|
tloc[1] - (tscale - 1.0f) * height / 2.0f,
|
|
|
|
|
0, 0, ibuf->x, ibuf->y);
|
2012-03-24 06:18:31 +00:00
|
|
|
}
|
|
|
|
|
else {
|
2011-11-07 12:55:18 +00:00
|
|
|
float mat[4][4];
|
2012-03-25 23:19:21 +00:00
|
|
|
int i, j, filter = tracking->stabilization.filter;
|
2012-06-10 19:59:02 +00:00
|
|
|
void (*interpolation)(struct ImBuf *, struct ImBuf *, float, float, int, int) = NULL;
|
2011-11-07 12:55:18 +00:00
|
|
|
|
2012-06-15 11:03:23 +00:00
|
|
|
BKE_tracking_stabilization_data_to_mat4(ibuf->x, ibuf->y, aspect, tloc, tscale, tangle, mat);
|
2011-11-07 12:55:18 +00:00
|
|
|
invert_m4(mat);
|
|
|
|
|
|
2012-12-11 14:19:41 +00:00
|
|
|
if (filter == TRACKING_FILTER_NEAREST)
|
|
|
|
|
interpolation = nearest_interpolation;
|
2012-03-24 06:18:31 +00:00
|
|
|
else if (filter == TRACKING_FILTER_BILINEAR)
|
2012-02-16 15:03:37 +00:00
|
|
|
interpolation = bilinear_interpolation;
|
2012-03-24 06:18:31 +00:00
|
|
|
else if (filter == TRACKING_FILTER_BICUBIC)
|
2012-02-16 15:03:37 +00:00
|
|
|
interpolation = bicubic_interpolation;
|
2012-03-13 10:31:42 +00:00
|
|
|
else
|
|
|
|
|
/* fallback to default interpolation method */
|
2012-12-11 14:19:41 +00:00
|
|
|
interpolation = nearest_interpolation;
|
2012-02-16 15:03:37 +00:00
|
|
|
|
2012-03-25 23:19:21 +00:00
|
|
|
for (j = 0; j < tmpibuf->y; j++) {
|
2012-06-10 19:59:02 +00:00
|
|
|
for (i = 0; i < tmpibuf->x; i++) {
|
2012-03-25 23:19:21 +00:00
|
|
|
float vec[3] = {i, j, 0};
|
2011-11-07 12:55:18 +00:00
|
|
|
|
|
|
|
|
mul_v3_m4v3(vec, mat, vec);
|
|
|
|
|
|
2012-02-16 15:03:37 +00:00
|
|
|
interpolation(ibuf, tmpibuf, vec[0], vec[1], i, j);
|
2011-11-07 12:55:18 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2012-03-25 23:19:21 +00:00
|
|
|
tmpibuf->userflags |= IB_MIPMAP_INVALID;
|
2011-11-07 12:55:18 +00:00
|
|
|
|
2012-03-24 06:18:31 +00:00
|
|
|
if (tmpibuf->rect_float)
|
2012-03-25 23:19:21 +00:00
|
|
|
tmpibuf->userflags |= IB_RECT_INVALID;
|
|
|
|
|
|
|
|
|
|
if (loc)
|
|
|
|
|
copy_v2_v2(loc, tloc);
|
2011-11-07 12:55:18 +00:00
|
|
|
|
2012-03-25 23:19:21 +00:00
|
|
|
if (scale)
|
2012-05-03 23:47:39 +00:00
|
|
|
*scale = tscale;
|
2012-03-25 23:19:21 +00:00
|
|
|
|
|
|
|
|
if (angle)
|
2012-05-03 23:47:39 +00:00
|
|
|
*angle = tangle;
|
2011-11-07 12:55:18 +00:00
|
|
|
|
|
|
|
|
return tmpibuf;
|
|
|
|
|
}
|
|
|
|
|
|
2012-06-15 11:03:23 +00:00
|
|
|
void BKE_tracking_stabilization_data_to_mat4(int width, int height, float aspect, float loc[2],
|
|
|
|
|
float scale, float angle, float mat[4][4])
|
2011-11-07 12:55:18 +00:00
|
|
|
{
|
2012-02-16 15:03:18 +00:00
|
|
|
float lmat[4][4], rmat[4][4], smat[4][4], cmat[4][4], icmat[4][4], amat[4][4], iamat[4][4];
|
2012-05-07 08:53:59 +00:00
|
|
|
float svec[3] = {scale, scale, scale};
|
2011-11-07 12:55:18 +00:00
|
|
|
|
|
|
|
|
unit_m4(rmat);
|
|
|
|
|
unit_m4(lmat);
|
|
|
|
|
unit_m4(smat);
|
|
|
|
|
unit_m4(cmat);
|
2012-02-16 15:03:18 +00:00
|
|
|
unit_m4(amat);
|
|
|
|
|
|
|
|
|
|
/* aspect ratio correction matrix */
|
|
|
|
|
amat[0][0] = 1.0f / aspect;
|
|
|
|
|
invert_m4_m4(iamat, amat);
|
2011-11-07 12:55:18 +00:00
|
|
|
|
|
|
|
|
/* image center as rotation center */
|
2012-03-25 23:19:21 +00:00
|
|
|
cmat[3][0] = (float)width / 2.0f;
|
|
|
|
|
cmat[3][1] = (float)height / 2.0f;
|
2011-11-07 12:55:18 +00:00
|
|
|
invert_m4_m4(icmat, cmat);
|
|
|
|
|
|
2012-06-10 19:59:02 +00:00
|
|
|
size_to_mat4(smat, svec); /* scale matrix */
|
|
|
|
|
add_v2_v2(lmat[3], loc); /* translation matrix */
|
|
|
|
|
rotate_m4(rmat, 'Z', angle); /* rotation matrix */
|
2011-11-07 12:55:18 +00:00
|
|
|
|
|
|
|
|
/* compose transformation matrix */
|
2012-03-09 10:01:29 +00:00
|
|
|
mul_serie_m4(mat, lmat, cmat, amat, rmat, iamat, smat, icmat, NULL);
|
2011-11-07 12:55:18 +00:00
|
|
|
}
|
|
|
|
|
|
2012-06-15 11:03:23 +00:00
|
|
|
/*********************** Dopesheet functions *************************/
|
2012-04-30 16:19:20 +00:00
|
|
|
|
|
|
|
|
static int channels_alpha_sort(void *a, void *b)
|
|
|
|
|
{
|
|
|
|
|
MovieTrackingDopesheetChannel *channel_a = a;
|
|
|
|
|
MovieTrackingDopesheetChannel *channel_b = b;
|
|
|
|
|
|
|
|
|
|
if (BLI_strcasecmp(channel_a->track->name, channel_b->track->name) > 0)
|
|
|
|
|
return 1;
|
|
|
|
|
else
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
2012-05-03 19:28:41 +00:00
|
|
|
static int channels_total_track_sort(void *a, void *b)
|
|
|
|
|
{
|
|
|
|
|
MovieTrackingDopesheetChannel *channel_a = a;
|
|
|
|
|
MovieTrackingDopesheetChannel *channel_b = b;
|
|
|
|
|
|
|
|
|
|
if (channel_a->total_frames > channel_b->total_frames)
|
|
|
|
|
return 1;
|
|
|
|
|
else
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static int channels_longest_segment_sort(void *a, void *b)
|
|
|
|
|
{
|
|
|
|
|
MovieTrackingDopesheetChannel *channel_a = a;
|
|
|
|
|
MovieTrackingDopesheetChannel *channel_b = b;
|
|
|
|
|
|
|
|
|
|
if (channel_a->max_segment > channel_b->max_segment)
|
|
|
|
|
return 1;
|
|
|
|
|
else
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
2012-06-08 16:42:24 +00:00
|
|
|
static int channels_average_error_sort(void *a, void *b)
|
|
|
|
|
{
|
|
|
|
|
MovieTrackingDopesheetChannel *channel_a = a;
|
|
|
|
|
MovieTrackingDopesheetChannel *channel_b = b;
|
|
|
|
|
|
|
|
|
|
if (channel_a->track->error > channel_b->track->error)
|
|
|
|
|
return 1;
|
|
|
|
|
else
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
2012-05-03 19:28:41 +00:00
|
|
|
static int channels_alpha_inverse_sort(void *a, void *b)
|
|
|
|
|
{
|
|
|
|
|
if (channels_alpha_sort(a, b))
|
|
|
|
|
return 0;
|
|
|
|
|
else
|
|
|
|
|
return 1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static int channels_total_track_inverse_sort(void *a, void *b)
|
|
|
|
|
{
|
|
|
|
|
if (channels_total_track_sort(a, b))
|
|
|
|
|
return 0;
|
|
|
|
|
else
|
|
|
|
|
return 1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static int channels_longest_segment_inverse_sort(void *a, void *b)
|
|
|
|
|
{
|
|
|
|
|
if (channels_longest_segment_sort(a, b))
|
|
|
|
|
return 0;
|
|
|
|
|
else
|
|
|
|
|
return 1;
|
|
|
|
|
}
|
|
|
|
|
|
2012-06-08 16:42:24 +00:00
|
|
|
static int channels_average_error_inverse_sort(void *a, void *b)
|
|
|
|
|
{
|
|
|
|
|
MovieTrackingDopesheetChannel *channel_a = a;
|
|
|
|
|
MovieTrackingDopesheetChannel *channel_b = b;
|
|
|
|
|
|
|
|
|
|
if (channel_a->track->error < channel_b->track->error)
|
|
|
|
|
return 1;
|
|
|
|
|
else
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
2012-05-03 17:52:34 +00:00
|
|
|
static void channels_segments_calc(MovieTrackingDopesheetChannel *channel)
|
|
|
|
|
{
|
|
|
|
|
MovieTrackingTrack *track = channel->track;
|
|
|
|
|
int i, segment;
|
|
|
|
|
|
|
|
|
|
channel->tot_segment = 0;
|
|
|
|
|
channel->max_segment = 0;
|
|
|
|
|
channel->total_frames = 0;
|
|
|
|
|
|
|
|
|
|
/* count */
|
|
|
|
|
i = 0;
|
|
|
|
|
while (i < track->markersnr) {
|
|
|
|
|
MovieTrackingMarker *marker = &track->markers[i];
|
|
|
|
|
|
|
|
|
|
if ((marker->flag & MARKER_DISABLED) == 0) {
|
|
|
|
|
int prev_fra = marker->framenr, len = 0;
|
|
|
|
|
|
|
|
|
|
i++;
|
|
|
|
|
while (i < track->markersnr) {
|
|
|
|
|
marker = &track->markers[i];
|
|
|
|
|
|
|
|
|
|
if (marker->framenr != prev_fra + 1)
|
|
|
|
|
break;
|
|
|
|
|
if (marker->flag & MARKER_DISABLED)
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
prev_fra = marker->framenr;
|
|
|
|
|
len++;
|
|
|
|
|
i++;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
channel->tot_segment++;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
i++;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!channel->tot_segment)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
channel->segments = MEM_callocN(2 * sizeof(int) * channel->tot_segment, "tracking channel segments");
|
|
|
|
|
|
|
|
|
|
/* create segments */
|
|
|
|
|
i = 0;
|
|
|
|
|
segment = 0;
|
|
|
|
|
while (i < track->markersnr) {
|
|
|
|
|
MovieTrackingMarker *marker = &track->markers[i];
|
|
|
|
|
|
|
|
|
|
if ((marker->flag & MARKER_DISABLED) == 0) {
|
|
|
|
|
MovieTrackingMarker *start_marker = marker;
|
|
|
|
|
int prev_fra = marker->framenr, len = 0;
|
|
|
|
|
|
|
|
|
|
i++;
|
|
|
|
|
while (i < track->markersnr) {
|
|
|
|
|
marker = &track->markers[i];
|
|
|
|
|
|
|
|
|
|
if (marker->framenr != prev_fra + 1)
|
|
|
|
|
break;
|
|
|
|
|
if (marker->flag & MARKER_DISABLED)
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
prev_fra = marker->framenr;
|
|
|
|
|
channel->total_frames++;
|
|
|
|
|
len++;
|
|
|
|
|
i++;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
channel->segments[2 * segment] = start_marker->framenr;
|
|
|
|
|
channel->segments[2 * segment + 1] = start_marker->framenr + len;
|
|
|
|
|
|
2012-10-23 16:21:55 +00:00
|
|
|
channel->max_segment = max_ii(channel->max_segment, len);
|
2012-05-03 17:52:34 +00:00
|
|
|
segment++;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
i++;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2012-10-26 12:36:50 +00:00
|
|
|
static void tracking_dopesheet_sort(MovieTracking *tracking, int sort_method, int inverse)
|
2012-05-03 23:15:01 +00:00
|
|
|
{
|
|
|
|
|
MovieTrackingDopesheet *dopesheet = &tracking->dopesheet;
|
|
|
|
|
|
|
|
|
|
if (inverse) {
|
2012-06-12 17:10:24 +00:00
|
|
|
if (sort_method == TRACKING_DOPE_SORT_NAME) {
|
2012-05-03 23:15:01 +00:00
|
|
|
BLI_sortlist(&dopesheet->channels, channels_alpha_inverse_sort);
|
|
|
|
|
}
|
2012-06-12 17:10:24 +00:00
|
|
|
else if (sort_method == TRACKING_DOPE_SORT_LONGEST) {
|
2012-05-03 23:15:01 +00:00
|
|
|
BLI_sortlist(&dopesheet->channels, channels_longest_segment_inverse_sort);
|
|
|
|
|
}
|
2012-06-12 17:10:24 +00:00
|
|
|
else if (sort_method == TRACKING_DOPE_SORT_TOTAL) {
|
2012-05-03 23:15:01 +00:00
|
|
|
BLI_sortlist(&dopesheet->channels, channels_total_track_inverse_sort);
|
|
|
|
|
}
|
2012-06-12 17:10:24 +00:00
|
|
|
else if (sort_method == TRACKING_DOPE_SORT_AVERAGE_ERROR) {
|
2012-06-08 16:42:24 +00:00
|
|
|
BLI_sortlist(&dopesheet->channels, channels_average_error_inverse_sort);
|
|
|
|
|
}
|
2012-05-03 23:15:01 +00:00
|
|
|
}
|
|
|
|
|
else {
|
2012-06-12 17:10:24 +00:00
|
|
|
if (sort_method == TRACKING_DOPE_SORT_NAME) {
|
2012-05-03 23:15:01 +00:00
|
|
|
BLI_sortlist(&dopesheet->channels, channels_alpha_sort);
|
|
|
|
|
}
|
2012-06-12 17:10:24 +00:00
|
|
|
else if (sort_method == TRACKING_DOPE_SORT_LONGEST) {
|
2012-05-03 23:15:01 +00:00
|
|
|
BLI_sortlist(&dopesheet->channels, channels_longest_segment_sort);
|
|
|
|
|
}
|
2012-06-12 17:10:24 +00:00
|
|
|
else if (sort_method == TRACKING_DOPE_SORT_TOTAL) {
|
2012-05-03 23:15:01 +00:00
|
|
|
BLI_sortlist(&dopesheet->channels, channels_total_track_sort);
|
|
|
|
|
}
|
2012-06-12 17:10:24 +00:00
|
|
|
else if (sort_method == TRACKING_DOPE_SORT_AVERAGE_ERROR) {
|
2012-06-08 16:42:24 +00:00
|
|
|
BLI_sortlist(&dopesheet->channels, channels_average_error_sort);
|
|
|
|
|
}
|
2012-05-03 23:15:01 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2013-02-22 10:13:15 +00:00
|
|
|
static int coverage_from_count(int count)
|
|
|
|
|
{
|
|
|
|
|
if (count < 8)
|
|
|
|
|
return TRACKING_COVERAGE_BAD;
|
|
|
|
|
else if (count < 16)
|
|
|
|
|
return TRACKING_COVERAGE_ACCEPTABLE;
|
|
|
|
|
return TRACKING_COVERAGE_OK;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void tracking_dopesheet_calc_coverage(MovieTracking *tracking)
|
|
|
|
|
{
|
|
|
|
|
MovieTrackingDopesheet *dopesheet = &tracking->dopesheet;
|
|
|
|
|
MovieTrackingObject *object = BKE_tracking_object_get_active(tracking);
|
|
|
|
|
ListBase *tracksbase = BKE_tracking_object_get_tracks(tracking, object);
|
|
|
|
|
MovieTrackingTrack *track;
|
|
|
|
|
int frames, start_frame = INT_MAX, end_frame = -INT_MAX;
|
|
|
|
|
int *per_frame_counter;
|
|
|
|
|
int prev_coverage, last_segment_frame;
|
|
|
|
|
int i;
|
|
|
|
|
|
|
|
|
|
/* find frame boundaries */
|
|
|
|
|
for (track = tracksbase->first; track; track = track->next) {
|
|
|
|
|
start_frame = min_ii(start_frame, track->markers[0].framenr);
|
|
|
|
|
end_frame = max_ii(end_frame, track->markers[track->markersnr - 1].framenr);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
frames = end_frame - start_frame + 1;
|
|
|
|
|
|
|
|
|
|
/* this is a per-frame counter of markers (how many markers belongs to the same frame) */
|
|
|
|
|
per_frame_counter = MEM_callocN(sizeof(int) * frames, "per frame track counter");
|
|
|
|
|
|
|
|
|
|
/* find per-frame markers count */
|
|
|
|
|
for (track = tracksbase->first; track; track = track->next) {
|
|
|
|
|
int i;
|
|
|
|
|
|
|
|
|
|
for (i = 0; i < track->markersnr; i++) {
|
|
|
|
|
MovieTrackingMarker *marker = &track->markers[i];
|
|
|
|
|
|
|
|
|
|
/* TODO: perhaps we need to add check for non-single-frame track here */
|
|
|
|
|
if ((marker->flag & MARKER_DISABLED) == 0)
|
|
|
|
|
per_frame_counter[marker->framenr - start_frame]++;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* convert markers count to coverage and detect segments with the same coverage */
|
|
|
|
|
prev_coverage = coverage_from_count(per_frame_counter[0]);
|
|
|
|
|
last_segment_frame = start_frame;
|
|
|
|
|
|
|
|
|
|
/* means only disabled tracks in the beginning, could be ignored */
|
|
|
|
|
if (!per_frame_counter[0])
|
|
|
|
|
prev_coverage = TRACKING_COVERAGE_OK;
|
|
|
|
|
|
|
|
|
|
for (i = 1; i < frames; i++) {
|
|
|
|
|
int coverage = coverage_from_count(per_frame_counter[i]);
|
|
|
|
|
|
|
|
|
|
/* means only disabled tracks in the end, could be ignored */
|
|
|
|
|
if (i == frames - 1 && !per_frame_counter[i])
|
|
|
|
|
coverage = TRACKING_COVERAGE_OK;
|
|
|
|
|
|
|
|
|
|
if (coverage != prev_coverage || i == frames - 1) {
|
|
|
|
|
MovieTrackingDopesheetCoverageSegment *coverage_segment;
|
|
|
|
|
int end_segment_frame = i - 1 + start_frame;
|
|
|
|
|
|
|
|
|
|
if (end_segment_frame == last_segment_frame)
|
|
|
|
|
end_segment_frame++;
|
|
|
|
|
|
|
|
|
|
coverage_segment = MEM_callocN(sizeof(MovieTrackingDopesheetCoverageSegment), "tracking coverage segment");
|
|
|
|
|
coverage_segment->coverage = prev_coverage;
|
|
|
|
|
coverage_segment->start_frame = last_segment_frame;
|
|
|
|
|
coverage_segment->end_frame = end_segment_frame;
|
|
|
|
|
|
|
|
|
|
BLI_addtail(&dopesheet->coverage_segments, coverage_segment);
|
|
|
|
|
|
|
|
|
|
last_segment_frame = end_segment_frame;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
prev_coverage = coverage;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
MEM_freeN(per_frame_counter);
|
|
|
|
|
}
|
|
|
|
|
|
2012-05-03 23:15:01 +00:00
|
|
|
void BKE_tracking_dopesheet_tag_update(MovieTracking *tracking)
|
|
|
|
|
{
|
|
|
|
|
MovieTrackingDopesheet *dopesheet = &tracking->dopesheet;
|
|
|
|
|
|
|
|
|
|
dopesheet->ok = FALSE;
|
|
|
|
|
}
|
|
|
|
|
|
2012-06-12 17:10:24 +00:00
|
|
|
void BKE_tracking_dopesheet_update(MovieTracking *tracking)
|
2012-04-30 16:19:20 +00:00
|
|
|
{
|
2012-06-15 11:03:23 +00:00
|
|
|
MovieTrackingObject *object = BKE_tracking_object_get_active(tracking);
|
2012-04-30 16:19:20 +00:00
|
|
|
MovieTrackingDopesheet *dopesheet = &tracking->dopesheet;
|
|
|
|
|
MovieTrackingTrack *track;
|
2012-06-12 17:11:00 +00:00
|
|
|
MovieTrackingReconstruction *reconstruction;
|
2012-06-15 11:03:23 +00:00
|
|
|
ListBase *tracksbase = BKE_tracking_object_get_tracks(tracking, object);
|
2012-06-12 17:11:00 +00:00
|
|
|
|
2012-06-12 17:10:24 +00:00
|
|
|
short sort_method = dopesheet->sort_method;
|
|
|
|
|
short inverse = dopesheet->flag & TRACKING_DOPE_SORT_INVERSE;
|
2012-06-12 17:10:47 +00:00
|
|
|
short sel_only = dopesheet->flag & TRACKING_DOPE_SELECTED_ONLY;
|
|
|
|
|
short show_hidden = dopesheet->flag & TRACKING_DOPE_SHOW_HIDDEN;
|
2012-04-30 16:19:20 +00:00
|
|
|
|
2012-06-12 17:10:24 +00:00
|
|
|
if (dopesheet->ok)
|
2012-05-03 23:15:01 +00:00
|
|
|
return;
|
|
|
|
|
|
2012-05-03 17:52:34 +00:00
|
|
|
tracking_dopesheet_free(dopesheet);
|
2012-04-30 16:19:20 +00:00
|
|
|
|
2012-06-15 11:03:23 +00:00
|
|
|
reconstruction = BKE_tracking_object_get_reconstruction(tracking, object);
|
2012-06-12 17:11:00 +00:00
|
|
|
|
2013-02-22 10:13:15 +00:00
|
|
|
/* channels */
|
2012-04-30 16:19:20 +00:00
|
|
|
for (track = tracksbase->first; track; track = track->next) {
|
2012-06-12 17:10:47 +00:00
|
|
|
MovieTrackingDopesheetChannel *channel;
|
2012-04-30 16:19:20 +00:00
|
|
|
|
2012-06-12 17:10:47 +00:00
|
|
|
if (!show_hidden && (track->flag & TRACK_HIDDEN) != 0)
|
|
|
|
|
continue;
|
2012-04-30 16:19:20 +00:00
|
|
|
|
2012-06-12 17:10:47 +00:00
|
|
|
if (sel_only && !TRACK_SELECTED(track))
|
|
|
|
|
continue;
|
2012-04-30 16:19:20 +00:00
|
|
|
|
2012-06-12 17:10:47 +00:00
|
|
|
channel = MEM_callocN(sizeof(MovieTrackingDopesheetChannel), "tracking dopesheet channel");
|
|
|
|
|
channel->track = track;
|
|
|
|
|
|
2012-06-12 17:11:00 +00:00
|
|
|
if (reconstruction->flag & TRACKING_RECONSTRUCTED) {
|
|
|
|
|
BLI_snprintf(channel->name, sizeof(channel->name), "%s (%.4f)", track->name, track->error);
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
BLI_strncpy(channel->name, track->name, sizeof(channel->name));
|
|
|
|
|
}
|
|
|
|
|
|
2012-06-12 17:10:47 +00:00
|
|
|
channels_segments_calc(channel);
|
|
|
|
|
|
|
|
|
|
BLI_addtail(&dopesheet->channels, channel);
|
|
|
|
|
dopesheet->tot_channel++;
|
2012-04-30 16:19:20 +00:00
|
|
|
}
|
|
|
|
|
|
2012-05-03 23:15:01 +00:00
|
|
|
tracking_dopesheet_sort(tracking, sort_method, inverse);
|
2012-05-03 19:28:41 +00:00
|
|
|
|
2013-02-22 10:13:15 +00:00
|
|
|
/* frame coverage */
|
|
|
|
|
tracking_dopesheet_calc_coverage(tracking);
|
|
|
|
|
|
2012-05-03 23:15:01 +00:00
|
|
|
dopesheet->ok = TRUE;
|
2012-04-30 16:19:20 +00:00
|
|
|
}
|