ACloudViewer  3.9.4
A Modern Library for 3D Data Processing
utils_test.cc
Go to the documentation of this file.
1 // Copyright (c) 2018, ETH Zurich and UNC Chapel Hill.
2 // All rights reserved.
3 //
4 // Redistribution and use in source and binary forms, with or without
5 // modification, are permitted provided that the following conditions are met:
6 //
7 // * Redistributions of source code must retain the above copyright
8 // notice, this list of conditions and the following disclaimer.
9 //
10 // * Redistributions in binary form must reproduce the above copyright
11 // notice, this list of conditions and the following disclaimer in the
12 // documentation and/or other materials provided with the distribution.
13 //
14 // * Neither the name of ETH Zurich and UNC Chapel Hill nor the names of
15 // its contributors may be used to endorse or promote products derived
16 // from this software without specific prior written permission.
17 //
18 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
19 // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21 // ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE
22 // LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
23 // CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
24 // SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
25 // INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
26 // CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
27 // ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
28 // POSSIBILITY OF SUCH DAMAGE.
29 //
30 // Author: Johannes L. Schoenberger (jsch-at-demuc-dot-de)
31 
32 #define TEST_NAME "feature/utils"
33 #include "util/testing.h"
34 
35 #include "feature/utils.h"
36 
37 using namespace colmap;
38 
39 BOOST_AUTO_TEST_CASE(TestFeatureKeypointsToPointsVector) {
40  FeatureKeypoints keypoints(2);
41  keypoints[1].x = 0.1;
42  keypoints[1].y = 0.2;
43  const std::vector<Eigen::Vector2d> points =
45  BOOST_CHECK_EQUAL(points[0], Eigen::Vector2d(0, 0));
46  BOOST_CHECK_EQUAL(points[1].cast<float>(), Eigen::Vector2f(0.1, 0.2));
47 }
48 
49 BOOST_AUTO_TEST_CASE(TestL2NormalizeFeatureDescriptors) {
50  Eigen::MatrixXf descriptors = Eigen::MatrixXf::Random(100, 128);
51  descriptors.array() += 1.0f;
52  const Eigen::MatrixXf descriptors_normalized =
54  for (Eigen::MatrixXf::Index r = 0; r < descriptors.rows(); ++r) {
55  BOOST_CHECK(std::abs(descriptors_normalized.row(r).norm() - 1.0f) < 1e-6);
56  }
57 }
58 
59 BOOST_AUTO_TEST_CASE(TestL1RootNormalizeFeatureDescriptors) {
60  Eigen::MatrixXf descriptors = Eigen::MatrixXf::Random(100, 128);
61  descriptors.array() += 1.0f;
62  const Eigen::MatrixXf descriptors_normalized =
64  for (Eigen::MatrixXf::Index r = 0; r < descriptors.rows(); ++r) {
65  BOOST_CHECK(std::abs(descriptors_normalized.row(r).norm() - 1.0f) < 1e-6);
66  }
67 }
68 
69 BOOST_AUTO_TEST_CASE(TestFeatureDescriptorsToUnsignedByte) {
70  Eigen::MatrixXf descriptors = Eigen::MatrixXf::Random(100, 128);
71  descriptors.array() += 1.0f;
72  const FeatureDescriptors descriptors_uint8 =
74  for (Eigen::MatrixXf::Index r = 0; r < descriptors.rows(); ++r) {
75  for (Eigen::MatrixXf::Index c = 0; c < descriptors.cols(); ++c) {
76  BOOST_CHECK_EQUAL(static_cast<uint8_t>(std::min(
77  255.0f, std::round(512.0f * descriptors(r, c)))),
78  descriptors_uint8(r, c));
79  }
80  }
81 }
82 
83 BOOST_AUTO_TEST_CASE(TestExtractTopScaleFeatures) {
84  FeatureKeypoints keypoints(5);
85  keypoints[0].Rescale(3);
86  keypoints[1].Rescale(4);
87  keypoints[2].Rescale(1);
88  keypoints[3].Rescale(5);
89  keypoints[4].Rescale(2);
90  const FeatureDescriptors descriptors = FeatureDescriptors::Random(5, 128);
91 
92  auto top_keypoints2 = keypoints;
93  auto top_descriptors2 = descriptors;
94  ExtractTopScaleFeatures(&top_keypoints2, &top_descriptors2, 2);
95  BOOST_CHECK_EQUAL(top_keypoints2.size(), 2);
96  BOOST_CHECK_EQUAL(top_keypoints2[0].ComputeScale(),
97  keypoints[3].ComputeScale());
98  BOOST_CHECK_EQUAL(top_keypoints2[1].ComputeScale(),
99  keypoints[1].ComputeScale());
100  BOOST_CHECK_EQUAL(top_descriptors2.rows(), 2);
101  BOOST_CHECK_EQUAL(top_descriptors2.row(0), descriptors.row(3));
102  BOOST_CHECK_EQUAL(top_descriptors2.row(1), descriptors.row(1));
103 
104  auto top_keypoints5 = keypoints;
105  auto top_descriptors5 = descriptors;
106  ExtractTopScaleFeatures(&top_keypoints5, &top_descriptors5, 5);
107  BOOST_CHECK_EQUAL(top_keypoints5.size(), 5);
108  BOOST_CHECK_EQUAL(top_descriptors5.rows(), 5);
109  BOOST_CHECK_EQUAL(top_descriptors5, descriptors);
110 
111  auto top_keypoints6 = keypoints;
112  auto top_descriptors6 = descriptors;
113  ExtractTopScaleFeatures(&top_keypoints6, &top_descriptors6, 6);
114  BOOST_CHECK_EQUAL(top_keypoints5.size(), 5);
115  BOOST_CHECK_EQUAL(top_descriptors6.rows(), 5);
116  BOOST_CHECK_EQUAL(top_descriptors6, descriptors);
117 }
int points
const double * e
BOOST_AUTO_TEST_CASE(TestCenterAndNormalizeImagePoints)
Definition: utils_test.cc:40
Eigen::MatrixXf L1RootNormalizeFeatureDescriptors(const Eigen::MatrixXf &descriptors)
Definition: utils.cc:52
void ExtractTopScaleFeatures(FeatureKeypoints *keypoints, FeatureDescriptors *descriptors, const size_t num_features)
Definition: utils.cc:79
Eigen::Matrix< uint8_t, Eigen::Dynamic, Eigen::Dynamic, Eigen::RowMajor > FeatureDescriptors
Definition: types.h:79
FeatureDescriptors FeatureDescriptorsToUnsignedByte(const Eigen::MatrixXf &descriptors)
Definition: utils.cc:65
Eigen::MatrixXf L2NormalizeFeatureDescriptors(const Eigen::MatrixXf &descriptors)
Definition: utils.cc:47
std::vector< Eigen::Vector2d > FeatureKeypointsToPointsVector(const FeatureKeypoints &keypoints)
Definition: utils.cc:38
std::vector< FeatureKeypoint > FeatureKeypoints
Definition: types.h:77
Eigen::MatrixXd::Index Index
Definition: knncpp.h:26
CorePointDescSet * descriptors