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 00026 #pragma once 00027 #include <iostream> 00028 #include <iomanip> 00029 #include <string> 00030 #include <stdio.h> 00031 #include "plugins/SceneUnderstanding/EIEdgeImage/EIEdgeImage.h" 00032 #include "plugins/SceneUnderstanding/LFLineFitter/LFLineFitter.h" 00033 #include "LMDistanceImage.h" 00034 00035 00036 00037 class LMLineMatcher { 00038 public: 00039 LMLineMatcher(); 00040 ~LMLineMatcher(); 00041 00042 struct Rect 00043 { 00044 int x; 00045 int y; 00046 int width; 00047 int height; 00048 double distance; 00049 00050 Rect(int inX, int inY, int w, int h, double d) : 00051 x(inX), y(inY), width(w), height(h), distance(d) 00052 {} 00053 }; 00054 00055 // Initialization 00056 void Configure(const char* fileName); 00057 void Init(const char* fileName,double db_scale=1.0); 00058 //void Match(LFLineFitter &lf); 00059 std::vector<Rect> Match(int width, int height, int nLines, LFLineSegment* linesSegment); 00060 00061 void GetColorImage(string filename) {imageName_ = filename;}; 00062 00063 double getCost(EIEdgeImage& tbImage, double ltrans[2], double factor, int& count); 00064 double getCost(int directionIdx, int sx, int sy, int ex, int ey, int count) const; 00065 00066 void computeIDT3(int width, int height, int nLines, LFLineSegment* linesSegment); 00067 00068 00069 private: 00070 00071 double MatchBruteForce(EIEdgeImage& dbImage, int index, int* iindices, int* indices, int* xIndex, int* yIndex, double* dIndex, double* sIndex, double* distances, int& counter, double& minCost); 00072 void DrawDetWind(IplImage *image,int x,int y,int detWindWidth,int detWindHeight,CvScalar scalar=cvScalar(0,255,0),int thickness=2); 00073 void DrawMatchTemplate(IplImage *image,EIEdgeImage &ei,int x,int y,double scale,CvScalar scalar=cvScalar(0,255,255),int thickness=1); 00074 void ISort(double* ra, int nVec, int* ira); 00075 void SafeRelease(); 00076 00077 00078 private: 00079 00080 // temporary structures 00081 double* distances_; 00082 int* indices_; 00083 int* xIndices_; 00084 int* yIndices_; 00085 double* sIndices_; 00086 double* dIndices_; 00087 int* iindices_; 00088 int* wIndices_; 00089 int* hIndices_; 00090 double scale_; 00091 EIEdgeImage* dbImages_; 00092 00093 // tempaltes 00094 int ndbImages_; 00095 LMDistanceImage queryDistanceImage_; 00096 00097 // test image 00098 string imageName_; 00099 EIEdgeImage queryImage_; 00100 00101 00102 // Matching parameter 00103 int nDirections_; 00104 double maxCost_; 00105 float directionCost_; 00106 00107 double db_scale_; 00108 00109 double baseSearchScale_; 00110 double minSearchScale_; 00111 double maxSearchScale_; 00112 00113 int searchStepSize_; 00114 int searchBoundarySize_; 00115 double minCostRatio_; 00116 };