LFLineFitter.h

00001 /*
00002 Copyright 2010, Ming-Yu Liu
00003 
00004 All Rights Reserved 
00005 
00006 Permission to use, copy, modify, and distribute this software and 
00007 its documentation for any non-commercial purpose is hereby granted 
00008 without fee, provided that the above copyright notice appear in 
00009 all copies and that both that copyright notice and this permission 
00010 notice appear in supporting documentation, and that the name of 
00011 the author not be used in advertising or publicity pertaining to 
00012 distribution of the software without specific, written prior 
00013 permission. 
00014 
00015 THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, 
00016 INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 
00017 ANY PARTICULAR PURPOSE. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 
00018 ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 
00019 WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN 
00020 AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING 
00021 OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 
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 //#include <opencv/highgui.h>
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         // Output
00087         LFLineSegment *outEdgeMap_;
00088         int nLineSegments_;
00089         int nInputEdges_;
00090 
00091 
00092         // Fitting parameters
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         // Program parameters
00102         int nMaxWindPoints_;
00103         int nMinEdges_;
00104         int localWindSize_;
00105         int smallLocalWindowSize_;
00106 
00107         // temporary storage use
00108         CvPoint *rpoints_;
00109         double *rProjection_;
00110         double *absRProjection_;
00111         int *idx_;
00112 };
Generated on Sun May 8 08:41:09 2011 for iLab Neuromorphic Vision Toolkit by  doxygen 1.6.3