2017-12-18 21:24:21 +01:00
|
|
|
//
|
|
|
|
// Created by mpapa on 05.12.2017.
|
|
|
|
//
|
|
|
|
|
|
|
|
#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-06 23:23:42 +01:00
|
|
|
#define PATH "..\\..\\..\\pieces\\%04d.jpg"
|
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:
|
2017-12-29 14:33:22 +01:00
|
|
|
bool PreProcessing(coor mySize, const vector<Part*>* partArray) override ;
|
2017-12-29 12:07:56 +01:00
|
|
|
bool EvaluateQuality ( coor constraintCoordinate, qualityVector& qVector)override;
|
|
|
|
bool SetConstraintOnPosition( coor constraintCoordinate, AbstractionLayer_1_Properties constraint)override;
|
|
|
|
bool RemoveConstraintOnPosition( coor constraintCoordinate)override;
|
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();
|
|
|
|
|
|
|
|
|
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;}
|
|
|
|
|
|
|
|
vector<Point> getCorners(){return corners;}
|
|
|
|
|
|
|
|
private:
|
|
|
|
Mat image;
|
|
|
|
vector<Point> corners;
|
|
|
|
vector<vector<Point>> contour;
|
|
|
|
vector<Vec4i> hierarchy;
|
|
|
|
Point center;
|
|
|
|
unsigned char tabs;
|
|
|
|
};
|
|
|
|
|
|
|
|
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();}
|
|
|
|
Point findCenter(Mat);
|
|
|
|
vector<Point> findCorners(vector<Point>,Point);
|
|
|
|
unsigned char analyseContour(vector<Point>, vector<Point>);
|
|
|
|
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
|