void Test::RunCannyTest(const RGBImage* in) { Gaussian smoother; Sobel sobel; Canny canny; StudentPreProcessing converter; double sigma = 1.6; int kernelSize = 5; // Convert RGB to Intensity IntensityImage* grey = ImageFactory::newIntensityImage(in->getWidth(), in->getHeight()); grey = converter.stepToIntensityImage(*in); BaseTimer timer; int total = 0; for (int i = 0; i < 10; ++i) { timer.start(); /* Start of Canny */ // 1. Smooth Intensity with Gaussian IntensityImage* gaussian = ImageFactory::newIntensityImage(in->getWidth() - kernelSize, in->getHeight() - kernelSize); smoother.smoothImage(grey, gaussian, sigma, kernelSize); // 2. Find edges with Sobel (convolve X and Y separately for Canny) int sobelKernelSize = 3; IntensityImage* sobelX = ImageFactory::newIntensityImage(gaussian->getWidth() - sobelKernelSize, gaussian->getHeight() - sobelKernelSize); IntensityImage* sobelY = ImageFactory::newIntensityImage(gaussian->getWidth() - sobelKernelSize, gaussian->getHeight() - sobelKernelSize); sobel.filterXY(gaussian, sobelX, sobelY); // 3. Apply non-maximum suppresion IntensityImage* nonMaxSuppression = ImageFactory::newIntensityImage(sobelX->getWidth(), sobelX->getHeight()); canny.nonMaximumSurpression(sobelX, sobelY, nonMaxSuppression); // 4. Apply hysteresis threshold IntensityImage* hysteresisThreshold = ImageFactory::newIntensityImage(sobelX->getWidth(), sobelX->getHeight()); canny.threshold(nonMaxSuppression, hysteresisThreshold, 60, 70); timer.stop(); std::cout << timer.elapsedMilliSeconds() << " ms" << std::endl; total += timer.elapsedMilliSeconds(); timer.reset(); if (i == 9) ImageIO::saveIntensityImage(*hysteresisThreshold, ImageIO::getDebugFileName("Canny.png")); } std::cout << "Average time per Canny edge detection: " << (total / 10) << " ms" << std::endl; std::cout << "Press the X in the console window to exit program" << std::endl; }
void Test::RunScaleTest(RGBImage* in) { StudentPreProcessing sPre; IntensityImage* grey = ImageFactory::newIntensityImage(in->getWidth(), in->getHeight()); grey = sPre.stepToIntensityImage(*in); IntensityImage* scale; BaseTimer timer; int total = 0; for (int i = 0; i < 10; ++i) { timer.start(); scale = sPre.stepScaleImage(*grey); timer.stop(); std::cout << timer.elapsedMicroSeconds() << " us" << std::endl; total += timer.elapsedMicroSeconds(); timer.reset(); } std::cout << "Gemiddelde tijd: " << (total / 10) << " us" << std::endl; }
bool executeSteps(DLLExecution * executor) { //Execute the four Pre-processing steps if (!executor->executePreProcessingStep1(false)) { std::cout << "Pre-processing step 1 failed!" << std::endl; return false; } if (!executor->executePreProcessingStep2(false)) { std::cout << "Pre-processing step 2 failed!" << std::endl; return false; } ImageIO::saveIntensityImage(*executor->resultPreProcessingStep2, ImageIO::getDebugFileName("Pre-processing-2.png")); if (!executor->executePreProcessingStep3(false)) { std::cout << "Pre-processing step 3 failed!" << std::endl; return false; } ImageIO::saveIntensityImage(*executor->resultPreProcessingStep3, ImageIO::getDebugFileName("Pre-processing-3.png")); if (!executor->executePreProcessingStep4(false)) { std::cout << "Pre-processing step 4 failed!" << std::endl; return false; } ImageIO::saveIntensityImage(*executor->resultPreProcessingStep4, ImageIO::getDebugFileName("Pre-processing-4.png")); //Execute the localization steps if (!executor->prepareLocalization()) { std::cout << "Localization preparation failed!" << std::endl; return false; } std::vector<long long> time; for (int i = 0; i < 10000; ++i){ bt.start(); if (!executor->executeLocalizationStep1(true)) { std::cout << "Localization step 1 failed!" << std::endl; return false; } bt.stop(); time.push_back(bt.elapsedMicroSeconds()); \ bt.reset(); } long long total = 0; for (int i = 0; i < time.size(); ++i){ total = total + time[i]; } long long average = total / time.size(); std::cout << average; if (!executor->executeLocalizationStep2(false)) { std::cout << "Localization step 2 failed!" << std::endl; return false; } if (!executor->executeLocalizationStep3(false)) { std::cout << "Localization step 3 failed!" << std::endl; return false; } if (!executor->executeLocalizationStep4(false)) { std::cout << "Localization step 4 failed!" << std::endl; return false; } if (!executor->executeLocalizationStep5(false)) { std::cout << "Localization step 5 failed!" << std::endl; return false; } //Execute the extraction steps if (!executor->prepareExtraction()) { std::cout << "Extraction preparation failed!" << std::endl; return false; } if (!executor->executeExtractionStep1(false)) { std::cout << "Extraction step 1 failed!" << std::endl; return false; } if (!executor->executeExtractionStep2(false)) { std::cout << "Extraction step 2 failed!" << std::endl; return false; } if (!executor->executeExtractionStep3(false)) { std::cout << "Extraction step 3 failed!" << std::endl; return false; } //Post processing and representation if (!executor->executePostProcessing()) { std::cout << "Post-processing failed!" << std::endl; return false; } drawFeatureDebugImage(*executor->resultPreProcessingStep1, executor->featuresScaled); if (!executor->executeRepresentation()) { std::cout << "Representation failed!" << std::endl; return false; } return true; }