chromaticmask.h
Go to the documentation of this file.
00001 /*****************************
00002 Copyright 2011 Rafael Muñoz Salinas. All rights reserved.
00003 
00004 Redistribution and use in source and binary forms, with or without modification, are
00005 permitted provided that the following conditions are met:
00006 
00007    1. Redistributions of source code must retain the above copyright notice, this list of
00008       conditions and the following disclaimer.
00009 
00010    2. Redistributions in binary form must reproduce the above copyright notice, this list
00011       of conditions and the following disclaimer in the documentation and/or other materials
00012       provided with the distribution.
00013 
00014 THIS SOFTWARE IS PROVIDED BY Rafael Muñoz Salinas ''AS IS'' AND ANY EXPRESS OR IMPLIED
00015 WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
00016 FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL Rafael Muñoz Salinas OR
00017 CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
00018 CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
00019 SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
00020 ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
00021 NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
00022 ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00023 
00024 The views and conclusions contained in the software and documentation are those of the
00025 authors and should not be interpreted as representing official policies, either expressed
00026 or implied, of Rafael Muñoz Salinas.
00027 ********************************/
00028 
00029 #ifndef CHROMATICMASK_H
00030 #define CHROMATICMASK_H
00031 
00032 #include <opencv2/core/core.hpp>
00033 #include <opencv2/ml/ml.hpp>
00034 #include <opencv2/calib3d/calib3d.hpp>
00035 #include <opencv2/highgui/highgui.hpp>
00036 #include <opencv2/imgproc/imgproc.hpp>
00037 #include <opencv2/ml/ml.hpp>
00038 #include "exports.h"
00039 #include "board.h"
00040 #include "boarddetector.h"
00041 #include "cvdrawingutils.h"
00042 
00043 
00044 class ARUCO_EXPORTS EMClassifier {
00045   public:
00046     EMClassifier(unsigned int nelements = 200);
00047     void addSample(uchar s) { _samples.push_back(s); };
00048     void clearSamples() { _samples.clear(); };
00049     void train();
00050     bool classify(uchar s) { return _inside[s]; };
00051     double getProb(uchar s) { return _prob[s]; };
00052     unsigned int numsamples() { return _samples.size(); };
00053     void setProb(double p) { _threshProb = p; }
00054 
00055     //   double probConj[256];
00056 
00057   private:
00058 #ifdef OPENCV_VERSION_3
00059     cv::Ptr< cv::ml::EM > _classifier;
00060 #else
00061     cv::EM _classifier;
00062 #endif
00063     vector< uchar > _samples;
00064     bool _inside[256];
00065     double _prob[256];
00066     double _histogram[256];
00067     unsigned int _nelem;
00068     double _threshProb;
00069 };
00070 
00071 
00072 class ARUCO_EXPORTS ChromaticMask {
00073   public:
00074     ChromaticMask() : _cellSize(20) { _isValid = false; };
00075 
00076     void setParams(unsigned int mc, unsigned int nc, double threshProb, aruco::CameraParameters CP, aruco::BoardConfiguration BC,
00077                    vector< cv::Point3f > corners);
00078     void setParams(unsigned int mc, unsigned int nc, double threshProb, aruco::CameraParameters CP, aruco::BoardConfiguration BC, float markersize = -1.);
00079 
00080     void calculateGridImage(const aruco::Board &board);
00081 
00082     cv::Mat getCellMap() { return _cellMap; };
00083     cv::Mat getMask() { return _mask; };
00084 
00085     void train(const cv::Mat &in, const aruco::Board &board);
00086     void classify(const cv::Mat &in, const aruco::Board &board);
00087     void classify2(const cv::Mat &in, const aruco::Board &board);
00088     void update(const cv::Mat &in);
00089 
00090     bool isValid() { return _isValid; };
00091     void resetMask();
00092 
00093   private:
00094     double getDistance(cv::Point2d pixel, unsigned int classifier) {
00095         cv::Vec2b canPos = _canonicalPos.at< cv::Vec2b >(pixel.y, pixel.x)[0];
00096         return norm(_cellCenters[classifier] - cv::Point2f(canPos[0], canPos[1]));
00097     }
00098 
00099     vector< cv::Point2f > _imgCornerPoints;
00100     vector< cv::Point3f > _objCornerPoints;
00101     cv::Mat _perpTrans;
00102     vector< EMClassifier > _classifiers;
00103     vector< cv::Point2f > _centers;
00104     vector< cv::Point2f > _pixelsVector;
00105     vector< cv::Point2f > _cellCenters;
00106     vector< vector< size_t > > _cell_neighbours;
00107     const float _cellSize;
00108 
00109 
00110     unsigned int _mc, _nc;
00111     aruco::BoardDetector _BD;
00112     aruco::CameraParameters _CP;
00113     cv::Mat _canonicalPos, _cellMap, _mask, _maskAux;
00114     bool _isValid;
00115     double _threshProb;
00116 };
00117 
00118 #endif // CHROMATICMASK_H


asr_aruco_marker_recognition
Author(s): Allgeyer Tobias, Meißner Pascal, Qattan Mohamad
autogenerated on Thu Jun 6 2019 21:14:12