From 397204b33ebf0ea062ed4f68c9ce7b53ef0ff30c Mon Sep 17 00:00:00 2001 From: yasarba71520 Date: Mon, 14 Nov 2022 17:31:01 +0100 Subject: [PATCH] =?UTF-8?q?Angefangen=20erste=20Linien=20zusammenf=C3=BChr?= =?UTF-8?q?en=20zu=20wollen?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Processing/processing.cpp | 30 +++++++++++++++++++++++++++++- Utils/utils.cpp | 14 ++++++++++++++ Utils/utils.h | 10 +++++----- 3 files changed, 48 insertions(+), 6 deletions(-) diff --git a/Processing/processing.cpp b/Processing/processing.cpp index c82b98a..0fa0cf1 100644 --- a/Processing/processing.cpp +++ b/Processing/processing.cpp @@ -23,8 +23,8 @@ void Processing::processImage(Mat& inputPicture, int thresholdValue, int gaussKe // One (this) to do all kinds of stuff to the picture (grayscale conversion, threshold, gauss etc etc) // And one (the other one) to segment the lines. // No return value here as the input is passed by reference -> directly modified. - vector lines; + vector lines; cvtColor(inputPicture, inputPicture, COLOR_BGR2GRAY); threshold(inputPicture, inputPicture, thresholdValue, 255, THRESH_BINARY); @@ -39,6 +39,34 @@ void Processing::processImage(Mat& inputPicture, int thresholdValue, int gaussKe line( inputPicture, Point(lines[i][0], lines[i][1]), Point( lines[i][2], lines[i][3]), Scalar(0,0,255), 3, 8 ); } + vector vectors; + + Point point11; + Point point12; + Point point21; + Point point22; + + for( size_t i = 0; i < lines.size(); i++ ) + { + point11 = Point(lines[i][0], lines[i][1]); + point12 = Point( lines[i][2], lines[i][3]); + float gradient1 = VectorOfLines::calcGradient(point11, point12); + for( size_t j = 0; j < lines.size(); j++ ) + { + if(j != i){ + point21 = Point(lines[j][0], lines[j][1]); + point22 = Point(lines[j][2], lines[j][3]); + float gradient2 = VectorOfLines::calcGradient(point21, point22); + float gradient12 = VectorOfLines::calcGradient(point12, point21); + if((norm(gradient1 - gradient2) < 0.05) & (norm(gradient1 - gradient12) < 0.05)) + { + //To Do: add line between 2 lines + } + + } + } + } + imshow("Result", inputPicture); waitKey(0); diff --git a/Utils/utils.cpp b/Utils/utils.cpp index c170b5c..083e86c 100644 --- a/Utils/utils.cpp +++ b/Utils/utils.cpp @@ -45,3 +45,17 @@ LFRLine::LFRLine(LFRPoint start, LFRPoint end) : start(start) LFRLine::~LFRLine() { } + +VectorOfLines::VectorOfLines() +{ +} + +float VectorOfLines::calcGradient(Point p0, Point p1) +{ + return (p1.y - p0.y)/(p1.x - p0.x); +} + +float VectorOfLines::calcZeroPoint(cv::Point x, float m) +{ + +} \ No newline at end of file diff --git a/Utils/utils.h b/Utils/utils.h index c30d401..dd0cd01 100644 --- a/Utils/utils.h +++ b/Utils/utils.h @@ -49,14 +49,14 @@ public: class VectorOfLines{ private: - float theta; - float m; - float zeroPoint; public: + Point startPoint; + float gradient; + float zeroPoint; VectorOfLines(); ~VectorOfLines(); - float calcTheta(cv::Point x, Point y); - float calcM(float theta); + static float calcGradient(Point x, Point y); float calcZeroPoint(cv::Point x, float m); + }; \ No newline at end of file