32 #define TEST_NAME "feature/sift_test"
36 #include <QApplication>
41 #include "SiftGPU/SiftGPU.h"
69 BOOST_CHECK_EQUAL(keypoints.size(), 22);
70 for (
size_t i = 0; i < keypoints.size(); ++i) {
71 BOOST_CHECK_GE(keypoints[i].
x, 0);
72 BOOST_CHECK_GE(keypoints[i].
y, 0);
73 BOOST_CHECK_LE(keypoints[i].
x, bitmap.
Width());
74 BOOST_CHECK_LE(keypoints[i].
y, bitmap.
Height());
75 BOOST_CHECK_GT(keypoints[i].ComputeScale(), 0);
76 BOOST_CHECK_GT(keypoints[i].ComputeOrientation(), -
M_PI);
77 BOOST_CHECK_LT(keypoints[i].ComputeOrientation(),
M_PI);
82 BOOST_CHECK_LT(std::abs(
descriptors.row(i).cast<
float>().norm() - 512), 1);
95 BOOST_CHECK_EQUAL(keypoints.size(), 22);
96 for (
size_t i = 0; i < keypoints.size(); ++i) {
97 BOOST_CHECK_GE(keypoints[i].
x, 0);
98 BOOST_CHECK_GE(keypoints[i].
y, 0);
99 BOOST_CHECK_LE(keypoints[i].
x, bitmap.
Width());
100 BOOST_CHECK_LE(keypoints[i].
y, bitmap.
Height());
101 BOOST_CHECK_GT(keypoints[i].ComputeScale(), 0);
102 BOOST_CHECK_GT(keypoints[i].ComputeOrientation(), -
M_PI);
103 BOOST_CHECK_LT(keypoints[i].ComputeOrientation(),
M_PI);
108 BOOST_CHECK_LT(std::abs(
descriptors.row(i).cast<
float>().norm() - 512), 1);
123 BOOST_CHECK_EQUAL(keypoints.size(), 10);
124 for (
size_t i = 0; i < keypoints.size(); ++i) {
125 BOOST_CHECK_GE(keypoints[i].
x, 0);
126 BOOST_CHECK_GE(keypoints[i].
y, 0);
127 BOOST_CHECK_LE(keypoints[i].
x, bitmap.
Width());
128 BOOST_CHECK_LE(keypoints[i].
y, bitmap.
Height());
129 BOOST_CHECK_GT(keypoints[i].ComputeScale(), 0);
130 BOOST_CHECK_GT(keypoints[i].ComputeOrientation(), -
M_PI);
131 BOOST_CHECK_LT(keypoints[i].ComputeOrientation(),
M_PI);
136 BOOST_CHECK_LT(std::abs(
descriptors.row(i).cast<
float>().norm() - 512), 1);
151 BOOST_CHECK_EQUAL(keypoints.size(), 22);
152 for (
size_t i = 0; i < keypoints.size(); ++i) {
153 BOOST_CHECK_GE(keypoints[i].
x, 0);
154 BOOST_CHECK_GE(keypoints[i].
y, 0);
155 BOOST_CHECK_LE(keypoints[i].
x, bitmap.
Width());
156 BOOST_CHECK_LE(keypoints[i].
y, bitmap.
Height());
157 BOOST_CHECK_GT(keypoints[i].ComputeScale(), 0);
158 BOOST_CHECK_GT(keypoints[i].ComputeOrientation(), -
M_PI);
159 BOOST_CHECK_LT(keypoints[i].ComputeOrientation(),
M_PI);
164 BOOST_CHECK_LT(std::abs(
descriptors.row(i).cast<
float>().norm() - 512), 1);
180 BOOST_CHECK_EQUAL(keypoints.size(), 10);
181 for (
size_t i = 0; i < keypoints.size(); ++i) {
182 BOOST_CHECK_GE(keypoints[i].
x, 0);
183 BOOST_CHECK_GE(keypoints[i].
y, 0);
184 BOOST_CHECK_LE(keypoints[i].
x, bitmap.
Width());
185 BOOST_CHECK_LE(keypoints[i].
y, bitmap.
Height());
186 BOOST_CHECK_GT(keypoints[i].ComputeScale(), 0);
187 BOOST_CHECK_GT(keypoints[i].ComputeOrientation(), -
M_PI);
188 BOOST_CHECK_LT(keypoints[i].ComputeOrientation(),
M_PI);
193 BOOST_CHECK_LT(std::abs(
descriptors.row(i).cast<
float>().norm() - 512), 1);
198 char app_name[] =
"Test";
200 char* argv[] = {app_name};
207 class TestThread :
public Thread {
210 opengl_context_.MakeCurrent();
223 BOOST_CHECK_EQUAL(keypoints.size(), 24);
224 for (
size_t i = 0; i < keypoints.size(); ++i) {
225 BOOST_CHECK_GE(keypoints[i].
x, 0);
226 BOOST_CHECK_GE(keypoints[i].
y, 0);
227 BOOST_CHECK_LE(keypoints[i].
x, bitmap.
Width());
228 BOOST_CHECK_LE(keypoints[i].
y, bitmap.
Height());
229 BOOST_CHECK_GT(keypoints[i].ComputeScale(), 0);
230 BOOST_CHECK_GT(keypoints[i].ComputeOrientation(), -
M_PI);
231 BOOST_CHECK_LT(keypoints[i].ComputeOrientation(),
M_PI);
236 BOOST_CHECK_LT(std::abs(
descriptors.row(i).cast<
float>().norm() - 512),
250 for (
size_t i = 0; i < num_features; ++i) {
251 for (
size_t j = 0; j < 128; ++j) {
261 BOOST_REQUIRE_EQUAL(matches1.size(), matches2.size());
262 for (
size_t i = 0; i < matches1.size(); ++i) {
263 BOOST_CHECK_EQUAL(matches1[i].point2D_idx1, matches2[i].point2D_idx1);
264 BOOST_CHECK_EQUAL(matches1[i].point2D_idx2, matches2[i].point2D_idx2);
269 char app_name[] =
"Test";
271 char* argv[] = {app_name};
278 class TestThread :
public Thread {
281 opengl_context_.MakeCurrent();
282 SiftMatchGPU sift_match_gpu;
296 SiftMatchGPU sift_match_gpu;
314 BOOST_CHECK_EQUAL(matches.size(), 2);
315 BOOST_CHECK_EQUAL(matches[0].point2D_idx1, 0);
316 BOOST_CHECK_EQUAL(matches[0].point2D_idx2, 1);
317 BOOST_CHECK_EQUAL(matches[1].point2D_idx1, 1);
318 BOOST_CHECK_EQUAL(matches[1].point2D_idx2, 0);
322 BOOST_CHECK_EQUAL(matches.size(), 0);
325 BOOST_CHECK_EQUAL(matches.size(), 0);
327 empty_descriptors, &matches);
328 BOOST_CHECK_EQUAL(matches.size(), 0);
347 const size_t num_matches = matches_bf.size();
365 empty_descriptors, &matches_bf);
377 TestFLANNvsBruteForce(match_options, descriptors1, descriptors2);
384 const size_t num_matches =
385 TestFLANNvsBruteForce(match_options, descriptors1, descriptors2);
386 BOOST_CHECK_EQUAL(num_matches, 100);
395 const size_t num_matches1 =
396 TestFLANNvsBruteForce(match_options, descriptors1, descriptors2);
397 BOOST_CHECK_EQUAL(num_matches1, 100);
399 descriptors2.row(99) = descriptors2.row(0);
400 descriptors2(0, 0) += 50.0f;
403 descriptors2(99, 0) += 100.0f;
408 const size_t num_matches2 = TestFLANNvsBruteForce(
409 match_options, descriptors1.topRows(99), descriptors2);
410 BOOST_CHECK_EQUAL(num_matches2, 98);
413 const size_t num_matches3 =
414 TestFLANNvsBruteForce(match_options, descriptors1, descriptors2);
415 BOOST_CHECK_EQUAL(num_matches3, 99);
422 descriptors1.row(0) = descriptors1.row(1);
427 const size_t num_matches1 =
428 TestFLANNvsBruteForce(match_options, descriptors1, descriptors2);
429 BOOST_CHECK_EQUAL(num_matches1, 100);
432 const size_t num_matches2 =
433 TestFLANNvsBruteForce(match_options, descriptors1, descriptors2);
434 BOOST_CHECK_EQUAL(num_matches2, 98);
453 two_view_geometry.
H = Eigen::Matrix3d::Identity();
456 descriptors1, descriptors2, &two_view_geometry);
458 BOOST_CHECK_EQUAL(two_view_geometry.
inlier_matches[0].point2D_idx1, 0);
459 BOOST_CHECK_EQUAL(two_view_geometry.
inlier_matches[0].point2D_idx2, 1);
460 BOOST_CHECK_EQUAL(two_view_geometry.
inlier_matches[1].point2D_idx1, 1);
461 BOOST_CHECK_EQUAL(two_view_geometry.
inlier_matches[1].point2D_idx2, 0);
463 keypoints1[0].x = 100;
465 descriptors1, descriptors2, &two_view_geometry);
467 BOOST_CHECK_EQUAL(two_view_geometry.
inlier_matches[0].point2D_idx1, 1);
468 BOOST_CHECK_EQUAL(two_view_geometry.
inlier_matches[0].point2D_idx2, 0);
471 empty_descriptors, descriptors2,
475 descriptors1, empty_descriptors,
479 empty_keypoints, empty_descriptors,
480 empty_descriptors, &two_view_geometry);
485 char app_name[] =
"Test";
487 char* argv[] = {app_name};
494 class TestThread :
public Thread {
497 opengl_context_.MakeCurrent();
498 SiftMatchGPU sift_match_gpu;
511 &sift_match_gpu, &matches);
512 BOOST_CHECK_EQUAL(matches.size(), 2);
513 BOOST_CHECK_EQUAL(matches[0].point2D_idx1, 0);
514 BOOST_CHECK_EQUAL(matches[0].point2D_idx2, 1);
515 BOOST_CHECK_EQUAL(matches[1].point2D_idx1, 1);
516 BOOST_CHECK_EQUAL(matches[1].point2D_idx2, 0);
519 &sift_match_gpu, &matches);
520 BOOST_CHECK_EQUAL(matches.size(), 2);
521 BOOST_CHECK_EQUAL(matches[0].point2D_idx1, 0);
522 BOOST_CHECK_EQUAL(matches[0].point2D_idx2, 1);
523 BOOST_CHECK_EQUAL(matches[1].point2D_idx1, 1);
524 BOOST_CHECK_EQUAL(matches[1].point2D_idx2, 0);
527 &sift_match_gpu, &matches);
528 BOOST_CHECK_EQUAL(matches.size(), 2);
529 BOOST_CHECK_EQUAL(matches[0].point2D_idx1, 0);
530 BOOST_CHECK_EQUAL(matches[0].point2D_idx2, 1);
531 BOOST_CHECK_EQUAL(matches[1].point2D_idx1, 1);
532 BOOST_CHECK_EQUAL(matches[1].point2D_idx2, 0);
535 &sift_match_gpu, &matches);
536 BOOST_CHECK_EQUAL(matches.size(), 2);
537 BOOST_CHECK_EQUAL(matches[0].point2D_idx1, 0);
538 BOOST_CHECK_EQUAL(matches[0].point2D_idx2, 1);
539 BOOST_CHECK_EQUAL(matches[1].point2D_idx1, 1);
540 BOOST_CHECK_EQUAL(matches[1].point2D_idx2, 0);
543 &descriptors2, &sift_match_gpu, &matches);
544 BOOST_CHECK_EQUAL(matches.size(), 0);
546 &empty_descriptors, &sift_match_gpu, &matches);
547 BOOST_CHECK_EQUAL(matches.size(), 0);
549 &empty_descriptors, &sift_match_gpu, &matches);
550 BOOST_CHECK_EQUAL(matches.size(), 0);
560 char app_name[] =
"Test";
562 char* argv[] = {app_name};
569 class TestThread :
public Thread {
572 opengl_context_.MakeCurrent();
573 SiftMatchGPU sift_match_gpu;
578 auto TestCPUvsGPU = [&sift_match_gpu](
587 &sift_match_gpu, &matches_gpu);
590 const size_t num_matches = matches_cpu.size();
598 &sift_match_gpu, &matches_gpu);
604 &sift_match_gpu, &matches_gpu);
610 &sift_match_gpu, &matches_gpu);
622 TestCPUvsGPU(match_options, descriptors1, descriptors2);
629 descriptors1.colwise().reverse();
631 const size_t num_matches =
632 TestCPUvsGPU(match_options, descriptors1, descriptors2);
633 BOOST_CHECK_EQUAL(num_matches, 100);
642 const size_t num_matches1 =
643 TestCPUvsGPU(match_options, descriptors1, descriptors2);
644 BOOST_CHECK_EQUAL(num_matches1, 100);
646 descriptors2.row(99) = descriptors2.row(0);
647 descriptors2(0, 0) += 50.0f;
650 descriptors2(99, 0) += 100.0f;
655 const size_t num_matches2 =
656 TestCPUvsGPU(match_options, descriptors1.topRows(99), descriptors2);
657 BOOST_CHECK_EQUAL(num_matches2, 98);
660 const size_t num_matches3 =
661 TestCPUvsGPU(match_options, descriptors1, descriptors2);
662 BOOST_CHECK_EQUAL(num_matches3, 99);
669 descriptors1.row(0) = descriptors1.row(1);
674 const size_t num_matches1 =
675 TestCPUvsGPU(match_options, descriptors1, descriptors2);
676 BOOST_CHECK_EQUAL(num_matches1, 100);
679 const size_t num_matches2 =
680 TestCPUvsGPU(match_options, descriptors1, descriptors2);
681 BOOST_CHECK_EQUAL(num_matches2, 98);
692 char app_name[] =
"Test";
694 char* argv[] = {app_name};
701 class TestThread :
public Thread {
704 opengl_context_.MakeCurrent();
705 SiftMatchGPU sift_match_gpu;
724 two_view_geometry.
H = Eigen::Matrix3d::Identity();
727 &keypoints2, &descriptors1, &descriptors2,
728 &sift_match_gpu, &two_view_geometry);
730 BOOST_CHECK_EQUAL(two_view_geometry.
inlier_matches[0].point2D_idx1, 0);
731 BOOST_CHECK_EQUAL(two_view_geometry.
inlier_matches[0].point2D_idx2, 1);
732 BOOST_CHECK_EQUAL(two_view_geometry.
inlier_matches[1].point2D_idx1, 1);
733 BOOST_CHECK_EQUAL(two_view_geometry.
inlier_matches[1].point2D_idx2, 0);
736 nullptr,
nullptr, &sift_match_gpu,
739 BOOST_CHECK_EQUAL(two_view_geometry.
inlier_matches[0].point2D_idx1, 0);
740 BOOST_CHECK_EQUAL(two_view_geometry.
inlier_matches[0].point2D_idx2, 1);
741 BOOST_CHECK_EQUAL(two_view_geometry.
inlier_matches[1].point2D_idx1, 1);
742 BOOST_CHECK_EQUAL(two_view_geometry.
inlier_matches[1].point2D_idx2, 0);
745 &descriptors1,
nullptr, &sift_match_gpu,
748 BOOST_CHECK_EQUAL(two_view_geometry.
inlier_matches[0].point2D_idx1, 0);
749 BOOST_CHECK_EQUAL(two_view_geometry.
inlier_matches[0].point2D_idx2, 1);
750 BOOST_CHECK_EQUAL(two_view_geometry.
inlier_matches[1].point2D_idx1, 1);
751 BOOST_CHECK_EQUAL(two_view_geometry.
inlier_matches[1].point2D_idx2, 0);
754 nullptr, &descriptors2, &sift_match_gpu,
757 BOOST_CHECK_EQUAL(two_view_geometry.
inlier_matches[0].point2D_idx1, 0);
758 BOOST_CHECK_EQUAL(two_view_geometry.
inlier_matches[0].point2D_idx2, 1);
759 BOOST_CHECK_EQUAL(two_view_geometry.
inlier_matches[1].point2D_idx1, 1);
760 BOOST_CHECK_EQUAL(two_view_geometry.
inlier_matches[1].point2D_idx2, 0);
762 keypoints1[0].x = 100;
764 &keypoints2, &descriptors1, &descriptors2,
765 &sift_match_gpu, &two_view_geometry);
767 BOOST_CHECK_EQUAL(two_view_geometry.
inlier_matches[0].point2D_idx1, 1);
768 BOOST_CHECK_EQUAL(two_view_geometry.
inlier_matches[0].point2D_idx2, 0);
771 &keypoints2, &empty_descriptors, &descriptors2,
772 &sift_match_gpu, &two_view_geometry);
776 &empty_descriptors, &sift_match_gpu, &two_view_geometry);
779 &empty_keypoints, &empty_descriptors,
780 &empty_descriptors, &sift_match_gpu,
int Run(int argc, const char *argv[])
bool SetPixel(const int x, const int y, const BitmapColor< uint8_t > &color)
void Fill(const BitmapColor< uint8_t > &color)
bool Allocate(const int width, const int height, const bool as_rgb)
void SetPRNGSeed(unsigned seed)
bool ExtractCovariantSiftFeaturesCPU(const SiftExtractionOptions &options, const Bitmap &bitmap, FeatureKeypoints *keypoints, FeatureDescriptors *descriptors)
void MatchGuidedSiftFeaturesGPU(const SiftMatchingOptions &match_options, const FeatureKeypoints *keypoints1, const FeatureKeypoints *keypoints2, const FeatureDescriptors *descriptors1, const FeatureDescriptors *descriptors2, SiftMatchGPU *sift_match_gpu, TwoViewGeometry *two_view_geometry)
bool CreateSiftGPUExtractor(const SiftExtractionOptions &options, SiftGPU *sift_gpu)
void RunThreadWithOpenGLContext(Thread *thread)
void MatchSiftFeaturesGPU(const SiftMatchingOptions &match_options, const FeatureDescriptors *descriptors1, const FeatureDescriptors *descriptors2, SiftMatchGPU *sift_match_gpu, FeatureMatches *matches)
bool CreateSiftGPUMatcher(const SiftMatchingOptions &match_options, SiftMatchGPU *sift_match_gpu)
Eigen::Matrix< uint8_t, Eigen::Dynamic, Eigen::Dynamic, Eigen::RowMajor > FeatureDescriptors
FeatureDescriptors FeatureDescriptorsToUnsignedByte(const Eigen::MatrixXf &descriptors)
Eigen::MatrixXf L2NormalizeFeatureDescriptors(const Eigen::MatrixXf &descriptors)
void MatchSiftFeaturesCPUBruteForce(const SiftMatchingOptions &match_options, const FeatureDescriptors &descriptors1, const FeatureDescriptors &descriptors2, FeatureMatches *matches)
void MatchSiftFeaturesCPU(const SiftMatchingOptions &match_options, const FeatureDescriptors &descriptors1, const FeatureDescriptors &descriptors2, FeatureMatches *matches)
bool ExtractSiftFeaturesCPU(const SiftExtractionOptions &options, const Bitmap &bitmap, FeatureKeypoints *keypoints, FeatureDescriptors *descriptors)
void MatchGuidedSiftFeaturesCPU(const SiftMatchingOptions &match_options, const FeatureKeypoints &keypoints1, const FeatureKeypoints &keypoints2, const FeatureDescriptors &descriptors1, const FeatureDescriptors &descriptors2, TwoViewGeometry *two_view_geometry)
std::vector< FeatureKeypoint > FeatureKeypoints
T RandomReal(const T min, const T max)
std::vector< FeatureMatch > FeatureMatches
bool ExtractSiftFeaturesGPU(const SiftExtractionOptions &options, const Bitmap &bitmap, SiftGPU *sift_gpu, FeatureKeypoints *keypoints, FeatureDescriptors *descriptors)
void MatchSiftFeaturesCPUFLANN(const SiftMatchingOptions &match_options, const FeatureDescriptors &descriptors1, const FeatureDescriptors &descriptors2, FeatureMatches *matches)
Eigen::MatrixXd::Index Index
void CreateImageWithSquare(const int size, Bitmap *bitmap)
void CheckEqualMatches(const FeatureMatches &matches1, const FeatureMatches &matches2)
FeatureDescriptors CreateRandomFeatureDescriptors(const size_t num_features)
BOOST_AUTO_TEST_CASE(TestExtractSiftFeaturesCPU)
FeatureMatches inlier_matches