Fixed errors due to no pictures in pieces folder

This commit is contained in:
TabDragon 2017-12-29 14:33:22 +01:00
parent 4c59e04fa7
commit cba4d204c8
7 changed files with 50 additions and 16 deletions

View File

@ -26,7 +26,7 @@ public:
* @brief pure virtual method for the pre processing of the layer
* @param [in] partArray - References of all Parts, in which the properties of the Layer will be written
*/
virtual void PreProcessing(coor mySize, const vector<Part*>* partArray) = 0;
virtual bool PreProcessing(coor mySize, const vector<Part*>* partArray) = 0;
/**
* @brief pure virtual method for the quality evaluation of the layer

View File

@ -11,9 +11,11 @@ map<int,float> DestructionPower_Properties::SpeedTable =
};
void DestructionPower::PreProcessing(coor mySize,const vector<Part*>* partArray)
bool DestructionPower::PreProcessing(coor mySize,const vector<Part*>* partArray)
{
InitialiseConstraintMatrixSize(mySize.row,mySize.col);
return true;
}
//it through qualityVector and removes all that do not trigger PlaceOfPartGood

View File

@ -17,7 +17,7 @@
class DestructionPower : public AbstractionLayer_Base<DestructionPower_Properties>
{
public:
void PreProcessing(coor mySize,const vector<Part*>* partArray)override;
bool PreProcessing(coor mySize,const vector<Part*>* partArray)override;
bool EvaluateQuality (coor constraintCoordinate, qualityVector& qVector) override;
bool SetConstraintOnPosition(coor constraintCoordinate, DestructionPower_Properties constraint);
bool RemoveConstraintOnPosition(coor constraintCoordinate)override;

View File

@ -8,19 +8,28 @@
#include <iostream>
#include <bitset>
void AbstractionLayer_1::PreProcessing(coor mySize, const vector<Part*>* partArray)
bool AbstractionLayer_1::PreProcessing(coor mySize, const vector<Part*>* partArray)
{
analyseParts analyse(1008);
vector<Part> parts;
Part buf;
unsigned char tabs = 0;
for(int i = 0; i < 1008; i++){
tabs = analyse.getTabs(i);
buf.m_a1.m_connections=tabs;
parts.push_back(buf);
}
if(!analyse.getImages())
{
cerr << "Error: No pictures found!" << endl;
return false;
}
else
{
unsigned char tabs = 0;
for(int i = 0; i < 1008; i++)
{
tabs = analyse.getTabs(i);
buf.m_a1.m_connections=tabs;
parts.push_back(buf);
}
}
//Zugriff auf den vector mit den einzelnen teilen: part[0].getConnenctions() entspricht pömpel von bild 0.jpg und liefert ein unsigned char, poempl Belegung wie ausgemacht
@ -28,6 +37,8 @@ void AbstractionLayer_1::PreProcessing(coor mySize, const vector<Part*>* partAr
InitialiseConstraintMatrixSize(mySize.col+2, mySize.row+2);
setEdgeZero();
return true;
}
//it through qualityVector and removes all that do not trigger PlaceOfPartGood
@ -204,7 +215,11 @@ Mat analyseParts::readImages(int count)
Mat src = imread(name, 1);
if (!src.data)
{
cerr << "Problem loading image!!!" << endl;
return src;
}
if(DISPLAY)imshow("src",src);
Mat im_gray, im_bw;
@ -328,7 +343,7 @@ float analyseParts::angle(Point one, Point two, Point three) {
return angle;
}
void analyseParts::getImages(){
bool analyseParts::getImages(){
Details mask;
Mat src;
vector<vector<Point> > contours;
@ -342,6 +357,13 @@ void analyseParts::getImages(){
for (int i = 0; i < nr_parts; i++) {
if(DISPLAY) cout << "Bild " << i << endl;
Mat im_bw = readImages(i);
if(!im_bw.data)
{
cerr << "Error: No pic found!!" << endl;
return false;
}
Mat dst = morphDilateErode(im_bw);
contours1 = findingContours(dst);
mask_gray = polyApprox(contours1);
@ -356,6 +378,8 @@ void analyseParts::getImages(){
masks.push_back(mask);
destroyAllWindows();
}
return true;
}
Point analyseParts::findCenter(Mat img){

View File

@ -37,7 +37,7 @@ using namespace cv;
class AbstractionLayer_1 : public AbstractionLayer_Base<AbstractionLayer_1_Properties>
{
public:
void PreProcessing(coor mySize, const vector<Part*>* partArray) override ;
bool PreProcessing(coor mySize, const vector<Part*>* partArray) override ;
bool EvaluateQuality ( coor constraintCoordinate, qualityVector& qVector)override;
bool SetConstraintOnPosition( coor constraintCoordinate, AbstractionLayer_1_Properties constraint)override;
bool RemoveConstraintOnPosition( coor constraintCoordinate)override;
@ -81,7 +81,7 @@ private:
class analyseParts{
public:
explicit analyseParts(int s = 1008): nr_parts(s){getImages();}
explicit analyseParts(int s = 1008): nr_parts(s){}
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();}
@ -95,8 +95,8 @@ public:
Mat morphDilateErode(Mat&);
vector<vector<Point>> findingContours(Mat&);
Mat polyApprox(vector<vector<Point>> &);
bool getImages();
private:
void getImages();
float lengthTwoPoints(Point, Point);
float angle(Point, Point, Point);
vector<Details> masks;

View File

@ -40,9 +40,11 @@ class Puzzle
{
public:
Puzzle(unsigned int newcols,unsigned int newrows):rows(newrows),cols(newcols)
Puzzle(unsigned int newcols,unsigned int newrows):rows(newrows),cols(newcols) {}
bool PreProcessing()
{
a1.PreProcessing({rows,cols}, nullptr);
return a1.PreProcessing({rows,cols}, nullptr);
}
coor getSizeAsCoor()

View File

@ -9,6 +9,12 @@ int main()
vector<LogEntry> log;
Puzzle puzzleMat(cols, rows);
if(!puzzleMat.PreProcessing())
{
cerr << "Error occured at PreProcessing!";
return 0;
}
puzzleMat.createRandomBox();
cout << "here" << endl;
puzzleMat.a1.printConstraintMatrix();