From faeeeb8d7128223ce839f0e660421034dd5961c6 Mon Sep 17 00:00:00 2001 From: JRauer Date: Fri, 26 Jan 2018 18:47:41 +0100 Subject: [PATCH] Added code for processing of puzzle-pieces Code working until now Commented out other layers in solve.h Path now in header-file Small changes to full-puzzle-processing --- .../AbstractionLayer_SURFFeatures.cpp | 66 +++++++++++++++---- .../AbstractionLayer_SURFFeatures.h | 17 +++++ Source/header/solve.h | 4 +- 3 files changed, 71 insertions(+), 16 deletions(-) diff --git a/Source/functions/AbstractionLayers/Layer_SURFFeatures/AbstractionLayer_SURFFeatures.cpp b/Source/functions/AbstractionLayers/Layer_SURFFeatures/AbstractionLayer_SURFFeatures.cpp index fc3d253..24b292b 100644 --- a/Source/functions/AbstractionLayers/Layer_SURFFeatures/AbstractionLayer_SURFFeatures.cpp +++ b/Source/functions/AbstractionLayers/Layer_SURFFeatures/AbstractionLayer_SURFFeatures.cpp @@ -13,14 +13,6 @@ #include "opencv2/highgui.hpp" #include "opencv2/imgproc.hpp" -#ifdef _WIN32 -#define PATH_FULL_PUZZLE "..\\..\\..\\puzzle_img\\puzzle1.jpg" -#elif defined __unix__ -#define PATH_FULL_PUZZLE "..//..//..//puzzle_img//puzzle1.jpg" -#elif defined __APPLE__ - #define PATH_FULL_PUZZLE "..//..//..//puzzle_img//puzzle1.jpg" -#endif - using namespace cv; using namespace std; @@ -29,11 +21,13 @@ bool AbstractionLayer_SURFFeatures::PreProcessing(coor mySize, const vector corners; // Variable to store corner-positions at - // -- Complete puzzle image processing -- + + // -- Complete puzzle image processing --------------------------------------------------------------------------------------------- + // --------------------------------------------------------------------------------------------------------------------------------- // Load and resize image, so that number of parts in row and col fit in cv::Mat image = cv::imread(PATH_FULL_PUZZLE, IMREAD_GRAYSCALE); //cout << "PRE: " << image.cols << " x " << image.rows << endl; - cv::resize(image, image, Size(int(ceil(double(image.cols)/mySize.col)*mySize.row), int(ceil(double(image.rows)/mySize.row)*mySize.row))); + cv::resize(image, image, Size(int(ceil(double(image.cols)/mySize.col)*mySize.col), int(ceil(double(image.rows)/mySize.row)*mySize.row))); //cout << "POST: " << image.cols << " x " << image.rows << endl; // PARAMETERS (for description see top of file) @@ -77,7 +71,7 @@ bool AbstractionLayer_SURFFeatures::PreProcessing(coor mySize, const vectorat(xxx)) - partArray->at(0)->m_a4.m_numberOfFeaturesDetected = 40; + + + // -- Puzzle piece image processing ------------------------------------------------------------------------------------------------ + // --------------------------------------------------------------------------------------------------------------------------------- + + int count = 0; + char name[100]; + + // PARAMETERS (for description see top of file) + maxCorners = 500; + qualityLevel = 0.05; + minDistance = .5; + + minFeatures = maxCorners; + maxFeatures = 0; + + // For each piece + for (count = 0; count < mySize.col*mySize.row; count++) { //cols*rows + sprintf(name, PATH, count); + Mat src = cv::imread(name, IMREAD_GRAYSCALE); + if (!src.data) { + cerr << "Problem loading image!!!" << endl; + return false; + } else { + cv::goodFeaturesToTrack( src, corners, maxCorners, qualityLevel, minDistance, mask, blockSize, useHarrisDetector, k ); + if(corners.size() < minFeatures) minFeatures = corners.size(); + if(corners.size() > maxFeatures) maxFeatures = corners.size(); + partArray->at(count)->m_a4.m_numberOfFeaturesDetected = corners.size(); + /*for( size_t i = 0; i < corners.size(); i++ ) { + cv::circle( src, corners[i], 2, cv::Scalar( 255. ), -1 ); + } + cv::namedWindow( "Output", CV_WINDOW_AUTOSIZE ); + cv::imshow( "Output", src ); + cout << count << " " << corners.size() << endl; + cv::waitKey(0);*/ + } + } + + // Calculate percentage from 0 to 100% (normalized 0-1) with numberOfFeatures and safe it + for( int i = 0; i < mySize.col*mySize.row; i++ ) + { + partArray->at(i)->m_a4.m_numberOfFeaturesDetected = (partArray->at(i)->m_a4.m_numberOfFeaturesDetected - minFeatures) / (maxFeatures - minFeatures); + cout << fixed << partArray->at(i)->m_a4.m_numberOfFeaturesDetected << endl; + } + cout << endl; + + return true; } bool AbstractionLayer_SURFFeatures::EvaluateQuality (coor constraintCoordinate, qualityVector& qVector) diff --git a/Source/functions/AbstractionLayers/Layer_SURFFeatures/AbstractionLayer_SURFFeatures.h b/Source/functions/AbstractionLayers/Layer_SURFFeatures/AbstractionLayer_SURFFeatures.h index 58a5c3d..e824700 100644 --- a/Source/functions/AbstractionLayers/Layer_SURFFeatures/AbstractionLayer_SURFFeatures.h +++ b/Source/functions/AbstractionLayers/Layer_SURFFeatures/AbstractionLayer_SURFFeatures.h @@ -3,6 +3,23 @@ #include "../AbstraktionLayer_Base.h" +#ifdef _WIN32 +#define PATH_FULL_PUZZLE "..\\..\\..\\puzzle_img\\puzzle1.jpg" +#elif defined __unix__ +#define PATH_FULL_PUZZLE "..//..//..//puzzle_img//puzzle1.jpg" +#elif defined __APPLE__ + #define PATH_FULL_PUZZLE "..//..//..//puzzle_img//puzzle1.jpg" +#endif + +#ifdef _WIN32 //TODO: Code duplicate from AbstractionLayer_1.h +#define PATH "..\\..\\..\\pieces\\%04d.jpg" +#elif defined __unix__ +#define PATH "..//..//..//pieces//%04d.jpg" +#elif defined __APPLE__ + #define PATH "..//..//..//pieces//%04d.jpg" +#endif + + using namespace std; class AbstractionLayer_SURFFeatures : public AbstractionLayer_Base diff --git a/Source/header/solve.h b/Source/header/solve.h index 2e3f509..2ae1737 100755 --- a/Source/header/solve.h +++ b/Source/header/solve.h @@ -44,9 +44,9 @@ public: bool PreProcessing() { createBox(); createp_box(); - if(!dp.PreProcessing({cols,rows}, nullptr)) return false; + /*if(!dp.PreProcessing({cols,rows}, nullptr)) return false; if(!a1.PreProcessing({cols,rows}, &p_myBox)) return false; - if(!a3.PreProcessing({cols,rows}, &p_myBox)) return false; + if(!a3.PreProcessing({cols,rows}, &p_myBox)) return false;*/ if(!a4.PreProcessing({cols,rows}, &p_myBox)) return false; return true;