Visual Servoing Platform version 3.7.0
Loading...
Searching...
No Matches
vpMe.h
1/*
2 * ViSP, open source Visual Servoing Platform software.
3 * Copyright (C) 2005 - 2025 by Inria. All rights reserved.
4 *
5 * This software is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 * See the file LICENSE.txt at the root directory of this source
10 * distribution for additional information about the GNU GPL.
11 *
12 * For using ViSP with software that can not be combined with the GNU
13 * GPL, please contact Inria about acquiring a ViSP Professional
14 * Edition License.
15 *
16 * See https://visp.inria.fr for more information.
17 *
18 * This software was developed at:
19 * Inria Rennes - Bretagne Atlantique
20 * Campus Universitaire de Beaulieu
21 * 35042 Rennes Cedex
22 * France
23 *
24 * If you have questions regarding the use of this file, please contact
25 * Inria at visp@inria.fr
26 *
27 * This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
28 * WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
29 *
30 * Description:
31 * Moving edges.
32 */
33
38
39#ifndef VP_ME_H
40#define VP_ME_H
41
42#include <visp3/core/vpConfig.h>
43#include <visp3/core/vpImage.h>
44#include <visp3/core/vpMath.h>
45#include <visp3/core/vpMatrix.h>
46
47#ifdef VISP_HAVE_NLOHMANN_JSON
48#include VISP_NLOHMANN_JSON(json.hpp)
49#endif
50
142class VISP_EXPORT vpMe
143{
144public:
148 typedef enum
149 {
155 } vpLikelihoodThresholdType;
156
157public:
161 vpMe();
162
166 vpMe(const vpMe &me);
167
171 virtual ~vpMe();
172
176 vpMe &operator=(const vpMe &me);
177
178#if (VISP_CXX_STANDARD >= VISP_CXX_STANDARD_11)
182 vpMe &operator=(const vpMe &&me);
183#endif
184
190 void checkSamplestep(double &sample_step)
191 {
192 if (sample_step < m_min_samplestep) {
193 sample_step = m_min_samplestep;
194 }
195 }
196
202 inline unsigned int getAngleStep() const { return m_anglestep; }
203
208 inline int getInitRange() const { return m_init_range; }
209
215 inline vpMatrix *getMask() const { return m_mask; }
216
224 inline unsigned int getMaskNumber() const { return m_mask_number; }
225
231 inline int getMaskSign() const { return m_mask_sign; }
232
240 inline unsigned int getMaskSize() const { return m_mask_size; }
241
248 inline double getMinSampleStep() const { return m_min_samplestep; }
249
255 inline double getMu1() const { return m_mu1; }
256
262 inline double getMu2() const { return m_mu2; }
263
269 inline int getNbTotalSample() const { return m_ntotal_sample; }
270
276 inline int getPointsToTrack() const { return m_points_to_track; }
277
283 inline unsigned int getRange() const { return m_range; }
284
290 inline double getSampleStep() const { return m_sample_step; }
291
297 inline int getStrip() const { return m_strip; }
298
306 inline double getThreshold() const { return m_threshold; }
307
315 inline double getThresholdMarginRatio() const { return m_thresholdMarginRatio; }
316
325 inline double getMinThreshold() const { return m_minThreshold; }
326
333 inline bool getUseAutomaticThreshold() const { return m_useAutomaticThreshold; }
334
342 inline vpLikelihoodThresholdType getLikelihoodThresholdType() const { return m_likelihood_threshold_type; }
343
348 void initMask(); // convolution masks - offset computation
349
353 void print();
354
360 void setAngleStep(const unsigned int &anglestep) { m_anglestep = anglestep; }
361
368 inline void setInitRange(const int &initRange) { m_init_range = initRange; }
369
377 void setMaskNumber(const unsigned int &mask_number);
378
384 void setMaskSign(const int &mask_sign) { m_mask_sign = mask_sign; }
385
393 void setMaskSize(const unsigned int &mask_size);
394
401 void setMinSampleStep(const double &min_samplestep) { m_min_samplestep = min_samplestep; }
402
408 void setMu1(const double &mu_1) { this->m_mu1 = mu_1; }
409
415 void setMu2(const double &mu_2) { this->m_mu2 = mu_2; }
416
422 void setNbTotalSample(const int &ntotal_sample) { m_ntotal_sample = ntotal_sample; }
423
431 void setPointsToTrack(const int &points_to_track) { m_points_to_track = points_to_track; }
432
438 void setRange(const unsigned int &range) { m_range = range; }
439
445 void setSampleStep(const double &sample_step) { m_sample_step = sample_step; }
446
452 void setStrip(const int &strip) { m_strip = strip; }
453
489 void setThreshold(const double &threshold) { m_threshold = threshold; }
490
500 inline void setThresholdMarginRatio(const double &thresholdMarginRatio)
501 {
502 if (thresholdMarginRatio > 1.) {
503 throw(vpException(vpException::badValue, "Threshold margin ratio must be between 0 and 1 if you want to use automatic threshold computation, or negative otherwise"));
504 }
505 m_thresholdMarginRatio = thresholdMarginRatio;
506 m_useAutomaticThreshold = (m_thresholdMarginRatio > 0) && (m_minThreshold > 0);
507 }
508
517 inline void setMinThreshold(const double &minThreshold)
518 {
519 m_minThreshold = minThreshold;
520 m_useAutomaticThreshold = (m_thresholdMarginRatio > 0) && (m_minThreshold > 0);
521 }
522
531 void setLikelihoodThresholdType(const vpLikelihoodThresholdType likelihood_threshold_type) { m_likelihood_threshold_type = likelihood_threshold_type; }
532
533private:
534 vpLikelihoodThresholdType m_likelihood_threshold_type;
536 double m_threshold;
537 double m_thresholdMarginRatio;
538 double m_minThreshold;
539 bool m_useAutomaticThreshold;
540 double m_mu1;
541 double m_mu2;
542 double m_min_samplestep;
543 unsigned int m_anglestep;
544 int m_mask_sign;
545 int m_init_range;
546 unsigned int m_range;
547 double m_sample_step;
548 int m_ntotal_sample;
549 int m_points_to_track;
551 unsigned int m_mask_size;
553 unsigned int m_mask_number;
556 int m_strip;
557 vpMatrix *m_mask;
558
559#ifdef VISP_HAVE_NLOHMANN_JSON
566 friend void to_json(nlohmann::json &j, const vpMe &me);
567
615 friend void from_json(const nlohmann::json &j, vpMe &me);
616#endif
617};
618
619#ifdef VISP_HAVE_NLOHMANN_JSON
620
621#if defined(__clang__)
622// Mute warning : declaration requires an exit-time destructor [-Wexit-time-destructors]
623// message : expanded from macro 'NLOHMANN_JSON_SERIALIZE_ENUM'
624# pragma clang diagnostic push
625# pragma clang diagnostic ignored "-Wexit-time-destructors"
626#endif
627
628NLOHMANN_JSON_SERIALIZE_ENUM(vpMe::vpLikelihoodThresholdType, {
631});
632
633#if defined(__clang__)
634# pragma clang diagnostic pop
635#endif
636
637inline void to_json(nlohmann::json &j, const vpMe &me)
638{
639 j = {
640 {"thresholdType", me.getLikelihoodThresholdType()},
641 {"threshold", me.getThreshold()},
642 {"thresholdMarginRatio", me.getThresholdMarginRatio()},
643 {"minThreshold", me.getMinThreshold()},
644 {"mu", {me.getMu1(), me.getMu2()}},
645 {"minSampleStep", me.getMinSampleStep()},
646 {"sampleStep", me.getSampleStep()},
647 {"initRange", me.getInitRange()},
648 {"range", me.getRange()},
649 {"ntotalSample", me.getNbTotalSample()},
650 {"pointsToTrack", me.getPointsToTrack()},
651 {"maskSize", me.getMaskSize()},
652 {"nMask", me.getMaskNumber()},
653 {"maskSign", me.getMaskSign()},
654 {"strip", me.getStrip()}
655 };
656}
657
658inline void from_json(const nlohmann::json &j, vpMe &me)
659{
660 if (j.contains("thresholdType")) {
661 me.setLikelihoodThresholdType(j.value("thresholdType", me.getLikelihoodThresholdType()));
662 }
663 me.setThreshold(j.value("threshold", me.getThreshold()));
664 me.setThresholdMarginRatio(j.value("thresholdMarginRatio", me.getThresholdMarginRatio()));
665 me.setMinThreshold(j.value("minThreshold", me.getMinThreshold()));
666
667 if (j.contains("mu")) {
668 std::vector<double> mus = j.at("mu").get<std::vector<double>>();
669 assert((mus.size() == 2));
670 me.setMu1(mus[0]);
671 me.setMu2(mus[1]);
672 }
673 me.setMinSampleStep(j.value("minSampleStep", me.getMinSampleStep()));
674 me.setSampleStep(j.value("sampleStep", me.getSampleStep()));
675 me.setRange(j.value("range", me.getRange()));
676 me.setInitRange(j.value("initRange", me.getInitRange()));
677 me.setNbTotalSample(j.value("ntotalSample", me.getNbTotalSample()));
678 me.setPointsToTrack(j.value("pointsToTrack", me.getPointsToTrack()));
679 me.setMaskSize(j.value("maskSize", me.getMaskSize()));
680 me.setMaskSign(j.value("maskSign", me.getMaskSign()));
681 me.setStrip(j.value("strip", me.getStrip()));
682 if (j.contains("angleStep") && j.contains("nMask")) {
683 std::cerr << "both angle step and number of masks are defined, number of masks will take precedence" << std::endl;
684 me.setMaskNumber(j["nMask"]);
685 }
686 else if (j.contains("angleStep")) {
687 me.setAngleStep(j["angleStep"]);
688 }
689 else if (j.contains("nMask")) {
690 me.setMaskNumber(j["nMask"]);
691 }
692 me.initMask();
693}
694
695#endif
696
697END_VISP_NAMESPACE
698#endif
error that can be emitted by ViSP classes.
Definition vpException.h:60
@ badValue
Used to indicate that a value is not in the allowed range.
Definition vpException.h:73
Implementation of a matrix and operations on matrices.
Definition vpMatrix.h:175
Definition vpMe.h:143
bool getUseAutomaticThreshold() const
Indicates if the contrast threshold of the vpMeSite is automatically computed.
Definition vpMe.h:333
int getMaskSign() const
Definition vpMe.h:231
void setMu1(const double &mu_1)
Definition vpMe.h:408
void setMinThreshold(const double &minThreshold)
Definition vpMe.h:517
void setPointsToTrack(const int &points_to_track)
Definition vpMe.h:431
friend void to_json(nlohmann::json &j, const vpMe &me)
Convert a vpMe object to a JSON representation.
Definition vpMe.h:637
friend void from_json(const nlohmann::json &j, vpMe &me)
Retrieve a vpMe object from a JSON representation.
Definition vpMe.h:658
void initMask()
Definition vpMe.cpp:383
vpLikelihoodThresholdType getLikelihoodThresholdType() const
Definition vpMe.h:342
double getMinSampleStep() const
Definition vpMe.h:248
void setInitRange(const int &initRange)
Definition vpMe.h:368
void setMaskSign(const int &mask_sign)
Definition vpMe.h:384
void setRange(const unsigned int &range)
Definition vpMe.h:438
void setLikelihoodThresholdType(const vpLikelihoodThresholdType likelihood_threshold_type)
Definition vpMe.h:531
void setNbTotalSample(const int &ntotal_sample)
Definition vpMe.h:422
void setAngleStep(const unsigned int &anglestep)
Definition vpMe.h:360
void setMaskNumber(const unsigned int &mask_number)
Definition vpMe.cpp:555
int getNbTotalSample() const
Definition vpMe.h:269
void setThreshold(const double &threshold)
Definition vpMe.h:489
void setStrip(const int &strip)
Definition vpMe.h:452
void checkSamplestep(double &sample_step)
Definition vpMe.h:190
unsigned int getAngleStep() const
Definition vpMe.h:202
double getThresholdMarginRatio() const
Definition vpMe.h:315
void setMinSampleStep(const double &min_samplestep)
Definition vpMe.h:401
vpMatrix * getMask() const
Definition vpMe.h:215
double getMu1() const
Definition vpMe.h:255
int getInitRange() const
Definition vpMe.h:208
unsigned int getMaskNumber() const
Definition vpMe.h:224
int getPointsToTrack() const
Definition vpMe.h:276
int getStrip() const
Definition vpMe.h:297
void setSampleStep(const double &sample_step)
Definition vpMe.h:445
vpMe()
Definition vpMe.cpp:433
double getMu2() const
Definition vpMe.h:262
double getThreshold() const
Definition vpMe.h:306
unsigned int getMaskSize() const
Definition vpMe.h:240
void setMaskSize(const unsigned int &mask_size)
Definition vpMe.cpp:563
void setThresholdMarginRatio(const double &thresholdMarginRatio)
Definition vpMe.h:500
void setMu2(const double &mu_2)
Definition vpMe.h:415
double getSampleStep() const
Definition vpMe.h:290
unsigned int getRange() const
Definition vpMe.h:283
vpLikelihoodThresholdType
Definition vpMe.h:149
@ NORMALIZED_THRESHOLD
Definition vpMe.h:154
@ OLD_THRESHOLD
Old likelihood ratio threshold (to be avoided).
Definition vpMe.h:151
double getMinThreshold() const
Definition vpMe.h:325