Blender V4.3
hybrid_region_tracker.cc
Go to the documentation of this file.
1// Copyright (c) 2011 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
22
24#include "libmv/image/image.h"
25#include "libmv/image/sample.h"
27
28namespace libmv {
29
31 const FloatImage& image2,
32 double x1,
33 double y1,
34 double* x2,
35 double* y2) const {
36 double x2_coarse = *x2;
37 double y2_coarse = *y2;
38 if (!coarse_tracker_->Track(image1, image2, x1, y1, &x2_coarse, &y2_coarse)) {
39 LG << "Coarse tracker failed.";
40 return false;
41 }
42
43 double x2_fine = x2_coarse;
44 double y2_fine = y2_coarse;
45 if (!fine_tracker_->Track(image1, image2, x1, y1, &x2_fine, &y2_fine)) {
46 LG << "Fine tracker failed.";
47 return false;
48 }
49
50 // Calculate the shift done by the fine tracker.
51 double dx2 = x2_coarse - x2_fine;
52 double dy2 = y2_coarse - y2_fine;
53 double fine_shift = sqrt(dx2 * dx2 + dy2 * dy2);
54
55 LG << "Refinement: dx=" << dx2 << " dy=" << dy2 << ", d=" << fine_shift;
56
57 // If the fine tracker shifted the window by more than a pixel, then
58 // something bad probably happened and we should give up tracking.
59 if (fine_shift < 2.0) {
60 LG << "Refinement small enough; success.";
61 *x2 = x2_fine;
62 *y2 = y2_fine;
63 return true;
64 }
65 LG << "Refinement was too big; failing.";
66 return false;
67}
68
69} // namespace libmv
sqrt(x)+1/max(0
3D array (row, column, channel).
Definition array_nd.h:332
virtual bool Track(const FloatImage &image1, const FloatImage &image2, double x1, double y1, double *x2, double *y2) const
scoped_ptr< RegionTracker > fine_tracker_
scoped_ptr< RegionTracker > coarse_tracker_
#define LG