40 #include <visp3/core/vpIoTools.h>
41 #include <visp3/mbt/vpMbGenericTracker.h>
43 #if defined(VISP_HAVE_NLOHMANN_JSON) && defined(VISP_HAVE_CATCH2)
44 #include VISP_NLOHMANN_JSON(json.hpp)
45 using json = nlohmann::json;
47 #include <catch_amalgamated.hpp>
49 #ifdef ENABLE_VISP_NAMESPACE
55 const std::vector<std::string> names = {
"C1",
"C2" };
56 std::vector<int> featureTypes;
57 #if defined(VISP_HAVE_MODULE_KLT) && defined(VISP_HAVE_OPENCV) && defined(HAVE_OPENCV_IMGPROC) && defined(HAVE_OPENCV_VIDEO)
70 std::map<std::string, vpCameraParameters> cams;
71 cams[names[0]] = cam1;
72 cams[names[1]] = cam2;
93 template<
typename T,
typename C>
94 void checkProperties(
const T &t1,
const T &t2, C fn,
const std::string &message)
98 REQUIRE((t1.*fn)() == (t2.*fn)());
102 template<
typename T,
typename C,
typename... Fns>
103 void checkProperties(
const T &t1,
const T &t2, C fn,
const std::string &message, Fns... fns)
105 checkProperties(t1, t2, fn, message);
106 checkProperties(t1, t2, fns...);
117 std::map<std::string, vpCameraParameters> c1, c2;
123 json loadJson(
const std::string &path)
125 std::ifstream json_file(path);
126 if (!json_file.good()) {
129 json j = json::parse(json_file);
134 void saveJson(
const json &j,
const std::string &path)
136 std::ofstream json_file(path);
137 if (!json_file.good()) {
140 json_file << j.dump();
144 SCENARIO(
"MBT JSON Serialization",
"[json]")
151 GIVEN(
"A generic tracker with two cameras, one with edge and KLT features, the other with depth features")
154 WHEN(
"Saving to a JSON settings file")
156 const std::string jsonPath = tmp_dir +
"/" +
"tracker_save.json";
158 const auto modifyJson = [&jsonPath](std::function<void(json &)> modify) ->
void {
159 json j = loadJson(jsonPath);
161 saveJson(j, jsonPath);
165 THEN(
"Reloading this tracker has the same basic properties")
169 compareNamesAndTypes(t1, t2);
170 compareCameraParameters(t1, t2);
173 THEN(
"Reloading this tracker has the same basic properties")
177 checkProperties(t1, t2,
183 THEN(
"Reloaded edge tracker parameters should be the same")
185 std::map<std::string, vpMe> oldvpMe, newvpMe;
190 for (
const auto &it : oldvpMe) {
193 REQUIRE_NOTHROW(n = newvpMe[it.first]);
194 checkProperties(o, n,
211 #if defined(VISP_HAVE_MODULE_KLT) && defined(VISP_HAVE_OPENCV)
212 THEN(
"Reloaded KLT tracker parameters should be the same")
214 std::map<std::string, vpKltOpencv> oldvpKlt, newvpKlt;
215 t1.getKltOpencv(oldvpKlt);
218 t2.getKltOpencv(newvpKlt);
219 for (
const auto &it : oldvpKlt) {
222 REQUIRE_NOTHROW(n = newvpKlt[it.first]);
223 checkProperties(o, n,
236 THEN(
"Clipping properties should be the same")
243 std::map<std::string, unsigned int> oldFlags, newFlags;
246 for (
const auto &it : oldFlags) {
247 unsigned int o = it.second;
249 REQUIRE_NOTHROW(n = newFlags[it.first]);
250 THEN(
"Clipping flags for camera " + it.first +
" should be the same")
255 checkProperties(t1, t2,
261 THEN(
"VVS properties should be the same")
270 checkProperties(t1, t2,
277 WHEN(
"Modifying JSON file/Using a custom JSON file")
279 THEN(
"Removing version from file generates an error on load")
281 modifyJson([](json &j) ->
void {
287 THEN(
"Using an unsupported version generates an error on load")
289 modifyJson([](json &j) ->
void {
290 j[
"version"] =
"0.0.0";
295 THEN(
"Using an undefined reference camera generates an error")
297 modifyJson([](json &j) ->
void {
298 j[
"referenceCameraName"] =
"C3";
303 THEN(
"Not defining a transformation matrix for the reference camera is valid")
305 modifyJson([&t1](json &j) ->
void {
311 THEN(
"Not defining a transformation from a non-reference camera to the reference camera generates an error")
313 modifyJson([&t1](json &j) ->
void {
315 j[
"trackers"][otherCamName].erase(
"camTref");
320 THEN(
"The full clipping config is optional")
323 const double clipping_near = 0.21;
324 const double clipping_far = 5.2;
329 modifyJson([&t1](json &j) ->
void {
331 j[
"trackers"][c].erase(
"clipping");
340 THEN(
"Each clipping param is optional on its own")
343 const double clipping_near = 0.21;
344 const double clipping_far = 5.2;
349 THEN(
"Near clipping is optional")
351 modifyJson([&t1](json &j) ->
void {
353 j[
"trackers"][c][
"clipping"].erase(
"near");
361 THEN(
"Far clipping is optional")
363 modifyJson([&t1](json &j) ->
void {
365 j[
"trackers"][c][
"clipping"].erase(
"far");
373 THEN(
"Clipping flags are optional")
375 modifyJson([&t1](json &j) ->
void {
377 j[
"trackers"][c][
"clipping"].erase(
"flags");
391 int main(
int argc,
char *argv[])
393 Catch::Session session;
394 session.applyCommandLine(argc, argv);
395 int numFailed = session.run();
Generic class defining intrinsic camera parameters.
void initPersProjWithoutDistortion(double px, double py, double u0, double v0)
error that can be emitted by ViSP classes.
Wrapper for the KLT (Kanade-Lucas-Tomasi) feature tracker implemented in OpenCV. Thus to enable this ...
double getQuality() const
int getMaxFeatures() const
Get the list of lost feature.
int getWindowSize() const
Get the window size used to refine the corner locations.
double getHarrisFreeParameter() const
Get the free parameter of the Harris detector.
double getMinDistance() const
int getBlockSize() const
Get the size of the averaging block used to track the features.
int getPyramidLevels() const
Get the list of features id.
static double rad(double deg)
Real-time 6D object pose tracking using its CAD model.
virtual void setCameraParameters(const vpCameraParameters &camera) VP_OVERRIDE
virtual void getCameraParameters(vpCameraParameters &camera) const VP_OVERRIDE
virtual void setLod(bool useLod, const std::string &name="") VP_OVERRIDE
virtual void saveConfigFile(const std::string &settingsFile) const
virtual std::string getReferenceCameraName() const
virtual std::map< std::string, int > getCameraTrackerTypes() const
virtual void setMovingEdge(const vpMe &me)
virtual void setAngleDisappear(const double &a) VP_OVERRIDE
virtual std::vector< std::string > getCameraNames() const
virtual void getClipping(unsigned int &clippingFlag1, unsigned int &clippingFlag2) const
virtual void setClipping(const unsigned int &flags) VP_OVERRIDE
virtual vpMe getMovingEdge() const
virtual void setNearClippingDistance(const double &dist) VP_OVERRIDE
virtual void loadConfigFile(const std::string &configFile, bool verbose=true) VP_OVERRIDE
virtual void setAngleAppear(const double &a) VP_OVERRIDE
virtual void setFarClippingDistance(const double &dist) VP_OVERRIDE
virtual double getNearClippingDistance() const
virtual void setMaxIter(unsigned int max)
virtual double getInitialMu() const
virtual double getAngleAppear() const
virtual double getAngleDisappear() const
virtual void setInitialMu(double mu)
virtual void setLambda(double gain)
virtual unsigned int getMaxIter() const
virtual double getLambda() const
virtual double getFarClippingDistance() const
void setMu1(const double &mu_1)
double getMinSampleStep() const
void setRange(const unsigned int &range)
void setLikelihoodThresholdType(const vpLikelihoodThresholdType likelihood_threshold_type)
void setMaskNumber(const unsigned int &mask_number)
int getNbTotalSample() const
void setThreshold(const double &threshold)
unsigned int getAngleStep() const
unsigned int getMaskNumber() const
int getPointsToTrack() const
void setSampleStep(const double &sample_step)
void setMaskSize(const unsigned int &mask_size)
void setMu2(const double &mu_2)
double getSampleStep() const
unsigned int getRange() const