diff options
author | Nash <nash@bsd-noobz.com> | 2014-11-14 00:10:53 +0700 |
---|---|---|
committer | Nash <nash@bsd-noobz.com> | 2014-11-14 00:10:53 +0700 |
commit | d3bd05d9f29d7c602d560d59f627760f654a83c7 (patch) | |
tree | 6238fad52265527094a13be7a99f829715ef34cf | |
parent | d7fd037c1d85c7eeec7ad331f672fe3edc002e31 (diff) | |
parent | 61f48f34b6c30d861fcf49714590739cb7ebc1fd (diff) |
Merge pull request #3 from darrensapalo/master
Added some error handling
-rw-r--r-- | quad-segmentation.cpp | 30 |
1 files changed, 18 insertions, 12 deletions
diff --git a/quad-segmentation.cpp b/quad-segmentation.cpp index bb341cd..17428a1 100644 --- a/quad-segmentation.cpp +++ b/quad-segmentation.cpp @@ -37,17 +37,20 @@ void sortCorners(std::vector<cv::Point2f>& corners, else bot.push_back(corners[i]); } - - cv::Point2f tl = top[0].x > top[1].x ? top[1] : top[0]; - cv::Point2f tr = top[0].x > top[1].x ? top[0] : top[1]; - cv::Point2f bl = bot[0].x > bot[1].x ? bot[1] : bot[0]; - cv::Point2f br = bot[0].x > bot[1].x ? bot[0] : bot[1]; - corners.clear(); - corners.push_back(tl); - corners.push_back(tr); - corners.push_back(br); - corners.push_back(bl); + + if (top.size() == 2 && bot.size() == 2){ + cv::Point2f tl = top[0].x > top[1].x ? top[1] : top[0]; + cv::Point2f tr = top[0].x > top[1].x ? top[0] : top[1]; + cv::Point2f bl = bot[0].x > bot[1].x ? bot[1] : bot[0]; + cv::Point2f br = bot[0].x > bot[1].x ? bot[0] : bot[1]; + + + corners.push_back(tl); + corners.push_back(tr); + corners.push_back(br); + corners.push_back(bl); + } } int main() @@ -93,14 +96,17 @@ int main() std::cout << "The object is not quadrilateral!" << std::endl; return -1; } - + // Get mass center for (int i = 0; i < corners.size(); i++) center += corners[i]; center *= (1. / corners.size()); sortCorners(corners, center); - + if (corners.size() == 0){ + std::cout << "The corners were not sorted correctly!" << std::endl; + return -1; + } cv::Mat dst = src.clone(); // Draw lines |