42 #include <visp3/core/vpIoTools.h>
43 #include <visp3/mbt/vpMbGenericTracker.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
54 const std::vector<std::string> names = {
"C1",
"C2" };
55 std::vector<int> featureTypes;
56 #if defined(VISP_HAVE_MODULE_KLT) && defined(VISP_HAVE_OPENCV) && defined(HAVE_OPENCV_IMGPROC) && defined(HAVE_OPENCV_VIDEO)
69 std::map<std::string, vpCameraParameters> cams;
70 cams[names[0]] = cam1;
71 cams[names[1]] = cam2;
92 template<
typename T,
typename C>
93 void checkProperties(
const T &t1,
const T &t2, C fn,
const std::string &message)
97 REQUIRE((t1.*fn)() == (t2.*fn)());
101 template<
typename T,
typename C,
typename... Fns>
102 void checkProperties(
const T &t1,
const T &t2, C fn,
const std::string &message, Fns... fns)
104 checkProperties(t1, t2, fn, message);
105 checkProperties(t1, t2, fns...);
116 std::map<std::string, vpCameraParameters> c1, c2;
122 json loadJson(
const std::string &path)
124 std::ifstream json_file(path);
125 if (!json_file.good()) {
128 json j = json::parse(json_file);
133 void saveJson(
const json &j,
const std::string &path)
135 std::ofstream json_file(path);
136 if (!json_file.good()) {
139 json_file << j.dump();
143 SCENARIO(
"MBT JSON Serialization",
"[json]")
150 GIVEN(
"A generic tracker with two cameras, one with edge and KLT features, the other with depth features")
153 WHEN(
"Saving to a JSON settings file")
155 const std::string jsonPath = tmp_dir +
"/" +
"tracker_save.json";
157 const auto modifyJson = [&jsonPath](std::function<void(json &)> modify) ->
void {
158 json j = loadJson(jsonPath);
160 saveJson(j, jsonPath);
164 THEN(
"Reloading this tracker has the same basic properties")
168 compareNamesAndTypes(t1, t2);
169 compareCameraParameters(t1, t2);
172 THEN(
"Reloading this tracker has the same basic properties")
176 checkProperties(t1, t2,
182 THEN(
"Reloaded edge tracker parameters should be the same")
184 std::map<std::string, vpMe> oldvpMe, newvpMe;
189 for (
const auto &it : oldvpMe) {
192 REQUIRE_NOTHROW(n = newvpMe[it.first]);
193 checkProperties(o, n,
210 #if defined(VISP_HAVE_MODULE_KLT) && defined(VISP_HAVE_OPENCV)
211 THEN(
"Reloaded KLT tracker parameters should be the same")
213 std::map<std::string, vpKltOpencv> oldvpKlt, newvpKlt;
218 for (
const auto &it : oldvpKlt) {
221 REQUIRE_NOTHROW(n = newvpKlt[it.first]);
222 checkProperties(o, n,
235 THEN(
"Clipping properties should be the same")
242 std::map<std::string, unsigned int> oldFlags, newFlags;
245 for (
const auto &it : oldFlags) {
246 unsigned int o = it.second;
248 REQUIRE_NOTHROW(n = newFlags[it.first]);
249 THEN(
"Clipping flags for camera " + it.first +
" should be the same")
254 checkProperties(t1, t2,
260 THEN(
"VVS properties should be the same")
269 checkProperties(t1, t2,
276 WHEN(
"Modifying JSON file/Using a custom JSON file")
278 THEN(
"Removing version from file generates an error on load")
280 modifyJson([](json &j) ->
void {
286 THEN(
"Using an unsupported version generates an error on load")
288 modifyJson([](json &j) ->
void {
289 j[
"version"] =
"0.0.0";
294 THEN(
"Using an undefined reference camera generates an error")
296 modifyJson([](json &j) ->
void {
297 j[
"referenceCameraName"] =
"C3";
302 THEN(
"Not defining a transformation matrix for the reference camera is valid")
304 modifyJson([&t1](json &j) ->
void {
310 THEN(
"Not defining a transformation from a non-reference camera to the reference camera generates an error")
312 modifyJson([&t1](json &j) ->
void {
314 j[
"trackers"][otherCamName].erase(
"camTref");
319 THEN(
"The full clipping config is optional")
322 const double clipping_near = 0.21;
323 const double clipping_far = 5.2;
328 modifyJson([&t1](json &j) ->
void {
330 j[
"trackers"][c].erase(
"clipping");
339 THEN(
"Each clipping param is optional on its own")
342 const double clipping_near = 0.21;
343 const double clipping_far = 5.2;
348 THEN(
"Near clipping is optional")
350 modifyJson([&t1](json &j) ->
void {
352 j[
"trackers"][c][
"clipping"].erase(
"near");
360 THEN(
"Far clipping is optional")
362 modifyJson([&t1](json &j) ->
void {
364 j[
"trackers"][c][
"clipping"].erase(
"far");
372 THEN(
"Clipping flags are optional")
374 modifyJson([&t1](json &j) ->
void {
376 j[
"trackers"][c][
"clipping"].erase(
"flags");
389 int main(
int argc,
char *argv[])
391 Catch::Session session;
392 session.applyCommandLine(argc, argv);
394 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 loadConfigFile(const std::string &configFile, bool verbose=true) vp_override
virtual void setAngleDisappear(const double &a) vp_override
virtual void getCameraParameters(vpCameraParameters &camera) const 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 setAngleAppear(const double &a) vp_override
virtual std::vector< std::string > getCameraNames() const
virtual void setFarClippingDistance(const double &dist) vp_override
virtual void setNearClippingDistance(const double &dist) vp_override
virtual void getClipping(unsigned int &clippingFlag1, unsigned int &clippingFlag2) const
virtual void setCameraParameters(const vpCameraParameters &camera) vp_override
virtual vpKltOpencv getKltOpencv() const
virtual void setClipping(const unsigned int &flags) vp_override
virtual vpMe getMovingEdge() const
virtual void setLod(bool useLod, const std::string &name="") 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