2017-12-18 21:24:21 +01:00
|
|
|
#ifndef SOURCE_ABSTRACTIONLAYER_1_H
|
|
|
|
#define SOURCE_ABSTRACTIONLAYER_1_H
|
|
|
|
|
|
|
|
#include "AbstractionLayer_1_Properties.h"
|
2017-12-21 12:20:57 +01:00
|
|
|
#include "../AbstraktionLayer_Base.h"
|
|
|
|
|
2017-12-29 12:07:56 +01:00
|
|
|
#include <utility>
|
2017-12-18 21:24:21 +01:00
|
|
|
#include <vector>
|
|
|
|
#include <iostream>
|
|
|
|
#include <bitset>
|
2017-12-20 17:35:52 +01:00
|
|
|
#include <random>
|
2017-12-29 12:07:56 +01:00
|
|
|
#include <iostream>
|
|
|
|
#include "opencv2/highgui/highgui.hpp"
|
|
|
|
#include "opencv2/imgproc/imgproc.hpp"
|
|
|
|
#include <iostream>
|
|
|
|
#include <cstdio>
|
|
|
|
#include <cstdlib>
|
|
|
|
#include <cmath>
|
|
|
|
#include <vector>
|
|
|
|
#include <bitset>
|
|
|
|
|
|
|
|
#define DISPLAY false
|
2018-01-18 21:47:53 +01:00
|
|
|
|
|
|
|
#ifdef _WIN32
|
2018-01-06 23:23:42 +01:00
|
|
|
#define PATH "..\\..\\..\\pieces\\%04d.jpg"
|
2018-01-18 21:47:53 +01:00
|
|
|
#elif defined __unix__
|
|
|
|
#define PATH "..//..//..//pieces//%04d.jpg"
|
|
|
|
#elif defined __APPLE__
|
|
|
|
#define PATH "..//..//..//pieces//%04d.jpg"
|
|
|
|
#endif
|
|
|
|
|
2017-12-29 12:07:56 +01:00
|
|
|
#define IMG_SIZE 400
|
|
|
|
#define TOP 6
|
|
|
|
#define RIGHT 4
|
|
|
|
#define BOTTOM 2
|
|
|
|
#define LEFT 0
|
|
|
|
|
|
|
|
using namespace std;
|
|
|
|
using namespace cv;
|
2017-12-18 21:24:21 +01:00
|
|
|
|
2017-12-21 12:20:57 +01:00
|
|
|
class AbstractionLayer_1 : public AbstractionLayer_Base<AbstractionLayer_1_Properties>
|
2017-12-18 21:24:21 +01:00
|
|
|
{
|
|
|
|
public:
|
2018-01-20 16:02:44 +01:00
|
|
|
bool PreProcessing(coor mySize, const vector<Part*>* partArray) final ;
|
|
|
|
bool EvaluateQuality ( coor constraintCoordinate, qualityVector& qVector)final;
|
|
|
|
bool SetConstraintOnPosition( coor constraintCoordinate, AbstractionLayer_1_Properties constraint)final;
|
|
|
|
bool RemoveConstraintOnPosition( coor constraintCoordinate)final;
|
2018-01-20 09:40:03 +01:00
|
|
|
int RemoveSimilar(qualityVector&,uint8_t&);
|
|
|
|
|
2017-12-18 22:50:03 +01:00
|
|
|
bool PlaceOfPartGood(coor myCoor, uint8_t& myPart);
|
|
|
|
void shift(uint8_t& Part, int shifts);
|
2017-12-18 21:24:21 +01:00
|
|
|
void setEdgeZero();
|
|
|
|
|
2018-01-20 11:58:32 +01:00
|
|
|
int PoempelSum(uint8_t constraint);
|
2017-12-18 21:24:21 +01:00
|
|
|
|
2017-12-23 10:11:07 +01:00
|
|
|
void CreateRandomPuzzle();
|
2017-12-20 17:35:52 +01:00
|
|
|
qualityVector returnInBox(vector<Part>& PuzzleBox);
|
2017-12-22 23:27:50 +01:00
|
|
|
void printConstraintMatrix();
|
2017-12-18 21:24:21 +01:00
|
|
|
|
|
|
|
private:
|
|
|
|
};
|
|
|
|
|
2017-12-29 12:07:56 +01:00
|
|
|
class Details{
|
|
|
|
public:
|
|
|
|
vector<vector<Point>> getContour(){return contour;}
|
|
|
|
Mat getImage(){return image;}
|
|
|
|
Point getCenter(){return center;}
|
|
|
|
vector<Vec4i> getHierarchy(){return hierarchy;}
|
|
|
|
unsigned char getTabs(){return tabs;}
|
|
|
|
|
|
|
|
void setContour(vector<vector<Point>> cont){contour = std::move(cont);}
|
|
|
|
void setImage(Mat im){image = std::move(im);}
|
|
|
|
void setCenter(const Point &c){center = c;}
|
|
|
|
void setHierarchy(vector<Vec4i> hier){hierarchy = std::move(hier);}
|
|
|
|
void setCorners(vector<Point> cor){corners = std::move(cor);}
|
|
|
|
void setTabs(unsigned char t){tabs = t;}
|
2018-01-20 20:03:34 +01:00
|
|
|
vector<double> getLen(){return len;}
|
|
|
|
void setLens(vector<double> l ){len = l;}
|
|
|
|
Point getMidpoint(){return midpoint;}
|
|
|
|
void setMidpoint(Point m ){midpoint = m;}
|
2018-01-22 19:20:25 +01:00
|
|
|
vector<double> getPoempelPosition(){return PoempelPosition;}
|
|
|
|
void setPoempelPosition(vector<double>& newPP){PoempelPosition=newPP;}
|
2017-12-29 12:07:56 +01:00
|
|
|
vector<Point> getCorners(){return corners;}
|
|
|
|
|
|
|
|
private:
|
|
|
|
Mat image;
|
2018-01-22 19:20:25 +01:00
|
|
|
vector<double> PoempelPosition;
|
2017-12-29 12:07:56 +01:00
|
|
|
vector<Point> corners;
|
|
|
|
vector<vector<Point>> contour;
|
|
|
|
vector<Vec4i> hierarchy;
|
|
|
|
Point center;
|
2018-01-20 20:03:34 +01:00
|
|
|
vector<double> len;
|
2017-12-29 12:07:56 +01:00
|
|
|
unsigned char tabs;
|
2018-01-20 20:03:34 +01:00
|
|
|
Point midpoint;
|
2017-12-29 12:07:56 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
class analyseParts{
|
|
|
|
public:
|
2017-12-29 14:33:22 +01:00
|
|
|
explicit analyseParts(int s = 1008): nr_parts(s){}
|
2017-12-29 12:07:56 +01:00
|
|
|
Mat getImage(int i){if(i>= nr_parts)return masks[nr_parts-1].getImage(); else return masks[i].getImage();}
|
|
|
|
vector<vector<Point>> getContour(int i){if(i>= nr_parts)return masks[nr_parts-1].getContour(); else return masks[i].getContour();}
|
|
|
|
Point getCenter(int i){if(i>= nr_parts)return masks[nr_parts-1].getCenter(); else return masks[i].getCenter();}
|
|
|
|
vector<Vec4i> getHierarchy(int i){if(i>= nr_parts)return masks[nr_parts-1].getHierarchy(); else return masks[i].getHierarchy();}
|
|
|
|
unsigned char getTabs(int i){if(i>= nr_parts)return masks[nr_parts-1].getTabs(); else return masks[i].getTabs();}
|
2018-01-20 20:03:34 +01:00
|
|
|
vector<double> getLen(int i ){return masks[i].getLen();}
|
2018-01-22 19:20:25 +01:00
|
|
|
vector<double> getPoempelPosition(int i){return masks[i].getPoempelPosition();}
|
2018-01-20 20:03:34 +01:00
|
|
|
vector<double> analyseLens(vector<double>, vector<Point>);
|
|
|
|
Point calcMidpoint(vector<Point>);
|
|
|
|
Point getMidpoint(int i){return masks[i].getMidpoint();}
|
2017-12-29 12:07:56 +01:00
|
|
|
Point findCenter(Mat);
|
|
|
|
vector<Point> findCorners(vector<Point>,Point);
|
2018-01-22 19:20:25 +01:00
|
|
|
unsigned char analyseContour(vector<Point>, vector<Point>,vector<double>&);
|
2017-12-29 12:07:56 +01:00
|
|
|
Mat makeBorder(Mat&);
|
|
|
|
Mat readImages(int);
|
|
|
|
Mat morphDilateErode(Mat&);
|
|
|
|
vector<vector<Point>> findingContours(Mat&);
|
|
|
|
Mat polyApprox(vector<vector<Point>> &);
|
2017-12-29 14:33:22 +01:00
|
|
|
bool getImages();
|
2017-12-29 12:07:56 +01:00
|
|
|
private:
|
|
|
|
float lengthTwoPoints(Point, Point);
|
|
|
|
float angle(Point, Point, Point);
|
|
|
|
vector<Details> masks;
|
|
|
|
int nr_parts;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2017-12-18 21:24:21 +01:00
|
|
|
#endif //SOURCE_ABSTRACTIONLAYER_1_H
|