diff --git a/Source/functions/AbstractionLayers/Layer1/AbstractionLayer_1.cpp b/Source/functions/AbstractionLayers/Layer1/AbstractionLayer_1.cpp index 33cde89..286cc93 100644 --- a/Source/functions/AbstractionLayers/Layer1/AbstractionLayer_1.cpp +++ b/Source/functions/AbstractionLayers/Layer1/AbstractionLayer_1.cpp @@ -72,7 +72,7 @@ bool AbstractionLayer_1::RemoveConstraintOnPosition(const coor constraintCoordin void AbstractionLayer_1::CreateRandomPuzzle() { std::minstd_rand simple_rand; - simple_rand.seed((unsigned int)"dumbo"); + simple_rand.seed((unsigned int)time(nullptr)); //dumbo for(int col = 0; col < m_constraintMatrix.size()-2; col++){ for(int row = 0; row < (m_constraintMatrix[col].size() - 2);) diff --git a/Source/functions/AbstractionLayers/Layer1/AbstractionLayer_1.h b/Source/functions/AbstractionLayers/Layer1/AbstractionLayer_1.h index d079332..7889a14 100644 --- a/Source/functions/AbstractionLayers/Layer1/AbstractionLayer_1.h +++ b/Source/functions/AbstractionLayers/Layer1/AbstractionLayer_1.h @@ -24,7 +24,15 @@ #include #define DISPLAY false + +#ifdef _WIN32 #define PATH "..\\..\\..\\pieces\\%04d.jpg" +#elif defined __unix__ +#define PATH "..//..//..//pieces//%04d.jpg" +#elif defined __APPLE__ + #define PATH "..//..//..//pieces//%04d.jpg" +#endif + #define IMG_SIZE 400 #define TOP 6 #define RIGHT 4 diff --git a/Source/functions/solve/puzzleExtension.cpp b/Source/functions/solve/puzzleExtension.cpp index e46999c..84de8d3 100644 --- a/Source/functions/solve/puzzleExtension.cpp +++ b/Source/functions/solve/puzzleExtension.cpp @@ -1,14 +1,20 @@ // // Created by Raphael Maenle on 21/12/2017. // - #include "../../header/solve.h" +#include "../../header/input.h" +typedef std::vector> Contour_t; +typedef std::vector Hierarchy_t; //hierarchy object is needed for drawContours apparently +Mat crop2ContourInv(const Mat & img); +Contour_t getLongestContour(Mat bw); +int getLongestContourIndex(Contour_t contours); void Puzzle::printPuzzle() { cout << "a1: " << endl; a1.printConstraintMatrix(); + } void Puzzle::printBox() @@ -22,6 +28,7 @@ void Puzzle::printBox() } } + //puts a puzzlepiece back into its box void Puzzle::putIntoBox() { @@ -39,7 +46,7 @@ void Puzzle::putIntoBox() for(int rotations=0;rotations<4;rotations++) { tmpPart.m_a1.shift(1); - //TODO! add all other layerswith their rotaionvariance here + //TODO! add all other layers with their rotaionvariance here myBox.emplace_back(tmpPart); } @@ -92,10 +99,7 @@ void Puzzle::createBox(){ temp.SetNumOfRotations(j); myBox.push_back(temp); } - - } - } bool Puzzle::allSet() { @@ -115,3 +119,119 @@ void Puzzle::clearMat() } } } + +Mat Puzzle::readImage(int fileIndex, const char* inputDir){ + + char indexstr[12]; + sprintf(indexstr,"%d.jpg",fileIndex); + char * inputstr = (char *) malloc(1 + strlen(inputDir)+ strlen(indexstr) ); + strcpy(inputstr, inputDir); + strcat(inputstr,indexstr); + //cout<& log){ + int Y_size = 1200; // chose this to fit your monitor! + int separator = 1; + int partHeight = 90; + int partWidth; + auto imageH = int(round(partHeight* cols)); + + if(imageH > Y_size){ + imageH = Y_size; + } + partHeight = int(round(imageH / cols)); + partWidth= partHeight; + int imageW = int(round( partWidth*rows)); + + int temp = imageW; + imageW = imageH; + imageH = temp; + + cout<<"imageW "<GetPartID() << endl; + + int imageNumber = it.PieceCollector[0].second->GetPartID(); + //cout<<"imageIndex: "<< imageNumber << endl; + + sprintf(name, PATH, imageNumber); + Mat img = imread(name, 1); + + copyMakeBorder(img,img,200,200,200,200,BORDER_CONSTANT,Scalar(255,255,255)); + Mat invert = Mat::ones(img.size(), CV_8UC3); // invert for rotation to work correctly + bitwise_not ( img, invert ); + if (it.myCoor.col == 12 && it.myCoor.row == 0) + { + //imshow("img",img); + //waitKey(0); + ; + } + + + int angle = ((int)it.PieceCollector[0].second->GetNumOfRotations())*-90; + Point2f center; + center.x = img.cols/2; + center.y = img.rows/2; + Mat RotMatrix = getRotationMatrix2D(center,angle,1); + warpAffine(invert,invert,RotMatrix, invert.size()); + bitwise_not(invert,img); + Mat cropped = crop2ContourInv(img); + auto ROI_X = int(round(it.myCoor.col*partWidth)); + auto ROI_Y = int(round(it.myCoor.row*partHeight)); +// cout<<"ROI X: "<< ROI_X< largestArea) { + largestArea = area; + largestIndex = i; // i is type size_t, should be converted to int. + } + } + return(largestIndex); +} \ No newline at end of file diff --git a/Source/functions/solve/structure.cpp b/Source/functions/solve/structure.cpp index 0562f10..05411a1 100755 --- a/Source/functions/solve/structure.cpp +++ b/Source/functions/solve/structure.cpp @@ -106,7 +106,7 @@ void setsolution(vector& log, Puzzle& puzzleMat) //tell log entry that it is set log.back().Set(); puzzleMat.setConstraints(log.back().myCoor,log.back().PieceCollector.begin()->second); - cout << "set:" << log.back().myCoor.col << "," << log.back().myCoor.row << endl; + //cout << "set:" << log.back().myCoor.col << "," << log.back().myCoor.row << endl; } bool backtrack(vector& log, Puzzle& puzzleMat) diff --git a/Source/header/solve.h b/Source/header/solve.h index 0c1a0e5..7bbc49a 100755 --- a/Source/header/solve.h +++ b/Source/header/solve.h @@ -58,6 +58,7 @@ public: void setConstraints(coor setConstraints, Part *constraintPiece); void printPuzzle(); void printBox(); + Mat resultImage(vector&); void createRandomBox(){ myBox.clear();p_myBox.clear(); @@ -81,6 +82,7 @@ public: private: + Mat readImage(int fileIndex, const char* inputDir); unsigned int cols; unsigned int rows; }; diff --git a/Source/main.cpp b/Source/main.cpp index 7f71bf6..001c09c 100644 --- a/Source/main.cpp +++ b/Source/main.cpp @@ -21,6 +21,9 @@ int main() while(next(log, puzzleMat)); cout << "Done!" << endl; + + cout << log.size() << endl; + puzzleMat.resultImage(log); puzzleMat.printPuzzle(); return 0; }