From ce6fc0db7228420d5b09a1e6c028ebeb62bd65ef Mon Sep 17 00:00:00 2001 From: TabDragon <31097001+TabDragon@users.noreply.github.com> Date: Fri, 29 Dec 2017 15:00:43 +0100 Subject: [PATCH] Fixed errors if not enough corners were found! --- .../Layer1/AbstractionLayer_1.cpp | 20 +++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/Source/functions/AbstractionLayers/Layer1/AbstractionLayer_1.cpp b/Source/functions/AbstractionLayers/Layer1/AbstractionLayer_1.cpp index 5e70797..b205b01 100644 --- a/Source/functions/AbstractionLayers/Layer1/AbstractionLayer_1.cpp +++ b/Source/functions/AbstractionLayers/Layer1/AbstractionLayer_1.cpp @@ -17,7 +17,7 @@ bool AbstractionLayer_1::PreProcessing(coor mySize, const vector* partAr if(!analyse.getImages()) { - cerr << "Error: No pictures found!" << endl; + cerr << "Error occured in getImages!" << endl; return false; } else @@ -373,6 +373,11 @@ bool analyseParts::getImages(){ mask.setContour(contours); mask.setHierarchy(hierarchy); corners = findCorners(contours[0],mask.getCenter()); + if((corners.empty()) || (corners.size() < 4)) + { + cerr << "Error occured in findCorners" << endl; + return false; + } mask.setCorners(corners); mask.setTabs(analyseContour(corners,contours[0])); masks.push_back(mask); @@ -413,6 +418,13 @@ vector analyseParts::findCorners(vector contour, Point center){ buf3.push_back(contour[i]); } } + + if((buf0.empty()) || (buf1.empty()) || (buf2.empty()) || (buf3.empty())) + { + // return an empty vector if not all corners were found! + return vector(); + } + quad_contour.push_back(buf0); quad_contour.push_back(buf1); quad_contour.push_back(buf2); @@ -458,7 +470,7 @@ vector analyseParts::findCorners(vector contour, Point center){ line(drawing,Point((IMG_SIZE/2),center.y+dist),Point(IMG_SIZE,center.y+dist),Scalar(255,0,255),3,8); circle(drawing,quad_contour[0][max_idx],5,Scalar(50,100,255),5,8); -/*finde ecke links unten*/ + /*finde ecke links unten*/ dist = 0; max_dist = 0; max_idx = 0; @@ -489,7 +501,7 @@ vector analyseParts::findCorners(vector contour, Point center){ line(drawing,Point((IMG_SIZE/2),center.y+dist),Point(0,center.y+dist),Scalar(255,0,255),3,8); circle(drawing,quad_contour[1][max_idx],5,Scalar(50,100,255),5,8); -/*finde ecke rechts oben*/ + /*finde ecke rechts oben*/ dist = 0; max_dist = 0; max_idx = 0; @@ -520,7 +532,7 @@ vector analyseParts::findCorners(vector contour, Point center){ line(drawing,Point((IMG_SIZE/2),center.y-dist),Point(IMG_SIZE,center.y-dist),Scalar(255,0,255),3,8); circle(drawing,quad_contour[2][max_idx],5,Scalar(50,100,255),5,8); -/*finde ecke links oben*/ + /*finde ecke links oben*/ dist = 0; max_dist = 0; max_idx = 0;