edited in puzzlecreator
This commit is contained in:
parent
490db896bf
commit
4701720d3a
@ -3,12 +3,13 @@
|
||||
//
|
||||
|
||||
#include "../../header/solve.h"
|
||||
|
||||
#include "../../header/input.h"
|
||||
|
||||
void Puzzle::printPuzzle()
|
||||
{
|
||||
cout << "a1: " << endl;
|
||||
a1.printConstraintMatrix();
|
||||
|
||||
}
|
||||
|
||||
void Puzzle::printBox()
|
||||
@ -22,6 +23,7 @@ void Puzzle::printBox()
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//puts a puzzlepiece back into its box
|
||||
void Puzzle::putIntoBox()
|
||||
{
|
||||
@ -92,10 +94,7 @@ void Puzzle::createBox(){
|
||||
temp.SetNumOfRotations(j);
|
||||
myBox.push_back(temp);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
bool Puzzle::allSet() {
|
||||
@ -115,3 +114,70 @@ 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<<inputstr<<endl;
|
||||
Mat source = imread(inputstr,1);
|
||||
return source;
|
||||
}
|
||||
|
||||
Mat Puzzle::resultImage( vector<LogEntry>& log){
|
||||
|
||||
int Y_size = 600; // 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));
|
||||
|
||||
cout<<"imageW "<<imageW <<endl<<"imageH " <<imageH<<endl<<endl;
|
||||
cout<<"partW "<<partWidth <<endl<<"partH " <<partHeight<<endl<<endl;
|
||||
Mat result(imageH,imageW,CV_8UC3);
|
||||
|
||||
for (auto it:log)
|
||||
{
|
||||
cout << log.size() << endl;
|
||||
cout << log[0].PieceCollector.size() << endl;
|
||||
|
||||
cout << it.PieceCollector[0].second->GetPartID() << endl;
|
||||
|
||||
int imageNumber = it.PieceCollector[0].second->GetPartID();
|
||||
//cout<<"imageIndex: "<< imageNumber << endl;
|
||||
|
||||
Mat img = readImage(imageNumber,PATH);
|
||||
int angle = 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(img,img,RotMatrix, img.size());
|
||||
// imshow("readImg",img); // you can comment with Ctrl + / did you know? :D
|
||||
// waitKey(0);
|
||||
|
||||
auto ROI_X = int(round(it.myCoor.col*partWidth));
|
||||
auto ROI_Y = int(round(it.myCoor.row*partHeight));
|
||||
// cout<<"ROI X: "<< ROI_X<<endl;
|
||||
// cout<<"ROI Y: "<< ROI_Y<<endl;
|
||||
|
||||
Rect ROI(ROI_X,ROI_Y , partWidth-separator, partHeight-separator); // j is the x coordinate not i!!
|
||||
Mat temp; resize(img,temp, Size(ROI.width, ROI.height));
|
||||
temp.copyTo(result(ROI));
|
||||
|
||||
// imshow("result",result);
|
||||
// waitKey(0);
|
||||
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
@ -106,7 +106,7 @@ void setsolution(vector<LogEntry>& 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<LogEntry>& log, Puzzle& puzzleMat)
|
||||
|
@ -58,6 +58,7 @@ public:
|
||||
void setConstraints(coor setConstraints, Part *constraintPiece);
|
||||
void printPuzzle();
|
||||
void printBox();
|
||||
Mat resultImage(vector<LogEntry>&);
|
||||
|
||||
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;
|
||||
};
|
||||
|
@ -21,6 +21,9 @@ int main()
|
||||
while(next(log, puzzleMat));
|
||||
|
||||
cout << "Done!" << endl;
|
||||
|
||||
cout << log.size() << endl;
|
||||
puzzleMat.resultImage(log);
|
||||
puzzleMat.printPuzzle();
|
||||
return 0;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user