LFLineFitter.h
00001 
00002 
00003 
00004 
00005 
00006 
00007 
00008 
00009 
00010 
00011 
00012 
00013 
00014 
00015 
00016 
00017 
00018 
00019 
00020 
00021 
00022 
00023 
00024 
00025 #pragma once
00026 
00027 #include <stdio.h>
00028 #include <math.h>
00029 #include <iostream>
00030 #include <iomanip>
00031 #include <map>
00032 
00033 
00034 #include <opencv/cxcore.h>
00035 
00036 #include "LFLineSegment.h"
00037 
00038 
00039 #define LF_NUM_LAYER 2
00040 using namespace std;
00041 
00042 class LFLineFitter
00043 {
00044 public:
00045         LFLineFitter();
00046         ~LFLineFitter();
00047 
00048         void Init();
00049 
00050         void Configure(
00051                 double sigmaFitALine,
00052                 double sigmaFindSupport, 
00053                 double maxGap,
00054                 int nLayer,
00055                 int *nLinesToFitInStage,
00056                 int *nTrialsPerLineInStage);
00057 
00058         void Configure(const char *fileName);
00059 
00060         void FitLine(IplImage *inputImage);
00061 
00062         void DisplayEdgeMap(IplImage *inputImage,const char *outputImageName=NULL);
00063         void SaveEdgeMap(const char *filename);
00064 
00065 
00066         int     rWidth() {return width_;};
00067         int rHeight() {return height_;};
00068         int rNLineSegments() {return nLineSegments_;};
00069         LFLineSegment* rOutputEdgeMap() {return outEdgeMap_;};
00070 
00071 
00072 private:
00073 
00074         int FitALine(const int nWindPoints,CvPoint *windPoints,const double sigmaFitALine,CvPoint2D64f &lnormal);
00075         int SampleAPixel(map<int,CvPoint> *edgeMap,IplImage *inputImage,int nPixels);
00076         void FindSupport(const int nWindPoints,CvPoint *windPoints,CvPoint2D64f &lnormal,double sigmaFindSupport,double maxGap,LFLineSegment &ls,CvPoint *proposedKillingList,int &nProposedKillingList,int x0,int y0);
00077         void Find(int x0,int y0,CvPoint *windPoints,int &nWindPoints,IplImage *inputImage,int localWindSize);
00078         void Find(map<int,CvPoint> *edgeMap,int x0,int y0,CvPoint *windPoints,int &nWindPoints,IplImage *inputImage,int localWindSize);
00079         void ISort(double* ra, int nVec, int* ira);
00080         void SafeRelease();
00081 
00082 private:
00083         int width_;
00084         int height_;
00085 
00086         
00087         LFLineSegment *outEdgeMap_;
00088         int nLineSegments_;
00089         int nInputEdges_;
00090 
00091 
00092         
00093         int nLinesToFitInStage_[LF_NUM_LAYER];
00094         int nTrialsPerLineInStage_[LF_NUM_LAYER];
00095         double sigmaFitALine_;
00096         double sigmaFindSupport_;
00097         double maxGap_;
00098         int minLength_;
00099 
00100 
00101         
00102         int nMaxWindPoints_;
00103         int nMinEdges_;
00104         int localWindSize_;
00105         int smallLocalWindowSize_;
00106 
00107         
00108         CvPoint *rpoints_;
00109         double *rProjection_;
00110         double *absRProjection_;
00111         int *idx_;
00112 };