int main(int argc, char** argv) { Image img; img.LoadPPM(argv[1]); img.SetColorModel(ImageBase::cm_Grey); StructureTensor t; t.SetFromImage(img); t.FoerstnerDetector(0.0005f, img); img.SavePPM("foerstner.ppm"); Image out; t.HarrisCornerDetector(0.0001, out); out.SavePPM("harris.ppm"); return 0; }
int main(int argc, char *argv[]) { argc--; argv++; if(argc < 1) { cout << "Usage: houghTransform <input image> [resolution (optional)]" << endl; return 1; } // Load image Image src; int result = src.LoadPPM(argv[0]); if(result != 0) { cerr << "Cannot open file! " << endl; return 1; } int resolution = 1; if(argc > 1) { resolution = atoi(argv[1]); } // convert image if needed Image greySrc = src; if(src.GetColorModel() != ImageBase::cm_Grey) { ColorConversion::ToGrey(src, greySrc); } // times timeval startStandard; timeval endStandard; timeval start1Fast; timeval start2Fast; timeval endFast; // ---------- standard hough transformation ------------ vector<PrimitiveLine> lines; HoughTransform ht; gettimeofday(&startStandard, NULL); ht.StandardHoughTransform(greySrc, resolution, lines); gettimeofday(&endStandard, NULL); // save hough space FloatImage houghSpace = ht.GetHoughSpace(); Image tmp; houghSpace.GetAsGreyImage(tmp); Save(tmp, string(argv[0]) + "_standardht_houghspace.ppm"); // paint lines Image linesImg; ColorConversion::ToRGB(greySrc, linesImg); for(unsigned int i = 0; i < lines.size(); i++) { lines[i].SetColor(Color::red()); lines[i].Draw(&linesImg); } Save(linesImg, string(argv[0]) + "_standardht_lines.ppm"); // ---------- fast hough transformation ------------ cout << endl; lines.clear(); StructureTensor J; gettimeofday(&start1Fast, NULL); J.SetFromImage(greySrc); HoughTransform ht2; gettimeofday(&start2Fast, NULL); ht2.FastHoughTransform(J, resolution, lines); gettimeofday(&endFast, NULL); // save hough space houghSpace = ht2.GetHoughSpace(); houghSpace.GetAsGreyImage(tmp); Save(tmp, string(argv[0]) + "_fastht_houghspace.ppm"); // paint lines ColorConversion::ToRGB(greySrc, linesImg); for(unsigned int i = 0; i < lines.size(); i++) { lines[i].SetColor(Color::blue()); lines[i].Draw(&linesImg); } Save(linesImg, string(argv[0]) + "_fastht_lines.ppm"); // ---------- Ausgabe benoetigte Zeit ------------- timeval standard; timeval fast1, fast2; timeval_subtract(&standard, &endStandard, &startStandard); timeval_subtract(&fast1, &endFast, &start1Fast); timeval_subtract(&fast2, &endFast, &start2Fast); long msecStandard = standard.tv_sec *1000 + standard.tv_usec/1000; long msecFast1 = fast1.tv_sec *1000 + fast1.tv_usec/1000; long msecFast2 = fast2.tv_sec *1000 + fast2.tv_usec/1000; cout << endl << endl; cout << "Standard hough transformation: " << msecStandard << " msec" << endl; cout << "Fast hough transformation (with Structure Tensor calculation): " << msecFast1 << " msec" << endl; cout << "Fast hough transformation (without Structure Tensor calculation): " << msecFast2 << " msec" << endl; cout << "Fertig! " << endl; return 0; }