Blender V4.3
pyramid_region_tracker_test.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#include "libmv/image/image.h"
24#include "testing/testing.h"
25
26namespace libmv {
27namespace {
28
29TEST(PyramidKltRegionTracker, Track) {
30 Array3Df image1(100, 100);
31 image1.Fill(0);
32
33 Array3Df image2(image1);
34
35 int x1 = 25, y1 = 25;
36 image1(y1 + 0, x1 + 0) = 1.0f;
37 image1(y1 + 0, x1 + 1) = 1.0f;
38 image1(y1 + 1, x1 + 0) = 1.0f;
39 image1(y1 + 1, x1 + 1) = 1.0f;
40
41 // Make the displacement too large for a single-level KLT.
42 int x2 = x1 + 6, y2 = y1 + 5;
43 image2(y2 + 0, x2 + 0) = 1.0f;
44 image2(y2 + 0, x2 + 1) = 1.0f;
45 image2(y2 + 1, x2 + 0) = 1.0f;
46 image2(y2 + 1, x2 + 1) = 1.0f;
47
48 // Use a small 5x5 tracking region.
49 int half_window_size = 3;
50
51 // Ensure that the track doesn't work with one level of KLT.
52 {
53 double x2_actual = x1;
54 double y2_actual = y1;
55
56 KltRegionTracker tracker;
57 tracker.half_window_size = half_window_size;
58 EXPECT_FALSE(tracker.Track(image1, image2, x1, y1, &x2_actual, &y2_actual));
59 }
60
61 // Verify that it works with the pyramid tracker.
62 {
63 double x2_actual = x1;
64 double y2_actual = y1;
65
66 KltRegionTracker* klt_tracker = new KltRegionTracker;
67 klt_tracker->half_window_size = half_window_size;
68
69 PyramidRegionTracker tracker(klt_tracker, 3);
70 EXPECT_TRUE(tracker.Track(image1, image2, x1, y1, &x2_actual, &y2_actual));
71
72 EXPECT_NEAR(x2_actual, x2, 0.001);
73 EXPECT_NEAR(y2_actual, y2, 0.001);
74 }
75}
76
77} // namespace
78} // namespace libmv
TEST(PolynomialCameraIntrinsics2, ApplyOnFocalCenter)
Array3D< float > Array3Df
Definition array_nd.h:373