diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 7f48fc0..d1aec1a 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -17,11 +17,14 @@ jobs: - name: Install dependencies run: | sudo apt-get update - sudo apt-get install -y libeigen3-dev libpng-dev + sudo apt-get install -y libeigen3-dev libpng-dev libgtest-dev - name: Configure - run: cd samples && mkdir build && cd build && cmake .. + run: mkdir build && cd build && cmake .. - name: Build - run: cd samples/build && make -j + run: cd build && make -j + + - name: Test + run: cd build && ctest --output-on-failure diff --git a/.gitignore b/.gitignore index 34c9441..d6d4c81 100644 --- a/.gitignore +++ b/.gitignore @@ -6,5 +6,8 @@ doc data/MPI-Sintel* data/kitti data/*.bin -samples/build +build +.cache +.cache + diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100644 index 0000000..55e3851 --- /dev/null +++ b/CMakeLists.txt @@ -0,0 +1,43 @@ +cmake_minimum_required(VERSION 3.10) +include(CheckCXXCompilerFlag) +include(CheckCXXSourceRuns) +project(openGPC CXX) +set (REQ_CPP11_FEATURES cxx_strong_enums cxx_auto_type) + +set(CMAKE_CXX_STANDARD 17) +set(CMAKE_CXX_STANDARD_REQUIRED ON) +set(CMAKE_EXPORT_COMPILE_COMMANDS ON) + +find_package(Eigen3 REQUIRED) +find_package(PNG REQUIRED) +find_package(Threads REQUIRED) + +include_directories(${EIGEN3_INCLUDE_DIR}) +include_directories(${PNG_INCLUDE_DIRS}) +include_directories(lib) + +#By default, use SSE intrinsics +option(SSE "Enable SSE/AVX optimizations if available" ON) + +add_compile_options(-O3 -funroll-loops) +if(SSE) + message(STATUS "Checking if target CPU supports AVX2 instructions...") + check_cxx_source_runs(" + #include + int main() { + __m256i x = _mm256_set1_epi32(1); + return _mm256_extract_epi32(x, 0); + } + " CPU_HAS_AVX2) + + if(CPU_HAS_AVX2) + message(STATUS "AVX2: supported and enabled") + add_compile_definitions(_INTRINSICS_SSE) + add_compile_options(-mavx2 -march=core-avx2) + endif() +endif() + +enable_testing() +add_subdirectory(samples) +add_subdirectory(tests) + diff --git a/data/middlebury/README.md b/data/middlebury/README.md new file mode 100644 index 0000000..567eede --- /dev/null +++ b/data/middlebury/README.md @@ -0,0 +1,7 @@ +The images in directory are sourced from the `chess` scene in the [Middlebury 2021 dataset](https://vision.middlebury.edu/stereo/data/). + +``` +D. Scharstein, H. Hirschmüller, Y. Kitajima, G. Krathwohl, N. Nesic, X. Wang, and P. Westling. High-resolution stereo datasets with subpixel-accurate ground truth. +In German Conference on Pattern Recognition (GCPR 2014), Münster, Germany, September 2014. +``` + diff --git a/data/middlebury/im0.png b/data/middlebury/im0.png new file mode 100644 index 0000000..05e5ccc Binary files /dev/null and b/data/middlebury/im0.png differ diff --git a/data/middlebury/im1.png b/data/middlebury/im1.png new file mode 100644 index 0000000..51c3460 Binary files /dev/null and b/data/middlebury/im1.png differ diff --git a/lib/gpc/buffer.hpp b/lib/gpc/buffer.hpp index 0a8969b..d8f3a5a 100644 --- a/lib/gpc/buffer.hpp +++ b/lib/gpc/buffer.hpp @@ -81,7 +81,6 @@ struct Descriptor { bool operator<=(const Descriptor& d) const { return state <= d.state; } int operator%(const int& d) const { return state % d; } }; - // Keeps support points with associated disparity // Support points are only used in the left image struct Support { @@ -91,6 +90,24 @@ struct Support { Support(int x, int y) : x(x), y(y), d(0.) {} Support() {}; }; +inline bool operator<(const Support& a, const Support& b) { + if (a.x != b.x) return a.x < b.x; + if (a.y != b.y) return a.y < b.y; + return a.d < b.d; +} +inline std::ostream& operator<<(std::ostream& os, const Support& s) { + return os << "(" << s.x << ", " << s.y << ", " << s.d << ")"; +} +template +inline std::ostream& operator<<(std::ostream& os, const std::vector& v) { + os << "["; + for (size_t i = 0; i < v.size(); ++i) { + os << v[i]; + if (i + 1 < v.size()) os << ", "; + } + os << "]"; + return os; +} // Keeps correspondences in case of non-epipolar matching scenario struct Correspondence { Point srcPt, tarPt; diff --git a/samples/CMakeLists.txt b/samples/CMakeLists.txt index 9dafd8a..3bbe11f 100644 --- a/samples/CMakeLists.txt +++ b/samples/CMakeLists.txt @@ -1,46 +1,3 @@ -cmake_minimum_required(VERSION 3.10) -include(CheckCXXCompilerFlag) -include(CheckCXXSourceRuns) -project(openGPC CXX) -set (REQ_CPP11_FEATURES cxx_strong_enums cxx_auto_type) - -set(CMAKE_CXX_STANDARD 17) -set(CMAKE_CXX_STANDARD_REQUIRED ON) -set(CMAKE_EXPORT_COMPILE_COMMANDS ON) - -find_package(Eigen3 REQUIRED) -include_directories(${EIGEN3_INCLUDE_DIR}) - -#By default, use SSE intrinsics -option(SSE "Enable SSE/AVX optimizations if available" ON) - -add_compile_options(-O3 -funroll-loops) -if(SSE) - message(STATUS "Checking if target CPU supports AVX2 instructions...") - check_cxx_source_runs(" - #include - int main() { - __m256i x = _mm256_set1_epi32(1); - return _mm256_extract_epi32(x, 0); - } - " CPU_HAS_AVX2) - - if(CPU_HAS_AVX2) - message(STATUS "AVX2: supported and enabled") - add_compile_definitions(_INTRINSICS_SSE) - add_compile_options(-mavx2 -march=core-avx2) - endif() -endif() - -#find pnglib (used to load and store images for training and during evaluation) -find_package(PNG REQUIRED) -include_directories(${PNG_INCLUDE_DIRS}) - -set(THREADS_PREFER_PTHREAD_FLAG ON) -find_package(Threads REQUIRED) - -include_directories("../lib") - add_executable(extract extract.cpp) target_link_libraries(extract ${PNG_LIBRARIES} Threads::Threads) diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt new file mode 100644 index 0000000..acf86db --- /dev/null +++ b/tests/CMakeLists.txt @@ -0,0 +1,18 @@ +find_package(GTest REQUIRED) + +include(FetchContent) + +FetchContent_Declare( + approvaltests + GIT_REPOSITORY https://github.com/approvals/ApprovalTests.cpp.git + GIT_TAG v.10.12.0 +) +FetchContent_MakeAvailable(approvaltests) + + +find_package(GTest REQUIRED) +add_executable(test_single_matching test_single_matching.cpp) +target_link_libraries(test_single_matching PRIVATE ${PNG_LIBRARIES} ApprovalTests::ApprovalTests GTest::gtest_main) + +add_test(NAME single_matching COMMAND test_single_matching) + diff --git a/tests/test_single_matching.Approval.Inference.approved.txt b/tests/test_single_matching.Approval.Inference.approved.txt new file mode 100644 index 0000000..294072e --- /dev/null +++ b/tests/test_single_matching.Approval.Inference.approved.txt @@ -0,0 +1 @@ +[(13, 569, 0), (13, 570, 0), (13, 658, -1), (13, 659, -1), (13, 660, -1), (13, 671, -1), (13, 690, -2), (14, 562, 1), (14, 571, 1), (14, 572, 1), (14, 573, 1), (14, 609, 0), (14, 792, -5), (14, 793, -5), (14, 794, -5), (14, 857, -5), (15, 566, 2), (15, 828, -5), (15, 868, -6), (15, 1006, -10), (16, 850, -5), (143, 76, 103), (215, 753, 102), (236, 336, 128), (236, 337, 128), (237, 340, 128), (237, 341, 128), (239, 347, 128), (239, 351, 128), (239, 352, 128), (239, 353, 128), (239, 356, 128), (240, 263, 67), (240, 351, 128), (240, 352, 128), (240, 354, 128), (240, 357, 128), (240, 359, 128), (240, 362, 128), (241, 264, 68), (241, 362, 128), (241, 364, 128), (242, 364, 128), (242, 367, 128), (243, 267, 68), (243, 370, 128), (243, 371, 128), (243, 372, 127), (243, 373, 127), (243, 374, 127), (243, 375, 128), (243, 377, 128), (243, 421, 124), (244, 268, 69), (244, 377, 127), (244, 378, 127), (244, 380, 127), (244, 420, 124), (244, 421, 124), (244, 442, 127), (245, 270, 69), (245, 385, 127), (245, 386, 127), (245, 425, 124), (245, 439, 127), (246, 387, 128), (246, 388, 127), (246, 389, 127), (247, 442, 128), (247, 448, 128), (248, 374, 128), (248, 446, 128), (249, 276, 69), (250, 277, 69), (250, 412, 127), (250, 413, 126), (250, 456, 127), (252, 426, 127), (252, 932, 115), (254, 425, 126), (256, 287, 68), (257, 289, 68), (258, 290, 68), (259, 292, 69), (259, 421, 126), (262, 419, 127), (264, 418, 126), (266, 418, 6), (266, 550, 121), (267, 422, 126), (269, 286, 82), (270, 938, 119), (272, 582, 120), (272, 583, 120), (273, 843, 113), (275, 934, 124), (277, 560, 127), (278, 617, 119), (279, 570, 96), (279, 617, 119), (279, 620, 119), (279, 621, 119), (282, 623, -1), (283, 644, 118), (284, 637, 92), (285, 635, -2), (285, 642, 119), (287, 401, 40), (290, 557, -38), (291, 634, 125), (292, 643, 126), (292, 674, 118), (296, 570, -40), (296, 665, 5), (296, 715, 116), (296, 716, 116), (297, 674, 119), (298, 672, 120), (298, 673, 120), (299, 682, 119), (299, 723, 117), (300, 687, 119), (300, 688, 119), (300, 690, 118), (301, 580, -42), (301, 693, 119), (301, 698, 118), (301, 744, 115), (304, 587, -43), (304, 953, 125), (310, 600, -46), (310, 986, 128), (311, 506, 62), (312, 205, 127), (320, 840, 112), (321, 836, 112), (322, 237, 72), (322, 841, 111), (324, 843, 112), (324, 844, 112), (325, 838, 113), (325, 844, 112), (325, 845, 112), (326, 842, 113), (328, 228, 127), (329, 228, 127), (332, 845, 113), (333, 844, 114), (336, 719, 42), (338, 716, 38), (339, 235, 125), (339, 381, 99), (339, 718, 39), (344, 232, 52), (346, 455, -117), (346, 456, -116), (346, 554, -121), (354, 834, 125), (355, 831, 126), (359, 223, 124), (368, 218, 126), (370, 392, -97), (377, 58, 124), (385, 315, 123), (387, 316, 124), (387, 384, 94), (388, 313, 119), (391, 312, 122), (395, 299, 122), (396, 54, 109), (396, 475, -24), (400, 918, -107), (404, 180, 123), (407, 453, -109), (408, 286, 119), (409, 208, 123), (412, 504, -44), (414, 340, 121), (415, 220, 123), (415, 221, 123), (417, 561, 87), (418, 218, 123), (420, 1035, -94), (425, 338, 118), (433, 53, 124), (434, 379, 117), (436, 379, 118), (437, 52, 128), (437, 205, -47), (437, 379, 118), (439, 378, 109), (440, 317, 120), (443, 285, 120), (443, 394, 125), (446, 414, 126), (448, 202, 121), (452, 330, 119), (452, 719, 64), (454, 199, 122), (455, 52, 126), (455, 723, 65), (456, 377, 118), (457, 199, 122), (463, 325, 120), (465, 330, 112), (470, 192, 121), (472, 330, 120), (473, 327, 118), (473, 372, 115), (477, 372, 112), (480, 272, 108), (480, 279, 119), (481, 170, 120), (481, 186, 120), (481, 221, 115), (482, 169, 120), (483, 185, 121), (486, 823, 63), (489, 181, 120), (492, 370, 115), (500, 312, 118), (504, 179, 119), (505, 172, 122), (508, 171, 120), (509, 171, 120), (510, 961, 126), (517, 169, 121), (517, 217, 118), (518, 401, 124), (519, 400, 122), (520, 400, 124), (523, 321, 115), (523, 407, 126), (525, 171, 118), (526, 272, 117), (527, 363, 127), (529, 315, 116), (532, 171, 119), (534, 360, 110), (539, 360, 112), (543, 297, 117), (552, 588, 27), (555, 262, 96), (555, 295, 117), (555, 391, 123), (556, 357, 112), (557, 291, 116), (558, 594, 27), (565, 161, 115), (570, 169, 116), (570, 170, 120), (572, 354, 111), (572, 398, 122), (573, 313, 114), (573, 611, 28), (574, 609, 29), (576, 394, 105), (577, 615, 29), (578, 352, 113), (579, 352, 110), (580, 697, -38), (581, 166, 112), (583, 354, 112), (585, 622, 31), (589, 310, 112), (591, 262, 113), (593, 352, 113), (595, 204, 115), (597, 68, 117), (597, 69, 117), (598, 64, 117), (598, 66, 117), (598, 67, 117), (598, 68, 117), (598, 69, 117), (598, 70, 117), (598, 71, 117), (598, 72, 117), (598, 81, 117), (599, 73, 117), (599, 75, 117), (599, 86, 116), (599, 87, 116), (600, 83, 117), (600, 84, 117), (600, 85, 117), (600, 88, 117), (600, 94, 116), (600, 95, 116), (601, 92, 117), (601, 99, 116), (601, 100, 116), (601, 101, 116), (601, 102, 116), (602, 102, 116), (602, 106, 116), (602, 107, 116), (603, 151, 115), (603, 204, 114), (603, 205, 113), (604, 126, 115), (604, 146, 115), (604, 147, 115), (605, 146, 115), (605, 205, 113), (605, 348, 107), (606, 144, 115), (606, 146, 115), (606, 148, 115), (606, 150, 115), (606, 203, 114), (607, 150, 115), (608, 55, 118), (609, 204, 114), (610, 205, 114), (611, 205, 114), (611, 208, 114), (611, 209, 114), (611, 210, 114), (612, 150, 116), (612, 202, 114), (612, 205, 114), (612, 206, 114), (612, 208, 113), (612, 209, 113), (612, 345, 112), (613, 102, 117), (613, 202, 114), (613, 348, 111), (613, 652, -113), (614, 212, 114), (614, 305, 111), (614, 306, 111), (615, 103, 118), (615, 347, 111), (616, 154, 114), (616, 233, 113), (616, 234, 113), (616, 236, 113), (616, 250, 113), (616, 251, 113), (616, 303, 112), (616, 655, 34), (617, 132, 117), (617, 160, 116), (617, 239, 113), (617, 241, 113), (617, 242, 113), (617, 251, 113), (617, 347, 110), (618, 134, 117), (618, 137, 117), (618, 138, 117), (618, 250, 113), (619, 108, 118), (619, 109, 118), (619, 110, 118), (619, 129, 117), (619, 135, 117), (619, 136, 117), (619, 138, 117), (619, 147, 117), (619, 154, 116), (619, 253, 113), (620, 103, 118), (620, 110, 118), (620, 256, 113), (620, 258, 119), (620, 304, 112), (621, 111, 117), (621, 150, 116), (622, 129, 118), (622, 168, 117), (622, 308, 112), (622, 347, 111), (623, 129, 118), (623, 203, 115), (623, 303, 112), (623, 306, 111), (623, 309, 111), (623, 310, 111), (623, 346, 110), (623, 347, 111), (624, 130, 117), (624, 164, 116), (624, 205, 115), (624, 305, 112), (624, 308, 111), (624, 311, 112), (624, 388, 116), (625, 167, 117), (625, 169, 116), (625, 198, 116), (625, 205, 115), (625, 303, 111), (625, 316, 111), (625, 317, 111), (625, 318, 111), (625, 319, 111), (625, 339, 111), (625, 341, 111), (625, 342, 111), (625, 343, 111), (625, 389, 123), (626, 130, 117), (626, 138, 118), (626, 199, 115), (626, 200, 115), (626, 301, 112), (626, 326, 111), (626, 329, 111), (626, 330, 111), (626, 331, 111), (626, 332, 111), (626, 333, 111), (626, 339, 111), (626, 342, 111), (626, 343, 111), (627, 130, 117), (627, 141, 116), (627, 254, 115), (627, 337, 111), (627, 339, 111), (628, 50, 117), (628, 183, 116), (628, 184, 116), (628, 185, 116), (628, 254, 114), (628, 255, 114), (628, 302, 111), (628, 341, 111), (629, 97, 117), (629, 132, 118), (629, 188, 115), (629, 192, 116), (629, 193, 116), (629, 255, 114), (629, 341, 111), (630, 144, 117), (630, 193, 115), (630, 194, 115), (630, 302, 112), (630, 342, 111), (630, 344, 111), (630, 348, 110), (631, 134, 118), (631, 344, 111), (631, 348, 110), (632, 47, 118), (632, 50, 117), (632, 109, 119), (632, 196, 116), (632, 198, 116), (632, 202, 115), (632, 203, 115), (632, 205, 115), (632, 206, 115), (632, 342, 111), (633, 52, 118), (633, 53, 118), (633, 54, 118), (633, 206, 115), (633, 214, 114), (634, 53, 118), (634, 55, 118), (634, 64, 117), (635, 51, 118), (635, 76, 117), (635, 97, 117), (635, 112, 118), (635, 136, 116), (636, 61, 117), (636, 79, 117), (636, 97, 117), (636, 301, 113), (637, 75, 118), (637, 84, 115), (637, 305, 113), (637, 347, 112), (638, 347, 112), (638, 408, 126), (639, 83, 117), (639, 387, 117), (639, 408, 124), (640, 85, 117), (640, 89, 117), (640, 92, 117), (640, 277, 113), (640, 278, 113), (641, 85, 117), (641, 111, 119), (641, 347, 112), (642, 91, 114), (643, 144, 115), (643, 145, 115), (643, 343, 112), (643, 346, 111), (644, 87, 114), (644, 142, 115), (644, 342, 112), (645, 94, 115), (645, 112, 121), (645, 162, 115), (645, 343, 112), (646, 90, 115), (646, 143, 116), (646, 146, 116), (646, 148, 116), (646, 149, 116), (646, 166, 115), (646, 167, 115), (646, 347, 102), (647, 118, 121), (647, 151, 116), (647, 163, 116), (647, 164, 116), (647, 343, 111), (647, 364, 115), (648, 144, 116), (648, 364, 115), (648, 386, 124), (649, 92, 116), (649, 119, 121), (649, 170, 115), (650, 294, 113), (651, 93, 116), (652, 459, 84), (654, 318, 112), (655, 122, 121), (655, 318, 111), (655, 321, 112), (655, 322, 112), (655, 323, 112), (655, 334, 112), (655, 439, 87), (656, 228, 114), (656, 229, 114), (656, 233, 113), (656, 256, 113), (656, 321, 112), (656, 323, 112), (656, 332, 111), (656, 347, 111), (657, 125, 66), (657, 331, 111), (657, 347, 111), (658, 149, 118), (658, 244, 114), (659, 254, 113), (659, 255, 113), (659, 265, 113), (660, 261, 113), (661, 99, 116), (662, 126, 121), (662, 127, 121), (664, 152, 120), (665, 126, 123), (665, 311, 113), (666, 340, 111), (666, 341, 111), (666, 380, 117), (667, 119, 121), (667, 129, 121), (667, 331, 111), (667, 339, 112), (667, 340, 111), (667, 343, 112), (668, 328, 112), (668, 329, 112), (668, 330, 112), (668, 339, 112), (668, 343, 111), (668, 380, 118), (669, 342, 111), (669, 343, 111), (669, 344, 111), (670, 343, 111), (671, 343, 111), (672, 344, 111), (673, 103, 117), (673, 106, 118), (673, 120, 119), (674, 426, -43), (674, 432, 11), (675, 135, 122), (677, 136, 121), (677, 155, 122), (678, 156, 121), (679, 123, 120), (679, 352, 115), (680, 136, 122), (681, 157, 122), (682, 125, 119), (682, 347, 113), (682, 459, 11), (683, 459, 13), (684, 138, 123), (686, 346, 116), (688, 354, 114), (688, 379, 118), (689, 493, -77), (691, 356, 115), (691, 378, 116), (692, 455, -69), (693, 356, 114), (694, 164, 126), (695, 356, 114), (697, 119, 119), (698, 130, 118), (698, 390, 121), (698, 955, 88), (699, 970, 4), (699, 971, 4), (699, 972, 89), (700, 998, 109), (703, 122, 120), (705, 123, 120), (706, 354, 115), (707, 124, 120), (707, 354, 115), (708, 125, 120), (708, 149, 125), (709, 372, 116), (710, 126, 120), (711, 130, 120), (712, 127, 120), (712, 130, 120), (715, 128, 120), (716, 128, 120), (716, 174, 124), (718, 129, 120), (718, 175, 124), (719, 134, 120), (720, 490, -69), (721, 131, 120), (723, 159, 125), (725, 133, 121), (726, 133, 121), (727, 158, 126), (727, 160, 126), (729, 135, 121), (730, 135, 121), (730, 159, 126), (730, 162, 126), (731, 136, 121), (734, 161, 126), (738, 1036, -31), (741, 139, 122), (742, 141, 122), (742, 164, 128), (742, 433, -93), (743, 638, -73), (744, 140, 121), (746, 166, 127), (747, 192, 126), (751, 171, 66), (755, 170, 127), (756, 173, 128), (757, 468, 122), (757, 479, 119), (760, 172, 128), (763, 174, 128), (764, 176, 65), (768, 369, 118), (772, 154, 125), (775, 443, -4), (777, 448, -3), (778, 457, 108), (778, 458, 108), (784, 185, 63), (793, 1033, -10), (794, 884, -29), (795, 1011, -44), (796, 400, -6), (796, 1025, 128), (797, 427, -8), (798, 165, 126), (798, 1024, -5), (800, 433, 45), (801, 880, -11), (802, 412, 119), (802, 771, 52), (802, 937, 94), (816, 224, 126), (816, 389, -93), (816, 393, -93), (816, 876, -77), (820, 934, -91), (823, 653, 95), (824, 423, -25), (824, 965, 66), (830, 936, 86), (833, 871, 62), (839, 769, -124), (845, 470, 83), (848, 185, 128), (850, 481, 47), (850, 864, -124), (851, 424, 2), (864, 762, -125), (865, 383, 6), (865, 761, -124), (868, 346, 53), (873, 476, 7), (884, 337, -6), (885, 371, -87), (885, 372, -87), (888, 586, 60), (889, 373, 45), (900, 759, -50), (902, 642, -3), (913, 389, 37), (916, 435, 38), (917, 842, -107), (919, 704, 58), (927, 561, -120), (940, 695, 54), (944, 840, -85), (957, 691, 52), (963, 269, 54), (963, 935, 116), (964, 952, -89), (965, 274, 54), (965, 275, 54), (965, 988, -94), (965, 989, -94), (966, 828, -90), (966, 983, -92), (966, 984, -92), (966, 985, -92), (966, 986, -92), (970, 667, -48), (972, 689, 56), (975, 397, 118), (990, 1000, -97), (997, 813, -85), (1007, 769, 53), (1010, 812, -61), (1018, 392, 38), (1026, 867, 91), (1057, 665, -59), (1085, 971, -84), (1087, 382, 112), (1119, 787, 40), (1128, 1008, -1), (1129, 973, 72), (1129, 974, 72), (1130, 989, -2), (1132, 642, 47), (1150, 639, 52), (1157, 635, 48), (1173, 631, 46), (1174, 461, 93), (1197, 804, -98), (1202, 624, -55), (1214, 500, -60), (1223, 618, 52), (1236, 494, -77), (1238, 929, 81), (1258, 916, 88), (1261, 606, 45), (1266, 684, 66), (1270, 603, 47), (1276, 685, 58), (1281, 998, 110), (1281, 999, 110), (1281, 1000, 112), (1288, 928, 120), (1288, 929, 120), (1296, 78, 107), (1297, 86, 107), (1297, 100, 109), (1297, 101, 109), (1297, 103, 109), (1297, 104, 109), (1298, 75, 108), (1298, 102, 109), (1298, 105, 108), (1298, 106, 108), (1299, 75, 108), (1300, 69, 109), (1301, 68, 108), (1302, 69, 109), (1302, 75, 109), (1303, 73, 108), (1304, 50, 107), (1304, 65, 108), (1304, 76, 108), (1307, 507, 77), (1322, 666, 65), (1325, 588, 47), (1341, 197, 123), (1341, 719, 39), (1341, 720, 39), (1354, 344, 97), (1355, 752, 38), (1355, 753, 38), (1356, 343, 98), (1358, 335, 96), (1360, 335, 97), (1360, 336, 97), (1364, 336, 98), (1367, 561, -53), (1371, 461, 125), (1372, 459, 126), (1380, 337, 99), (1383, 335, 111), (1403, 715, 83), (1408, 820, 110), (1412, 825, 114), (1417, 856, 116), (1418, 570, 107), (1426, 910, 20), (1427, 890, 120), (1428, 889, 120), (1437, 942, 125), (1437, 943, 125), (1443, 963, 124), (1453, 896, 123), (1455, 417, 101), (1456, 305, 99), (1456, 308, 99), (1456, 416, 102), (1457, 306, 100), (1457, 416, 102), (1457, 917, 119), (1458, 897, 125), (1461, 477, 115), (1464, 410, 98), (1467, 334, 103), (1469, 407, 98), (1469, 440, 104), (1469, 441, 103), (1469, 443, 103), (1514, 460, 104), (1519, 897, 124), (1519, 899, 124), (1520, 897, 124), (1526, 929, 124), (1528, 899, 122), (1529, 912, 125), (1529, 913, 124), (1529, 916, 125), (1531, 839, 124), (1536, 969, 128), (1539, 962, 127), (1540, 964, 127), (1540, 965, 127), (1561, 1000, 128), (1584, 863, 49), (1686, 1017, -39), (1712, 979, 90), (1713, 978, 86), (1766, 971, 128), (1769, 966, 128), (1778, 834, -14), (1853, 970, 126), (1885, 905, 89), (1897, 935, 125), (1902, 171, 1), (1903, 67, 1), (1903, 291, 1), (1903, 292, 1), (1904, 260, 1), (1904, 261, 1), (1905, 329, 1)] diff --git a/tests/test_single_matching.cpp b/tests/test_single_matching.cpp new file mode 100644 index 0000000..f6a2e8c --- /dev/null +++ b/tests/test_single_matching.cpp @@ -0,0 +1,55 @@ +#define APPROVALS_GOOGLETEST +#include +#include +#include "gpc/inference.hpp" + + +TEST(Approval, Inference) +{ + auto file = std::filesystem::absolute(__FILE__); + auto dir = file.parent_path(); + std::filesystem::path forestPath = dir / ".." / "forests" / "defaultZeroForest.txt"; + + std::string leftImgPath = (dir / ".." / "data" / "middlebury" / "im0.png").string(); + std::string rightImgPath = (dir / ".." / "data" / "middlebury" / "im1.png").string(); + + ndb::Buffer simg, timg; + + typedef gpc::inference::Forest GPCForest_t; + GPCForest_t forest; + + gpc::inference::InferenceSettings inferencesettings = + gpc::inference::InferenceSettings() + .builder() + .gradientThreshold(5) + .verticalTolerance( + 0) // 0px tolerance for rectified epipolar matches + .dispHigh(128) // limit disparities to 128 + .epipolarMode(true) // match GPC states in epipolar mode. more + // matches, lower accuracy than global + .useHashtable(false); // use sort method for matching. faster for + // <100K descriptors + + // Load images + if (simg.readPNG(leftImgPath) || timg.readPNG(rightImgPath)) { + throw std::runtime_error("Image load failed"); + } + // Get learned filter for the given image dimensions. + GPCForest_t::FilterMask fm = + forest.readForest(forestPath, simg.cols(), simg.rows()); + + GPCForest_t::PreprocessedImage simgP = + forest.preprocessImage(simg, inferencesettings); + GPCForest_t::PreprocessedImage timgP = + forest.preprocessImage(timg, inferencesettings); + + // Match rectified stereo images + std::vector supp = + forest.rectifiedMatch(simgP, timgP, fm, inferencesettings); + std::sort(supp.begin(), supp.end()); + + std::stringstream ss; + ss << supp; + EXPECT_EQ(866, supp.size()); + ApprovalTests::Approvals::verify(ss.str()); +}