Blender V4.3
libmv/tracking/track_region.h
Go to the documentation of this file.
1// Copyright (c) 2012 libmv authors.
2//
3// Permission is hereby granted, free of charge, to any person obtaining a copy
4// of this software and associated documentation files (the "Software"), to
5// deal in the Software without restriction, including without limitation the
6// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
7// sell copies of the Software, and to permit persons to whom the Software is
8// furnished to do so, subject to the following conditions:
9//
10// The above copyright notice and this permission notice shall be included in
11// all copies or substantial portions of the Software.
12//
13// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
18// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
19// IN THE SOFTWARE.
20
21#ifndef LIBMV_TRACKING_TRACK_REGION_H_
22#define LIBMV_TRACKING_TRACK_REGION_H_
23
24#include "libmv/image/image.h"
25#include "libmv/image/sample.h"
27
28namespace libmv {
29
32
38
48
49 // Minimum normalized cross-correlation necessary between the final tracked
50 // position of the patch on the destination image and the reference patch
51 // needed to declare tracking success. If the minimum correlation is not met,
52 // then TrackResult::termination is INSUFFICIENT_CORRELATION.
54
55 // Maximum number of Ceres iterations to run for the inner minimization.
57
58 // Use the "Efficient Second-order Minimization" scheme. This increases
59 // convergence speed at the cost of more per-iteration work.
60 bool use_esm;
61
62 // If true, apply a brute-force translation-only search before attempting the
63 // full search. This is not enabled if the destination image ("image2") is
64 // too small; in that case either the basin of attraction is close enough
65 // that the nearby minima is correct, or the search area is too small.
67
68 // If true and brute initialization is enabled, first try refining with the
69 // initial guess instead of starting with the brute initialization. If the
70 // initial refinement fails, then a normal brute search followed by
71 // refinement is attempted. If the initial refinement succeeds, then the
72 // result is returned as is (skipping a costly brute search).
74
75 // If true, normalize the image patches by their mean before doing the sum of
76 // squared error calculation. This is reasonable since the effect of
77 // increasing light intensity is multiplicative on the pixel intensities.
78 //
79 // Note: This does nearly double the solving time, so it is not advised to
80 // turn this on all the time.
82
83 // The size in pixels of the blur kernel used to both smooth the image and
84 // take the image derivative.
85 double sigma;
86
87 // Extra points that should get transformed by the warp. These points are
88 // appended to the x and y arrays. This is useful because the actual warp
89 // parameters are not exposed.
91
92 // For motion models other than translation, the optimizer sometimes has
93 // trouble deciding what to do around flat areas in the cost function. This
94 // leads to the optimizer picking poor solutions near the minimum. Visually,
95 // the effect is that the quad corners jiggle around, even though the center
96 // of the patch is well estimated. regularization_coefficient controls a term
97 // in the sum of squared error cost that makes it expensive for the optimizer
98 // to pick a warp that changes the shape of the patch dramatically (e.g.
99 // rotating, scaling, skewing, etc).
100 //
101 // In particular it adds an 8-residual cost function to the optimization,
102 // where each corner induces 2 residuals: the difference between the warped
103 // and the initial guess. However, the patch centroids are subtracted so that
104 // only patch distortions are penalized.
105 //
106 // If zero, no regularization is used.
108
109 // If the maximum shift of any patch corner between successful iterations of
110 // the solver is less than this amount, then the tracking is declared
111 // successful. The solver termination becomes PARAMETER_TOLERANCE.
113
114 // If non-null, this is used as the pattern mask. It should match the size of
115 // image1, even though only values inside the image1 quad are examined. The
116 // values must be in the range 0.0 to 0.1.
118};
119
147
148// Always needs 4 correspondences.
149void TrackRegion(const FloatImage& image1,
150 const FloatImage& image2,
151 const double* x1,
152 const double* y1,
154 double* x2,
155 double* y2,
156 TrackRegionResult* result);
157
158// Sample a "canonical" version of the passed planar patch, using bilinear
159// sampling. The passed corners must be within the image, and have at least two
160// pixels of border around them. (so e.g. a corner of the patch cannot lie
161// directly on the edge of the image). Four corners are always required. All
162// channels are interpolated.
163// When mask is not null it'll be used as a pattern mask. Ot should match
164// the size of image.
165// Warped coordinates of marker's position would be returned in
166// warped_position_x and warped_position_y
167bool SamplePlanarPatch(const FloatImage& image,
168 const double* xs,
169 const double* ys,
170 int num_samples_x,
171 int num_samples_y,
172 FloatImage* mask,
173 FloatImage* patch,
174 double* warped_position_x,
175 double* warped_position_y);
176
177} // namespace libmv
178
179#endif // LIBMV_TRACKING_TRACK_REGION_H_
3D array (row, column, channel).
Definition array_nd.h:332
CCL_NAMESPACE_BEGIN struct Options options
void TrackRegion(const FloatImage &image1, const FloatImage &image2, const double *x1, const double *y1, const TrackRegionOptions &options, double *x2, double *y2, TrackRegionResult *result)
bool SamplePlanarPatch(const FloatImage &image, const double *xs, const double *ys, int num_samples_x, int num_samples_y, FloatImage *mask, FloatImage *patch, double *warped_position_x, double *warped_position_y)