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/PGH.H"
00043 #include "Image/Rectangle.H"
00044 #include "Image/FilterOps.H"
00045
00046 #include <signal.h>
00047 #include <sys/types.h>
00048
00049 std::vector<PGH::Line> transform(std::vector<PGH::Line>& lines, Point2D<int> pos,
00050 float scale, float rot)
00051 {
00052 std::vector<PGH::Line> newLines = lines;
00053
00054
00055
00056
00057 Point2D<int> com(0,0);
00058 for(uint i=0; i<newLines.size(); i++)
00059 com += newLines[i].pos;
00060 com /= newLines.size();
00061
00062 for(uint i=0; i<lines.size(); i++)
00063 {
00064
00065
00066
00067 float x = scale*(newLines[i].pos.i - com.i);
00068 float y = scale*(newLines[i].pos.j - com.j);
00069 newLines[i].pos.i = com.i + int(x * cos(rot) - y * sin(rot));
00070 newLines[i].pos.j = com.j + int(y * cos(rot) + x * sin(rot));
00071
00072 newLines[i].pos += pos;
00073
00074 newLines[i].length *= scale;
00075 newLines[i].ori -= rot;
00076 }
00077
00078
00079 return newLines;
00080
00081 }
00082
00083 int main(const int argc, const char **argv)
00084 {
00085
00086 MYLOGVERB = LOG_INFO;
00087 ModelManager manager("Test SFS");
00088
00089 if (manager.parseCommandLine(
00090 (const int)argc, (const char**)argv, "", 0, 0) == false)
00091 return 1;
00092
00093 manager.start();
00094
00095
00096 PGH pgh;
00097
00098
00099 std::vector<PGH::Line> model;
00100
00101 model.push_back(PGH::Line(Point2D<int>(100, 100), 50, 0));
00102 model.push_back(PGH::Line(Point2D<int>(100, 50), 50, 0));
00103 model.push_back(PGH::Line(Point2D<int>(75, 75), 50, M_PI/2));
00104 model.push_back(PGH::Line(Point2D<int>(125, 75), 50, M_PI/2));
00105
00106
00107 model.push_back(PGH::Line(Point2D<int>(80, 40), 60, M_PI/3.7));
00108 model.push_back(PGH::Line(Point2D<int>(120, 40), 60, -M_PI/3.7));
00109
00110
00111 Image<PixRGB<byte> > img(320, 240, ZEROS);
00112 for(uint i=0; i<model.size(); i++)
00113 {
00114 drawLine(img, model[i].pos, model[i].ori, model[i].length, PixRGB<byte>(255,0,0));
00115 }
00116 SHOWIMG(img);
00117
00118
00119 std::vector<PGH::Line> newLines2 = transform(model,Point2D<int>(50,50), 1.0F, float(M_PI/8));
00120
00121 pgh.addModel(newLines2, 0);
00122
00123 for(float rot = 0; rot < 2*M_PI; rot+=10*M_PI/180)
00124 {
00125 Point2D<int> pos(50,50);
00126 float scale = 1;
00127 std::vector<PGH::Line> newLines = transform(model,pos, scale, rot);
00128
00129 img = Image<PixRGB<byte> >(320, 240, ZEROS);
00130 for(uint i=0; i<model.size(); i++)
00131 {
00132 drawLine(img, newLines[i].pos, newLines[i].ori, newLines[i].length,
00133 PixRGB<byte>(255,0,0));
00134 }
00135
00136 pgh.matchModel(newLines);
00137
00138 SHOWIMG(img);
00139 }
00140
00141
00142
00143 manager.stop();
00144
00145 return 0;
00146 }
00147