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 "exports.h"
00038 #include "board.h"
00039 #include "boarddetector.h"
00040 #include "cvdrawingutils.h"
00041 
00042 
00043 class ARUCO_EXPORTS EMClassifier {
00044 public:
00045   EMClassifier(unsigned int nelements=200);
00046   void addSample(uchar s) { _samples.push_back(s); };
00047   void clearSamples() { _samples.clear();  } ;
00048   void train();
00049   bool classify(uchar s) { return _inside[s]; };
00050   double getProb(uchar s) { return _prob[s]; };
00051   unsigned int numsamples() {return _samples.size();};
00052   void setProb(double p) { _threshProb = p; }
00053   
00054 //   double probConj[256];
00055   
00056 private:
00057   cv::EM _classifier;
00058   vector<uchar> _samples;
00059   bool _inside[256];
00060   double _prob[256];
00061   double _histogram[256];
00062   unsigned int _nelem;
00063   double _threshProb;
00064 
00065 };
00066 
00067 
00068 class ARUCO_EXPORTS ChromaticMask
00069 {
00070 public:
00071   
00072   ChromaticMask() : _cellSize(20) { _isValid=false; };
00073   
00074   void setParams(unsigned int mc, unsigned int nc, double threshProb, aruco::CameraParameters CP, aruco::BoardConfiguration BC, vector<cv::Point3f> corners);
00075   void setParams(unsigned int mc, unsigned int nc, double threshProb, aruco::CameraParameters CP, aruco::BoardConfiguration BC, float markersize=-1.);
00076   
00077   void calculateGridImage(const aruco::Board &board);
00078   
00079   cv::Mat getCellMap() { return _cellMap; };
00080   cv::Mat getMask() { return _mask; };
00081   
00082   void train(const cv::Mat& in, const aruco::Board &board);
00083   void classify(const cv::Mat& in, const aruco::Board &board);
00084   void classify2(const cv::Mat& in, const aruco::Board &board);
00085   void update(const cv::Mat& in);
00086   
00087   bool isValid() {return _isValid;};
00088   void resetMask();
00089   
00090 private:
00091   
00092   double getDistance(cv::Point2d pixel, unsigned int classifier) {
00093     cv::Vec2b canPos = _canonicalPos.at<cv::Vec2b>(pixel.y, pixel.x)[0];
00094     return norm(_cellCenters[classifier] - cv::Point2f(canPos[0], canPos[1]) );
00095   }
00096   
00097   vector<cv::Point2f> _imgCornerPoints;  
00098   vector<cv::Point3f> _objCornerPoints;
00099   cv::Mat _perpTrans;
00100   vector<EMClassifier> _classifiers;
00101   vector<cv::Point2f> _centers;
00102   vector<cv::Point2f> _pixelsVector;
00103   vector<cv::Point2f> _cellCenters;
00104   vector<vector<size_t> > _cell_neighbours;
00105   const float _cellSize;
00106 
00107   
00108   unsigned int _mc, _nc;
00109   aruco::BoardDetector _BD;
00110   aruco::CameraParameters _CP;
00111   cv::Mat _canonicalPos, _cellMap, _mask,_maskAux;
00112   bool _isValid;
00113   double _threshProb;
00114 
00115 
00116   
00117 };
00118 
00119 #endif // CHROMATICMASK_H


ar_sys
Author(s): Hamdi Sahloul , Rafael Muñoz Salinas , Bence Magyar
autogenerated on Thu Aug 27 2015 12:23:55