From cba4d204c87cbda448fc8b7563902f2d35c365ba Mon Sep 17 00:00:00 2001 From: TabDragon <31097001+TabDragon@users.noreply.github.com> Date: Fri, 29 Dec 2017 14:33:22 +0100 Subject: [PATCH] Fixed errors due to no pictures in pieces folder --- .../AbstractionLayers/AbstraktionLayer_Base.h | 2 +- .../DestructionPower/DestructionPower.cpp | 4 +- .../DestructionPower/DestructionPower.h | 2 +- .../Layer1/AbstractionLayer_1.cpp | 40 +++++++++++++++---- .../Layer1/AbstractionLayer_1.h | 6 +-- Source/header/solve.h | 6 ++- Source/main.cpp | 6 +++ 7 files changed, 50 insertions(+), 16 deletions(-) diff --git a/Source/functions/AbstractionLayers/AbstraktionLayer_Base.h b/Source/functions/AbstractionLayers/AbstraktionLayer_Base.h index 36c79f6..f14d362 100644 --- a/Source/functions/AbstractionLayers/AbstraktionLayer_Base.h +++ b/Source/functions/AbstractionLayers/AbstraktionLayer_Base.h @@ -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* partArray) = 0; + virtual bool PreProcessing(coor mySize, const vector* partArray) = 0; /** * @brief pure virtual method for the quality evaluation of the layer diff --git a/Source/functions/AbstractionLayers/DestructionPower/DestructionPower.cpp b/Source/functions/AbstractionLayers/DestructionPower/DestructionPower.cpp index bdcdae3..17d8e42 100644 --- a/Source/functions/AbstractionLayers/DestructionPower/DestructionPower.cpp +++ b/Source/functions/AbstractionLayers/DestructionPower/DestructionPower.cpp @@ -11,9 +11,11 @@ map DestructionPower_Properties::SpeedTable = }; -void DestructionPower::PreProcessing(coor mySize,const vector* partArray) +bool DestructionPower::PreProcessing(coor mySize,const vector* partArray) { InitialiseConstraintMatrixSize(mySize.row,mySize.col); + + return true; } //it through qualityVector and removes all that do not trigger PlaceOfPartGood diff --git a/Source/functions/AbstractionLayers/DestructionPower/DestructionPower.h b/Source/functions/AbstractionLayers/DestructionPower/DestructionPower.h index 8790202..53c9431 100644 --- a/Source/functions/AbstractionLayers/DestructionPower/DestructionPower.h +++ b/Source/functions/AbstractionLayers/DestructionPower/DestructionPower.h @@ -17,7 +17,7 @@ class DestructionPower : public AbstractionLayer_Base { public: - void PreProcessing(coor mySize,const vector* partArray)override; + bool PreProcessing(coor mySize,const vector* partArray)override; bool EvaluateQuality (coor constraintCoordinate, qualityVector& qVector) override; bool SetConstraintOnPosition(coor constraintCoordinate, DestructionPower_Properties constraint); bool RemoveConstraintOnPosition(coor constraintCoordinate)override; diff --git a/Source/functions/AbstractionLayers/Layer1/AbstractionLayer_1.cpp b/Source/functions/AbstractionLayers/Layer1/AbstractionLayer_1.cpp index 9e15967..5e70797 100644 --- a/Source/functions/AbstractionLayers/Layer1/AbstractionLayer_1.cpp +++ b/Source/functions/AbstractionLayers/Layer1/AbstractionLayer_1.cpp @@ -8,19 +8,28 @@ #include #include -void AbstractionLayer_1::PreProcessing(coor mySize, const vector* partArray) +bool AbstractionLayer_1::PreProcessing(coor mySize, const vector* partArray) { analyseParts analyse(1008); vector 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* 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 > 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){ diff --git a/Source/functions/AbstractionLayers/Layer1/AbstractionLayer_1.h b/Source/functions/AbstractionLayers/Layer1/AbstractionLayer_1.h index 0fdee4c..f424c31 100644 --- a/Source/functions/AbstractionLayers/Layer1/AbstractionLayer_1.h +++ b/Source/functions/AbstractionLayers/Layer1/AbstractionLayer_1.h @@ -37,7 +37,7 @@ using namespace cv; class AbstractionLayer_1 : public AbstractionLayer_Base { public: - void PreProcessing(coor mySize, const vector* partArray) override ; + bool PreProcessing(coor mySize, const vector* 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> 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> findingContours(Mat&); Mat polyApprox(vector> &); + bool getImages(); private: - void getImages(); float lengthTwoPoints(Point, Point); float angle(Point, Point, Point); vector
masks; diff --git a/Source/header/solve.h b/Source/header/solve.h index bdbe160..9b9fa2f 100755 --- a/Source/header/solve.h +++ b/Source/header/solve.h @@ -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() diff --git a/Source/main.cpp b/Source/main.cpp index 9c1918b..fe8d765 100644 --- a/Source/main.cpp +++ b/Source/main.cpp @@ -9,6 +9,12 @@ int main() vector log; Puzzle puzzleMat(cols, rows); + if(!puzzleMat.PreProcessing()) + { + cerr << "Error occured at PreProcessing!"; + return 0; + } + puzzleMat.createRandomBox(); cout << "here" << endl; puzzleMat.a1.printConstraintMatrix();