TestMicroEdgeCorrectionTable.cpp
Go to the documentation of this file.
00001 #include "EdgeDetection/AdaptiveRasterizer.h"
00002 #include "EdgeDetection/MicroEdgeDetector.h"
00003 #include "EdgeDetection/MicroEdgeCorrectionTable.h"
00004 #include "EdgeDetection/EdgeImage.h"
00005 #include "EdgeDetection/Image.h"
00006 
00007 #include <iostream>
00008 #include <fstream>
00009 #include <cmath>
00010 #include <stdlib.h>
00011 #include <time.h>
00012 
00013 using namespace std;
00014 using namespace EdgeDetection;
00015 
00016 double MeasureError(Rasterizer* rasterizer, MicroEdgeDetector* microEdgeDetector, MicroEdgeCorrectionTable* microEdgeCorrectionTable, Edge realEdge)
00017 {
00018         EdgeImage* realEdgeImage = new EdgeImage(Line::FromEdge(realEdge), Rectangle(-1, +1, -1, +1));
00019         Image* realImage = rasterizer->Rasterize(realEdgeImage, 5, 5);
00020         Edge measuredEdge = microEdgeDetector->DetectEdge(realImage);
00021         Edge correctedEdge = microEdgeCorrectionTable->Correct(measuredEdge);
00022 
00023         delete realEdgeImage;
00024         delete realImage;
00025 
00026         double error = Edge::GetDistance(realEdge, correctedEdge);
00027 
00028 /*
00029         if (error > 0.1)
00030         {
00031                 cout << "Real: [" << realEdge.GetOffset() << ", " << realEdge.GetAngle() << "]" << endl;
00032                 cout << "Measured: [" << measuredEdge.GetOffset() << ", " << measuredEdge.GetAngle() << "]" << endl;
00033                 cout << "Corrected: [" << correctedEdge.GetOffset() << ", " << correctedEdge.GetAngle() << "]" << endl;
00034                 cout << "Error: " << error << endl;
00035                 cout << endl;
00036         }
00037 */
00038 
00039         return error;
00040 }
00041 double NextDouble()
00042 {
00043         return (double)rand() / (double)RAND_MAX;
00044 }
00045 
00046 int main(int argc, char** argv)
00047 {
00048         cout << "Creating Rasterizer (fine)..." << endl;
00049         Rasterizer* rasterizerFine = new AdaptiveRasterizer(0.00000001);
00050         cout << "Creating MicroEdgeDetector..." << endl;
00051         MicroEdgeDetector* microEdgeDetector = new MicroEdgeDetector(rasterizerFine, 5);
00052         cout << "Loading MicroEdgeCorrectionTable..." << endl;
00053         ifstream microEdgeCorrectionTableFile("MicroEdgeCorrectionTable.bin", ifstream::in | ifstream::binary);
00054         MicroEdgeCorrectionTable* microEdgeCorrectionTable = MicroEdgeCorrectionTable::Deserialize(&microEdgeCorrectionTableFile);
00055         microEdgeCorrectionTableFile.close();
00056         cout << endl;
00057 
00058         cout << "Generating error statistics..." << endl;
00059 
00060         double errorMinimum = -1;
00061         double errorMaximum = -1;
00062         double errorSum = 0;
00063 
00064         srand(time(NULL));
00065 
00066         int sampleCount = 10000;
00067 
00068         for (int i = 0; i < sampleCount; i++)
00069         {
00070                 Edge realEdge = Edge((1.2 * NextDouble()) - 0.6, (2 * M_PI * NextDouble()) - M_PI);
00071 
00072                 double error = MeasureError(rasterizerFine, microEdgeDetector, microEdgeCorrectionTable, realEdge);
00073 
00074                 if (errorMinimum == -1 || error < errorMinimum) errorMinimum = error;
00075                 if (errorMaximum == -1 || error > errorMaximum) errorMaximum = error;
00076                 errorSum += error;
00077         }
00078 
00079         double errorAverage = errorSum / sampleCount;
00080 
00081         cout << "Errors: Minimum: " << errorMinimum << ", Maximum: " << errorMaximum << ", Average: " << errorAverage << endl;
00082 
00083         delete rasterizerFine;
00084         delete microEdgeDetector;
00085         delete microEdgeCorrectionTable;
00086 
00087         return 0;
00088 }


aruco_pose
Author(s): Julian Brunner
autogenerated on Mon Oct 6 2014 08:32:34