chromaticmask.h
Go to the documentation of this file.
1 /*****************************
2 Copyright 2011 Rafael Muñoz Salinas. All rights reserved.
3 
4 Redistribution and use in source and binary forms, with or without modification, are
5 permitted provided that the following conditions are met:
6 
7  1. Redistributions of source code must retain the above copyright notice, this list of
8  conditions and the following disclaimer.
9 
10  2. Redistributions in binary form must reproduce the above copyright notice, this list
11  of conditions and the following disclaimer in the documentation and/or other materials
12  provided with the distribution.
13 
14 THIS SOFTWARE IS PROVIDED BY Rafael Muñoz Salinas ''AS IS'' AND ANY EXPRESS OR IMPLIED
15 WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
16 FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL Rafael Muñoz Salinas OR
17 CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
18 CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
19 SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
20 ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
21 NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
22 ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
23 
24 The views and conclusions contained in the software and documentation are those of the
25 authors and should not be interpreted as representing official policies, either expressed
26 or implied, of Rafael Muñoz Salinas.
27 ********************************/
28 
29 #ifndef CHROMATICMASK_H
30 #define CHROMATICMASK_H
31 
32 #include <opencv2/core/core.hpp>
33 #include <opencv2/ml/ml.hpp>
34 #include <opencv2/calib3d/calib3d.hpp>
35 #include <opencv2/highgui/highgui.hpp>
36 #include <opencv2/imgproc/imgproc.hpp>
37 #include <opencv2/ml/ml.hpp>
38 #include "exports.h"
39 #include "board.h"
40 #include "boarddetector.h"
41 #include "cvdrawingutils.h"
42 
43 
45  public:
46  EMClassifier(unsigned int nelements = 200);
47  void addSample(uchar s) { _samples.push_back(s); };
48  void clearSamples() { _samples.clear(); };
49  void train();
50  bool classify(uchar s) { return _inside[s]; };
51  double getProb(uchar s) { return _prob[s]; };
52  unsigned int numsamples() { return _samples.size(); };
53  void setProb(double p) { _threshProb = p; }
54 
55  // double probConj[256];
56 
57  private:
58 #ifdef OPENCV_VERSION_3
59  cv::Ptr< cv::ml::EM > _classifier;
60 #else
61  cv::EM _classifier;
62 #endif
63  vector< uchar > _samples;
64  bool _inside[256];
65  double _prob[256];
66  double _histogram[256];
67  unsigned int _nelem;
68  double _threshProb;
69 };
70 
71 
73  public:
74  ChromaticMask() : _cellSize(20) { _isValid = false; };
75 
76  void setParams(unsigned int mc, unsigned int nc, double threshProb, aruco::CameraParameters CP, aruco::BoardConfiguration BC,
77  vector< cv::Point3f > corners);
78  void setParams(unsigned int mc, unsigned int nc, double threshProb, aruco::CameraParameters CP, aruco::BoardConfiguration BC, float markersize = -1.);
79 
80  void calculateGridImage(const aruco::Board &board);
81 
82  cv::Mat getCellMap() { return _cellMap; };
83  cv::Mat getMask() { return _mask; };
84 
85  void train(const cv::Mat &in, const aruco::Board &board);
86  void classify(const cv::Mat &in, const aruco::Board &board);
87  void classify2(const cv::Mat &in, const aruco::Board &board);
88  void update(const cv::Mat &in);
89 
90  bool isValid() { return _isValid; };
91  void resetMask();
92 
93  private:
94  double getDistance(cv::Point2d pixel, unsigned int classifier) {
95  cv::Vec2b canPos = _canonicalPos.at< cv::Vec2b >(pixel.y, pixel.x)[0];
96  return norm(_cellCenters[classifier] - cv::Point2f(canPos[0], canPos[1]));
97  }
98 
99  vector< cv::Point2f > _imgCornerPoints;
100  vector< cv::Point3f > _objCornerPoints;
101  cv::Mat _perpTrans;
102  vector< EMClassifier > _classifiers;
103  vector< cv::Point2f > _centers;
104  vector< cv::Point2f > _pixelsVector;
105  vector< cv::Point2f > _cellCenters;
106  vector< vector< size_t > > _cell_neighbours;
107  const float _cellSize;
108 
109 
110  unsigned int _mc, _nc;
113  cv::Mat _canonicalPos, _cellMap, _mask, _maskAux;
114  bool _isValid;
115  double _threshProb;
116 };
117 
118 #endif // CHROMATICMASK_H
cv::Mat getMask()
Definition: chromaticmask.h:83
#define ARUCO_EXPORTS
Definition: exports.h:42
const float _cellSize
vector< EMClassifier > _classifiers
aruco::BoardDetector _BD
unsigned int _nc
double getDistance(cv::Point2d pixel, unsigned int classifier)
Definition: chromaticmask.h:94
vector< cv::Point2f > _pixelsVector
cv::Mat getCellMap()
Definition: chromaticmask.h:82
void update(const std::string &key, const XmlRpc::XmlRpcValue &v)
vector< cv::Point3f > _objCornerPoints
vector< cv::Point2f > _cellCenters
This class detects AR boards Version 1.2 There are two modes for board detection. First...
Definition: boarddetector.h:64
vector< cv::Point2f > _imgCornerPoints
Definition: chromaticmask.h:99
unsigned int numsamples()
Definition: chromaticmask.h:52
bool classify(uchar s)
Definition: chromaticmask.h:50
cv::Mat _perpTrans
double _threshProb
double _threshProb
Definition: chromaticmask.h:68
Parameters of the camera.
void clearSamples()
Definition: chromaticmask.h:48
vector< uchar > _samples
Definition: chromaticmask.h:63
This class defines a board with several markers. A Board contains several markers so that they are mo...
Definition: board.h:69
double getProb(uchar s)
Definition: chromaticmask.h:51
void addSample(uchar s)
Definition: chromaticmask.h:47
void setProb(double p)
Definition: chromaticmask.h:53
cv::Mat _maskAux
vector< vector< size_t > > _cell_neighbours
unsigned int _nelem
Definition: chromaticmask.h:67
aruco::CameraParameters _CP
cv::EM _classifier
Definition: chromaticmask.h:61
vector< cv::Point2f > _centers


asr_aruco_marker_recognition
Author(s): Allgeyer Tobias, Meißner Pascal, Qattan Mohamad
autogenerated on Mon Feb 28 2022 21:41:30