score-back/tests/test_config.cpp
Artur Mukhamadiev 4f21e2ea38 fix(cloud_point): regularise SGBM and export viewable PLY meshes
- Configure StereoSGBM with P1/P2 penalties, 5x5 block, uniqueness ratio,
  speckle filter and left-right check; previously it ran unregularised and
  produced a heavy tail of low-disparity outliers reprojecting metres away
  (SCARED benchmark MAE3D 44 mm -> 0.8 mm, RMSE 289 mm -> 1.4 mm)
- Pass the requested disparity count to the CUDA SGM matcher (rounded to
  64/128/256) instead of a hard-coded 16
- Add optional `cloud_point` config section (algorithm, num_disparities,
  depth range) consumed by CLI options 4/5; ship config.scared.yml
- write_ply now emits a binary PLY with a grid-triangulated mesh so web
  viewers stop fabricating slivers from consecutive vertices
- Add config, matcher and PLY export tests; document in README
2026-09-14 10:43:24 +03:00

64 lines
2.3 KiB
C++

#include <cstdio>
#include <fstream>
#include <gtest/gtest.h>
#include <string>
#include "cloud_point_rpc/config.hpp"
namespace {
struct TempConfig {
std::string path;
explicit TempConfig(const std::string &yaml)
: path("test_config_" +
std::to_string(reinterpret_cast<uintptr_t>(this)) + ".yaml") {
std::ofstream(path) << yaml;
}
~TempConfig() { std::remove(path.c_str()); }
};
} // namespace
TEST(ConfigLoaderTest, CloudPointSectionDefaultsWhenAbsent) {
TempConfig cfg("server:\n ip: \"127.0.0.1\"\n port: 8080\n");
const auto c = score::ConfigLoader::load(cfg.path);
EXPECT_EQ(c.cloud_point.algorithm, "gpu");
EXPECT_EQ(c.cloud_point.num_disparities, 128);
EXPECT_DOUBLE_EQ(c.cloud_point.min_depth_m, 0.01);
EXPECT_DOUBLE_EQ(c.cloud_point.max_depth_m, 10.0);
}
TEST(ConfigLoaderTest, CloudPointSectionIsParsed) {
TempConfig cfg("server:\n ip: \"127.0.0.1\"\n port: 8080\n"
"cloud_point:\n algorithm: cpu\n num_disparities: 160\n"
" min_depth_m: 0.02\n max_depth_m: 0.3\n");
const auto c = score::ConfigLoader::load(cfg.path);
EXPECT_EQ(c.cloud_point.algorithm, "cpu");
EXPECT_EQ(c.cloud_point.num_disparities, 160);
EXPECT_DOUBLE_EQ(c.cloud_point.min_depth_m, 0.02);
EXPECT_DOUBLE_EQ(c.cloud_point.max_depth_m, 0.3);
}
TEST(ConfigLoaderTest, CloudPointPartialSectionKeepsDefaults) {
TempConfig cfg("server:\n ip: \"127.0.0.1\"\n port: 8080\n"
"cloud_point:\n max_depth_m: 0.5\n");
const auto c = score::ConfigLoader::load(cfg.path);
EXPECT_EQ(c.cloud_point.algorithm, "gpu");
EXPECT_EQ(c.cloud_point.num_disparities, 128);
EXPECT_DOUBLE_EQ(c.cloud_point.max_depth_m, 0.5);
}
TEST(ConfigLoaderTest, CloudPointRejectsBadAlgorithm) {
TempConfig cfg("server:\n ip: \"127.0.0.1\"\n port: 8080\n"
"cloud_point:\n algorithm: fpga\n");
EXPECT_THROW(std::ignore = score::ConfigLoader::load(cfg.path),
std::runtime_error);
}
TEST(ConfigLoaderTest, CloudPointRejectsInvertedDepthRange) {
TempConfig cfg("server:\n ip: \"127.0.0.1\"\n port: 8080\n"
"cloud_point:\n min_depth_m: 1.0\n max_depth_m: 0.5\n");
EXPECT_THROW(std::ignore = score::ConfigLoader::load(cfg.path),
std::runtime_error);
}