Jafar
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines
lineSegment.hpp
00001 #ifndef LINE_SEGMENT
00002 #define LINE_SEGMENT
00003 
00004 #include <cmath>
00005 #include <vector>
00006 
00007 #include <image/Image.hpp>
00008 
00009 #include "lines/histogram.hpp"
00010 #include "lines/lsMisc.hpp"
00011 #include "lines/lineSegmentSet.hpp"
00012 #include "lines/lsPredictor2D.hpp"
00013 
00014 
00015 namespace jafar{
00016   namespace lines{
00017     
00018     class LineSegmentSet;
00019 
00021 
00036     class LineSegment{
00037       public:
00039 
00042         LineSegment();
00043       
00045 
00049         LineSegment(int _numberOfNeighbours);
00050         
00052         LineSegment(const LineSegment& ls);
00053         
00055         ~LineSegment();
00056         
00058 
00074         static bool calcSupportingLine(double x1, double y1, double x2, double y2, double& alpha, double& y0);
00075         
00077 
00089         static bool calcEndpointsOfSupportingLine(double alpha, double y0, int height, int width, double& x1, double& y1, double& x2, double& y2);
00090         
00092 
00095         static double mahaDistLines(LineSegment &lA, LineSegment &lB, double varEP, double varDir, double varGrey, double varVGrey);
00096     
00098 
00105         void extractGreyscale(jafar::image::Image* image, int parallel_flag=0);
00106         
00108 
00117         void extractGradientscale(jafar::image::Image* image, int gradientimage, int parallel_flag=0);
00118         
00120 
00129         void extractLaplacescale(jafar::image::Image* image, int laplaceimage, int parallel_flag=0);
00130         
00132 
00139         void setPoints(double _x1, double _y1, double _x2, double _y2, bool resetFlag=1); 
00140         
00142         LineSegment& operator=(const LineSegment &ls);
00143         
00145 
00151         void setNumberOfNeighbours(int number);
00152         
00154 
00159         double assignContourPts(jafar::image::Image* image);
00160     
00162 
00165         void changePointOrder();
00166         
00168 
00173         void orientLine(jafar::image::Image* image);
00174     
00176 
00180         void calcHistogramDescriptor(jafar::image::Image* image,int nParallels=1, int d=3, jafar::image::Image* colorImage=0);
00181         
00183 
00186         void calcHistogramDescriptor();
00187         
00189 
00192         void normaliseHistogramDescriptor();
00193 
00195 
00198         void calcGreyspaceDescriptor(jafar::image::Image* image);
00199     
00201 
00204         static double compareGreyspace( std::vector<int>& greyA, std::vector<int>& greyB);
00205         
00207 
00210         static double compareAvLR(LineSegment& lsA, LineSegment& lsB);
00211         
00213 
00221         bool fitLine(jafar::image::Image* image, int gradientimage = 0, int nPoints=20, int pDist=25, jafar::image::Image* colorImage=0);
00222         
00224 
00236         int fitLineCandidates(jafar::image::Image* image, int gradientimage,std::vector<CvPoint>& startPts, std::vector<CvPoint>& endPts, int nPoints, int pDist, int nIter, jafar::image::Image* colorImage);
00237         
00239 
00254         bool fitLineOrientation(LineSegmentSet& lsSet, jafar::image::Image* gradX, jafar::image::Image* gradY, int nPoints=10, int pDist=25, double aDist=M_PI*0.5, double minLength=0, double extend=0, jafar::image::Image* colorImage=0);
00255       
00257 
00262         void searchGradMax(CvPoint p1, CvPoint p2, std::vector<CvPoint>& points, std::vector<double>& pointGrads, jafar::image::Image* gradX, jafar::image::Image* gradY, int nPoints, double pDist);
00263       
00265 
00269         void interpolateLineRansac(std::vector<LineSegment> lines, std::vector<CvPoint>& points, std::vector<double>& pointGrads, jafar::image::Image* gradX, jafar::image::Image* gradY, int nPoints, int nIt, double minInlierRate, double minLength, jafar::image::Image* colorImage);
00270       
00272 
00275         void interpolateLineGrowline(std::vector<LineSegment>& lines, std::vector<CvPoint>& points, std::vector<double>& pointGrads, jafar::image::Image* gradX, jafar::image::Image* gradY, int nPoints, double minLength,double aDist, jafar::image::Image* colorImage);
00276     
00278 
00283         static double chi2TestLocalPolarCOS(LineSegment &lsA, LineSegment &lsB, double* pDiffRho=0);
00284 
00285         
00287 
00291         static int tryMergeLinesChiSq(LineSegment &lA, LineSegment &lB, double maxGap=0);
00292         
00294 
00298         static void mergeLinesProb(LineSegment& lsA, LineSegment& lsB);
00299         
00301 
00306         static int mergeLinesEP(LineSegment& lsA, LineSegment& lsB);
00307         
00309 
00312         static double sizeOfGap(LineSegment& lsA, LineSegment& lsB);
00313         
00315 
00318         double getEPPredictionByRhoThetaPrediction(double x1Old, double y1Old, double x2Old, double y2Old, double& x1Pred, double& y1Pred, double& x2Pred, double& y2Pred);
00319         
00321 
00324         double getEPPrediction(double& _x1Pred, double& _y1Pred, double& _x2Pred, double& _y2Pred);
00325 
00326         
00328 
00335         bool growLineParallel(jafar::image::Image* image, int dist=3, int thresh=5, int distThresh=20);
00336         
00338 
00341         bool growLine( jafar::image::Image* image, int gapThresh=1, int thresh=40, int maxOffset=2);
00342     
00343         
00344         void drawLine(jafar::image::Image* image, CvScalar color, int width=1);
00345       
00346         unsigned int getId(){return id;}  
00347         double getX1(){return x1;}  
00348         double getY1(){return y1;}  
00349         double getX2(){return x2;}  
00350         double getY2(){return y2;}  
00351         double getMx(){return mx;}  
00352         double getMy(){return my;}  
00353         double getAlpha(){return alpha;}  
00354         double getOAlpha(){return oAlpha;}  
00355         double getEucLength(){return eucLength;}  
00356       
00357         bool isValid(){return validFlag;}   
00358         void setValid(){validFlag=1;}       
00359         void setInvalid(){validFlag=0;}     
00360       
00361         int length; 
00362       
00363         CvScalar color; 
00364     
00365         std::vector<int> greyscale;      
00366         std::vector<int> gradientscale;  
00367         std::vector<int> laplacescale;   
00368     
00369         int numberOfNeighbours;   
00370     
00371         LineSegment **parallels;  
00372       
00373         jafar::lines::Histogram* histogramB;    
00374         jafar::lines::Histogram* histogramD;    
00375       
00376       
00377         std::vector<int> greyspace;    
00378         std::vector<int> greyspaceL;   
00379         std::vector<int> greyspaceR;   
00380       
00381         double avL;   
00382         double avR;   
00383         double varL;  
00384         double varR;  
00385     
00386       // values for polar coordinates and covariance matrix for polar coordinates
00387         double polarD;      
00388         double polarAlpha;  
00389         double covDD;       
00390         double covAA;       
00391         double covAD;       
00392       
00393         double covXX;       
00394         double covXY;       
00395         double covYY;       
00396         double covAlpha;    
00397         double covXA;       
00398         double covYA;       
00399       
00400         double covXX_M;     
00401         double covXY_M;     
00402         double covYY_M;     
00403         double covXA_M;     
00404         double covYA_M;     
00405       
00406         double u;           
00407         double v;           
00408       
00409         uint id;    
00410       
00411         std::vector<std::vector<CvPoint> > contourPoints;   
00412         int param1;                   
00413         std::vector<int> parameters;  
00414       
00415         jafar::lines::LsPredictor2D predictor;  
00416       
00418 
00429         void setPredictionPolar(double rho, double theta, double covRR, double covRT, double covTT){
00430           rhoPred = rho;
00431           thetaPred = theta;
00432           covRRpred = covRR;
00433           covRTpred = covRT;
00434           covTTpred = covTT;
00435           predFlag = 1;
00436 
00437         }
00438         
00439         double rhoPred;     
00440         double thetaPred;   
00441         double covRRpred;   
00442         double covRTpred;   
00443         double covTTpred;   
00444         bool predFlag;      
00445         
00447 
00462         void setPrediction(double x1P, double y1P, double x2P, double y2P, double cov1xxP, double cov1xyP, double cov1yyP, double cov2xxP, double cov2xyP, double cov2yyP);
00463         
00464 
00465         
00466         double x1Pred;  
00467         double y1Pred;  
00468         double x2Pred;  
00469         double y2Pred;  
00470         double rangePred; 
00471         
00472       private:
00473         bool validFlag;
00474         double x1;      
00475         double y1;      
00476         double x2;      
00477         double y2;      
00478         double mx;      
00479         double my;      
00480         double slope;   
00481         double eucLength;   
00482         double alpha;   
00483         double oAlpha;  
00484     };
00485   } // namespace lines
00486 } // namespace jafar
00487 #endif
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines

Generated on Wed Oct 15 2014 00:37:25 for Jafar by doxygen 1.7.6.1
LAAS-CNRS