42 #include <visp3/core/vpCameraParameters.h>
43 #include <visp3/core/vpIoTools.h>
45 #if defined(VISP_HAVE_NLOHMANN_JSON) && defined(VISP_HAVE_CATCH2)
46 #include <nlohmann/json.hpp>
47 using json = nlohmann::json;
49 #define CATCH_CONFIG_RUNNER
56 class vpRandomCamGenerator :
public Catch::Generators::IGenerator<vpCameraParameters>
59 std::minstd_rand m_rand;
60 std::uniform_int_distribution<> m_count_dist;
61 std::uniform_int_distribution<> m_type_dist;
62 std::uniform_real_distribution<> m_dist;
67 vpRandomCamGenerator(
double low,
double high)
68 : m_rand(std::random_device {}()), m_count_dist(1, 5), m_type_dist(0, 2), m_dist(low, high)
70 static_cast<void>(next());
74 bool next() vp_override
76 const double px = m_dist(m_rand);
77 const double py = m_dist(m_rand);
78 const double u0 = m_dist(m_rand);
79 const double v0 = m_dist(m_rand);
81 const int type = m_type_dist(m_rand);
92 std::vector<double> coeffs;
93 const int count = m_count_dist(m_rand);
94 for (
int i = 0; i < count; ++i) {
95 coeffs.push_back(m_dist(m_rand));
108 Catch::Generators::GeneratorWrapper<vpCameraParameters> randomCam(
double low,
double high)
110 return Catch::Generators::GeneratorWrapper<vpCameraParameters>(
111 std::unique_ptr<Catch::Generators::IGenerator<vpCameraParameters> >(
new vpRandomCamGenerator(low, high)));
115 SCENARIO(
"Serializing and deserializing a single vpCameraParameters",
"[json]")
117 GIVEN(
"Some camera intrinsics")
120 THEN(
"Serializing and deserializing does not modify the object")
124 REQUIRE(cam == otherCam);
129 SCENARIO(
"Serializing two cameras",
"[json]")
131 GIVEN(
"Some camera intrinsics")
136 WHEN(
"serializing and deserializing two different cameras")
138 THEN(
"The deserialized cams are still different")
141 const json j2 = cam2;
145 REQUIRE(resCam != resCam2);
152 int main(
int argc,
char *argv[])
154 Catch::Session session;
155 session.applyCommandLine(argc, argv);
157 int numFailed = session.run();
163 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.