Visual Servoing Platform version 3.6.0
Loading...
Searching...
No Matches
vpMe.h
1/****************************************************************************
2 *
3 * ViSP, open source Visual Servoing Platform software.
4 * Copyright (C) 2005 - 2023 by Inria. All rights reserved.
5 *
6 * This software is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 * See the file LICENSE.txt at the root directory of this source
11 * distribution for additional information about the GNU GPL.
12 *
13 * For using ViSP with software that can not be combined with the GNU
14 * GPL, please contact Inria about acquiring a ViSP Professional
15 * Edition License.
16 *
17 * See https://visp.inria.fr for more information.
18 *
19 * This software was developed at:
20 * Inria Rennes - Bretagne Atlantique
21 * Campus Universitaire de Beaulieu
22 * 35042 Rennes Cedex
23 * France
24 *
25 * If you have questions regarding the use of this file, please contact
26 * Inria at visp@inria.fr
27 *
28 * This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
29 * WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
30 *
31 * Description:
32 * Moving edges.
33 *
34*****************************************************************************/
35
41#ifndef _vpMe_h_
42#define _vpMe_h_
43
44#include <visp3/core/vpImage.h>
45#include <visp3/core/vpMath.h>
46#include <visp3/core/vpMatrix.h>
47
121class VISP_EXPORT vpMe
122{
123public:
127 typedef enum
128 {
130 OLD_THRESHOLD = 0,
132 NORMALIZED_THRESHOLD = 1
133 } vpLikelihoodThresholdType;
134
135private:
136 vpLikelihoodThresholdType m_likelihood_threshold_type;
137
138#ifdef VISP_BUILD_DEPRECATED_FUNCTIONS
139public:
140#else
141private:
142#endif
143 double threshold;
144 double mu1;
145 double mu2;
147 unsigned int anglestep;
149 unsigned int range;
150 double sample_step;
156 unsigned int mask_size;
160 unsigned int n_mask;
161 // Strip: defines a "security strip" such that Seek_Extremities()
162 // cannot return a new extremity which is too close to the
163 // frame borders which may cause Get_Sampling_Grid to refuse
164 // the that extremity
165 int strip;
167
168public:
172 vpMe();
176 vpMe(const vpMe &me);
180 virtual ~vpMe();
181
185 vpMe &operator=(const vpMe &me);
186#if (VISP_CXX_STANDARD >= VISP_CXX_STANDARD_11)
190 vpMe &operator=(const vpMe &&me);
191#endif
192
198 void checkSamplestep(double &sample_step)
199 {
200 if (sample_step < min_samplestep)
201 sample_step = min_samplestep;
202 }
208 inline unsigned int getAngleStep() const { return anglestep; }
214 inline vpMatrix *getMask() const { return mask; }
222 inline unsigned int getMaskNumber() const { return n_mask; }
228 inline int getMaskSign() const { return mask_sign; }
236 inline unsigned int getMaskSize() const { return mask_size; }
243 inline double getMinSampleStep() const { return min_samplestep; }
249 inline double getMu1() const { return mu1; }
255 inline double getMu2() const { return mu2; }
261 inline int getNbTotalSample() const { return ntotal_sample; }
267 inline int getPointsToTrack() const { return points_to_track; }
273 inline unsigned int getRange() const { return range; }
279 inline int getStrip() const { return strip; }
280
288 inline double getThreshold() const { return threshold; }
289
297 inline vpLikelihoodThresholdType getLikelihoodThresholdType() const { return m_likelihood_threshold_type; }
298
303 void initMask(); // convolution masks - offset computation
304
308 void print();
309
315 void setAngleStep(const unsigned int &a) { anglestep = a; }
323 void setMaskNumber(const unsigned int &a);
324
330 void setMaskSign(const int &a) { mask_sign = a; }
331
339 void setMaskSize(const unsigned int &a);
346 void setMinSampleStep(const double &min) { min_samplestep = min; }
347
353 void setMu1(const double &mu_1) { this->mu1 = mu_1; }
354
360 void setMu2(const double &mu_2) { this->mu2 = mu_2; }
361
367 void setNbTotalSample(const int &nb) { ntotal_sample = nb; }
368
376 void setPointsToTrack(const int &n) { points_to_track = n; }
377
383 void setRange(const unsigned int &r) { range = r; }
384
390 void setSampleStep(const double &s) { sample_step = s; }
391
397 inline double getSampleStep() const { return sample_step; }
398
404 void setStrip(const int &a) { strip = a; }
405
435 void setThreshold(const double &t) { threshold = t; }
436
445 void setLikelihoodThresholdType(const vpLikelihoodThresholdType likelihood_threshold_type) { m_likelihood_threshold_type = likelihood_threshold_type; }
446
447#ifdef VISP_HAVE_NLOHMANN_JSON
454 friend void to_json(nlohmann::json &j, const vpMe &me);
455
499 friend void from_json(const nlohmann::json &j, vpMe &me);
500#endif
501};
502#ifdef VISP_HAVE_NLOHMANN_JSON
503#include <nlohmann/json.hpp>
504
505inline void to_json(nlohmann::json &j, const vpMe &me)
506{
507 j = {
508 {"thresholdType", me.getLikelihoodThresholdType()},
509 {"threshold", me.getThreshold()},
510 {"mu", {me.getMu1(), me.getMu2()}},
511 {"minSampleStep", me.getMinSampleStep()},
512 {"sampleStep", me.getSampleStep()},
513 {"range", me.getRange()},
514 {"ntotalSample", me.getNbTotalSample()},
515 {"pointsToTrack", me.getPointsToTrack()},
516 {"maskSize", me.getMaskSize()},
517 {"nMask", me.getMaskNumber()},
518 {"maskSign", me.getMaskSign()},
519 {"strip", me.getStrip()}
520 };
521}
522
523inline void from_json(const nlohmann::json &j, vpMe &me)
524{
525 if (j.contains("thresholdType")) {
526 me.setLikelihoodThresholdType(j.value("thresholdType", me.getLikelihoodThresholdType()));
527 }
528 me.setThreshold(j.value("threshold", me.getThreshold()));
529
530 if (j.contains("mu")) {
531 std::vector<double> mus = j.at("mu").get<std::vector<double>>();
532 assert((mus.size() == 2));
533 me.setMu1(mus[0]);
534 me.setMu2(mus[1]);
535 }
536 me.setMinSampleStep(j.value("minSampleStep", me.getMinSampleStep()));
537
538 me.setRange(j.value("range", me.getRange()));
539 me.setNbTotalSample(j.value("ntotalSample", me.getNbTotalSample()));
540 me.setPointsToTrack(j.value("pointsToTrack", me.getPointsToTrack()));
541 me.setMaskSize(j.value("maskSize", me.getMaskSize()));
542 me.setMaskSign(j.value("maskSign", me.getMaskSign()));
543 me.setStrip(j.value("strip", me.getStrip()));
544 if (j.contains("angleStep") && j.contains("nMask")) {
545 std::cerr << "both angle step and number of masks are defined, number of masks will take precedence" << std::endl;
546 me.setMaskNumber(j["nMask"]);
547 }
548 else if (j.contains("angleStep")) {
549 me.setAngleStep(j["angleStep"]);
550 }
551 else if (j.contains("nMask")) {
552 me.setMaskNumber(j["nMask"]);
553 }
554 me.initMask();
555}
556
557#endif
558
559#endif
Implementation of a matrix and operations on matrices.
Definition vpMatrix.h:152
Definition vpMe.h:122
int getMaskSign() const
Definition vpMe.h:228
void setMu1(const double &mu_1)
Definition vpMe.h:353
double threshold
Definition vpMe.h:143
void setSampleStep(const double &s)
Definition vpMe.h:390
void setMaskSign(const int &a)
Definition vpMe.h:330
int ntotal_sample
Distance between sampled points in pixels.
Definition vpMe.h:151
double sample_step
Seek range - on both sides of the reference pixel.
Definition vpMe.h:150
void setRange(const unsigned int &r)
Definition vpMe.h:383
void setStrip(const int &a)
Definition vpMe.h:404
vpLikelihoodThresholdType getLikelihoodThresholdType() const
Definition vpMe.h:297
double getMinSampleStep() const
Definition vpMe.h:243
void setLikelihoodThresholdType(const vpLikelihoodThresholdType likelihood_threshold_type)
Definition vpMe.h:445
void setMinSampleStep(const double &min)
Definition vpMe.h:346
double min_samplestep
Contrast continuity parameter (right boundary)
Definition vpMe.h:146
void setMaskSize(const unsigned int &a)
Definition vpMe.cpp:452
void setAngleStep(const unsigned int &a)
Definition vpMe.h:315
int getNbTotalSample() const
Definition vpMe.h:261
unsigned int n_mask
Definition vpMe.h:160
void checkSamplestep(double &sample_step)
Definition vpMe.h:198
unsigned int anglestep
Definition vpMe.h:147
unsigned int getAngleStep() const
Definition vpMe.h:208
vpMatrix * getMask() const
Definition vpMe.h:214
double getMu1() const
Definition vpMe.h:249
unsigned int mask_size
Definition vpMe.h:156
unsigned int getMaskNumber() const
Definition vpMe.h:222
int getPointsToTrack() const
Definition vpMe.h:267
int strip
Definition vpMe.h:165
int getStrip() const
Definition vpMe.h:279
void setNbTotalSample(const int &nb)
Definition vpMe.h:367
int points_to_track
Definition vpMe.h:152
double mu1
Old likelihood ratio threshold (to be avoided) or easy-to-use normalized threshold: minimal contrast.
Definition vpMe.h:144
double getMu2() const
Definition vpMe.h:255
double getThreshold() const
Definition vpMe.h:288
void setPointsToTrack(const int &n)
Definition vpMe.h:376
unsigned int range
Definition vpMe.h:149
unsigned int getMaskSize() const
Definition vpMe.h:236
void initMask()
Definition vpMe.cpp:329
void setMu2(const double &mu_2)
Definition vpMe.h:360
double mu2
Contrast continuity parameter (left boundary)
Definition vpMe.h:145
double getSampleStep() const
Definition vpMe.h:397
unsigned int getRange() const
Definition vpMe.h:273
int mask_sign
Definition vpMe.h:148
vpLikelihoodThresholdType
Definition vpMe.h:128
vpMatrix * mask
Definition vpMe.h:166
void setMaskNumber(const unsigned int &a)
Definition vpMe.cpp:445
void setThreshold(const double &t)
Definition vpMe.h:435