40 #include <visp3/core/vpCameraParameters.h>
41 #include <visp3/core/vpIoTools.h>
43 #if defined(VISP_HAVE_NLOHMANN_JSON) && defined(VISP_HAVE_CATCH2)
44 #include <nlohmann/json.hpp>
45 using json = nlohmann::json;
47 #define CATCH_CONFIG_RUNNER
50 #ifdef ENABLE_VISP_NAMESPACE
58 class vpRandomCamGenerator :
public Catch::Generators::IGenerator<vpCameraParameters>
61 std::minstd_rand m_rand;
62 std::uniform_int_distribution<> m_count_dist;
63 std::uniform_int_distribution<> m_type_dist;
64 std::uniform_real_distribution<> m_dist;
69 vpRandomCamGenerator(
double low,
double high)
70 : m_rand(std::random_device {}()), m_count_dist(1, 5), m_type_dist(0, 2), m_dist(low, high)
72 static_cast<void>(next());
76 bool next() VP_OVERRIDE
78 const double px = m_dist(m_rand);
79 const double py = m_dist(m_rand);
80 const double u0 = m_dist(m_rand);
81 const double v0 = m_dist(m_rand);
83 const int type = m_type_dist(m_rand);
94 std::vector<double> coeffs;
95 const int count = m_count_dist(m_rand);
96 for (
int i = 0; i < count; ++i) {
97 coeffs.push_back(m_dist(m_rand));
110 Catch::Generators::GeneratorWrapper<vpCameraParameters> randomCam(
double low,
double high)
112 return Catch::Generators::GeneratorWrapper<vpCameraParameters>(
113 std::unique_ptr<Catch::Generators::IGenerator<vpCameraParameters> >(
new vpRandomCamGenerator(low, high)));
117 SCENARIO(
"Serializing and deserializing a single vpCameraParameters",
"[json]")
119 GIVEN(
"Some camera intrinsics")
122 THEN(
"Serializing and deserializing does not modify the object")
126 REQUIRE(cam == otherCam);
131 SCENARIO(
"Serializing two cameras",
"[json]")
133 GIVEN(
"Some camera intrinsics")
138 WHEN(
"serializing and deserializing two different cameras")
140 THEN(
"The deserialized cams are still different")
143 const json j2 = cam2;
147 REQUIRE(resCam != resCam2);
154 int main(
int argc,
char *argv[])
156 Catch::Session session;
157 session.applyCommandLine(argc, argv);
159 int numFailed = session.run();
165 int main() {
return EXIT_SUCCESS; }
Generic class defining intrinsic camera parameters.
void initPersProjWithoutDistortion(double px, double py, double u0, double v0)
void initPersProjWithDistortion(double px, double py, double u0, double v0, double kud, double kdu)
void initProjWithKannalaBrandtDistortion(double px, double py, double u0, double v0, const std::vector< double > &distortion_coefficients)
error that can be emitted by ViSP classes.
@ badValue
Used to indicate that a value is not in the allowed range.