test-FDCM.C
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
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038 #include "Image/Image.H"
00039 #include "Component/ModelManager.H"
00040 #include "Raster/Raster.H"
00041 #include "GUI/DebugWin.H"
00042 #include "FeatureMatching/GHough.H"
00043 #include "FeatureMatching/OriChamferMatching.H"
00044 #include "Image/Rectangle.H"
00045 #include "Image/FilterOps.H"
00046
00047 #include <signal.h>
00048 #include <sys/types.h>
00049
00050 int main(const int argc, const char **argv)
00051 {
00052
00053 MYLOGVERB = LOG_INFO;
00054 ModelManager manager("Test FDCM");
00055
00056 if (manager.parseCommandLine(
00057 (const int)argc, (const char**)argv, "", 0, 0) == false)
00058 return 1;
00059
00060 manager.start();
00061
00062
00063
00064
00065
00066
00067 for(float ori=360; ori>10; ori-=10)
00068 {
00069 Image<PixRGB<byte> > inputImg(320,240,ZEROS);
00070 Point2D<int> pos(100,100);
00071 float len=50;
00072 float x1 = cos(ori*M_PI/180)*len/2;
00073 float y1 = sin(ori*M_PI/180)*len/2;
00074
00075 Point2D<float> p1(pos.i-x1, pos.j+y1);
00076 Point2D<float> p2(pos.i+x1, pos.j-y1);
00077
00078 drawLine(inputImg, (Point2D<int>)p1, (Point2D<int>)p2, PixRGB<byte>(255,0,0));
00079
00080
00081
00082 std::vector<Line> lines;
00083 lines.push_back(Line(p1,p2));
00084 OriChamferMatching matcher(lines,
00085 60,
00086 2.5,
00087 inputImg.getDims());
00088
00089
00090
00091
00092
00093
00094
00095 Image<float> costImg(inputImg.getDims(), NO_INIT);
00096 costImg.clear(1e10);
00097 for(int y=0; y<inputImg.getHeight(); y++)
00098 {
00099 for(int x=0; x<inputImg.getWidth(); x++)
00100 {
00101 for(int ori=0; ori < 360; ori++)
00102 {
00103 Point2D<int> pos(x,y);
00104 float len=50;
00105 float x1 = cos((ori)*M_PI/180)*len/2;
00106 float y1 = sin((ori)*M_PI/180)*len/2;
00107
00108 Point2D<float> p1(pos.i-x1, pos.j+y1);
00109 Point2D<float> p2(pos.i+x1, pos.j-y1);
00110
00111 Polygon model;
00112 model.addLine(Line(p1,p2));
00113 model.quantize(60);
00114
00115 for(uint i=0; i<model.getNumLines(); i++)
00116 {
00117 Line l = model.getLine(i);
00118
00119 float sum = matcher.getCost(l.getDirectionIdx(), Point2D<int>(l.getP1()), Point2D<int>(l.getP2()));
00120
00121
00122 if (sum < costImg.getVal(x,y))
00123 costImg.setVal(x,y,sum);
00124 }
00125 }
00126 }
00127 LINFO("Y %i", y);
00128 }
00129 SHOWIMG(costImg);
00130
00131
00132
00133 }
00134
00135
00136
00137
00138 manager.stop();
00139
00140 return 0;
00141 }
00142