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
This commit is contained in:
@@ -43,6 +43,7 @@
|
||||
|
||||
#include "BKE_colortools.h"
|
||||
#include "BKE_texture.h"
|
||||
#include "BKE_tracking.h"
|
||||
|
||||
|
||||
#include "IMB_imbuf.h"
|
||||
@@ -1507,36 +1508,10 @@ void ui_draw_but_CURVE(ARegion *ar, uiBut *but, uiWidgetColors *wcol, rcti *rect
|
||||
fdrawbox(rect->xmin, rect->ymin, rect->xmax, rect->ymax);
|
||||
}
|
||||
|
||||
static ImBuf *scale_trackpreview_ibuf(ImBuf *ibuf, float track_pos[2], int width, float height, int margin)
|
||||
{
|
||||
ImBuf *scaleibuf;
|
||||
const float scalex = ((float)ibuf->x - 2 * margin) / width;
|
||||
const float scaley = ((float)ibuf->y - 2 * margin) / height;
|
||||
/* NOTE: 1.0f = 0.5f for integer coordinate coorrection (center of pixel vs. left bottom corner of bixel)
|
||||
* and 0.5f for centering image in preview (cross is draving at exact center of widget so image
|
||||
* should be shifted by half of pixel for correct centering) - sergey */
|
||||
float off_x = (int)track_pos[0] - track_pos[0] + 1.0f;
|
||||
float off_y = (int)track_pos[1] - track_pos[1] + 1.0f;
|
||||
int x, y;
|
||||
|
||||
scaleibuf = IMB_allocImBuf(width, height, 32, IB_rect);
|
||||
|
||||
for (y = 0; y < height; y++) {
|
||||
for (x = 0; x < width; x++) {
|
||||
float src_x = scalex * (x) + margin - off_x;
|
||||
float src_y = scaley * (y) + margin - off_y;
|
||||
|
||||
bicubic_interpolation(ibuf, scaleibuf, src_x, src_y, x, y);
|
||||
}
|
||||
}
|
||||
|
||||
return scaleibuf;
|
||||
}
|
||||
|
||||
void ui_draw_but_TRACKPREVIEW(ARegion *ar, uiBut *but, uiWidgetColors *UNUSED(wcol), rcti *recti)
|
||||
{
|
||||
rctf rect;
|
||||
int ok = 0;
|
||||
int ok = 0, width, height;
|
||||
GLint scissor[4];
|
||||
MovieClipScopes *scopes = (MovieClipScopes *)but->poin;
|
||||
|
||||
@@ -1545,6 +1520,9 @@ void ui_draw_but_TRACKPREVIEW(ARegion *ar, uiBut *but, uiWidgetColors *UNUSED(wc
|
||||
rect.ymin = (float)recti->ymin + SCOPE_RESIZE_PAD + 2;
|
||||
rect.ymax = (float)recti->ymax - 1;
|
||||
|
||||
width = rect.xmax - rect.xmin + 1;
|
||||
height = rect.ymax - rect.ymin;
|
||||
|
||||
glEnable(GL_BLEND);
|
||||
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
|
||||
|
||||
@@ -1562,40 +1540,53 @@ void ui_draw_but_TRACKPREVIEW(ARegion *ar, uiBut *but, uiWidgetColors *UNUSED(wc
|
||||
|
||||
ok = 1;
|
||||
}
|
||||
else if (scopes->track_preview) {
|
||||
/* additional margin around image */
|
||||
/* NOTE: should be kept in sync with value from BKE_movieclip_update_scopes */
|
||||
const int margin = 3;
|
||||
float zoomx, zoomy, track_pos[2], off_x, off_y;
|
||||
int a, width, height;
|
||||
else if ((scopes->track_search) &&
|
||||
((!scopes->track_preview) ||
|
||||
(scopes->track_preview->x != width || scopes->track_preview->y != height)))
|
||||
{
|
||||
ImBuf *tmpibuf;
|
||||
|
||||
if (scopes->track_preview)
|
||||
IMB_freeImBuf(scopes->track_preview);
|
||||
|
||||
tmpibuf = BKE_tracking_sample_pattern_imbuf(scopes->frame_width, scopes->frame_height,
|
||||
scopes->track_search, &scopes->undist_marker,
|
||||
width, height, scopes->track_pos);
|
||||
|
||||
if (tmpibuf->rect_float)
|
||||
IMB_rect_from_float(tmpibuf);
|
||||
|
||||
// XXX: for debug only
|
||||
// tmpibuf->ftype = PNG;
|
||||
// IMB_saveiff(tmpibuf, "sample.png", IB_rect);
|
||||
|
||||
if (tmpibuf->rect)
|
||||
scopes->track_preview = tmpibuf;
|
||||
else
|
||||
IMB_freeImBuf(tmpibuf);
|
||||
}
|
||||
|
||||
if (!ok && scopes->track_preview) {
|
||||
float track_pos[2];
|
||||
int a;
|
||||
ImBuf *drawibuf;
|
||||
|
||||
glPushMatrix();
|
||||
|
||||
track_pos[0] = scopes->track_pos[0] - margin;
|
||||
track_pos[1] = scopes->track_pos[1] - margin;
|
||||
track_pos[0] = scopes->track_pos[0];
|
||||
track_pos[1] = scopes->track_pos[1];
|
||||
|
||||
/* draw content of pattern area */
|
||||
glScissor(ar->winrct.xmin + rect.xmin, ar->winrct.ymin + rect.ymin, scissor[2], scissor[3]);
|
||||
|
||||
width = rect.xmax - rect.xmin + 1;
|
||||
height = rect.ymax - rect.ymin;
|
||||
|
||||
if (width > 0 && height > 0) {
|
||||
zoomx = (float)width / (scopes->track_preview->x - 2 * margin);
|
||||
zoomy = (float)height / (scopes->track_preview->y - 2 * margin);
|
||||
|
||||
off_x = ((int)track_pos[0] - track_pos[0] + 0.5f) * zoomx;
|
||||
off_y = ((int)track_pos[1] - track_pos[1] + 0.5f) * zoomy;
|
||||
|
||||
drawibuf = scale_trackpreview_ibuf(scopes->track_preview, track_pos, width, height, margin);
|
||||
drawibuf = scopes->track_preview;
|
||||
|
||||
glaDrawPixelsSafe(rect.xmin, rect.ymin + 1, drawibuf->x, drawibuf->y,
|
||||
drawibuf->x, GL_RGBA, GL_UNSIGNED_BYTE, drawibuf->rect);
|
||||
IMB_freeImBuf(drawibuf);
|
||||
|
||||
/* draw cross for pizel position */
|
||||
glTranslatef(off_x + rect.xmin + track_pos[0] * zoomx, off_y + rect.ymin + track_pos[1] * zoomy, 0.f);
|
||||
glTranslatef(rect.xmin + track_pos[0], rect.ymin + track_pos[1], 0.f);
|
||||
glScissor(ar->winrct.xmin + rect.xmin,
|
||||
ar->winrct.ymin + rect.ymin,
|
||||
rect.xmax - rect.xmin,
|
||||
|
||||
Reference in New Issue
Block a user