From d66e5d05b2708d5322d01946411b27f502623ffa Mon Sep 17 00:00:00 2001 From: TimZnr Date: Fri, 9 Dec 2022 15:29:01 +0100 Subject: [PATCH] introduce checkIntersection --- AutonomousMode/Processing/processing.cpp | 60 ++++++++++++++---------- AutonomousMode/Processing/processing.h | 1 + 2 files changed, 35 insertions(+), 26 deletions(-) diff --git a/AutonomousMode/Processing/processing.cpp b/AutonomousMode/Processing/processing.cpp index 8a31f7a..181f677 100644 --- a/AutonomousMode/Processing/processing.cpp +++ b/AutonomousMode/Processing/processing.cpp @@ -47,24 +47,6 @@ void Processing::filterReflections(FrameData& frameData) indicesToDelete.push_back(i); continue; } - - // Third approach: - // Calculate the HoughLinesP of the contour. - // There should be 4 lines - // This one is not really working yet. - Rect boundingRect = cv::boundingRect(frameData.contours[i]); - Point offset(-boundingRect.x, -boundingRect.y); - Mat contourMat = Mat::zeros(frameData.boundingBoxes[i].height, frameData.boundingBoxes[i].width, CV_8UC1); - drawContours(contourMat, frameData.contours, i, Scalar(255,255,255), 1, 8, noArray(), 0, offset); - std::vector linesP; - HoughLinesP(contourMat, linesP, 1, CV_PI/180, 20, 10, 5 ); - //imshow("Some window", contourMat); - if(linesP.size() < 4) - { - //indicesToDelete.push_back(i); - //continue; - //std::cout << linesP.size(); - } } //reverse the vector with the indices so the order isn't messed up when deleting: @@ -79,6 +61,28 @@ void Processing::filterReflections(FrameData& frameData) return; } +bool Processing::checkIntersection(const std::vector>& lines, const std::vector& outline) +{ + + /* TODO: + * Was ich mir hier vorstelle: + * Wir haben die konturen und die hough linien + * Konturen haben schwäche mit Reflektionen, hough linien sind unvollständig. + * Irgendwie sollten die beiden Datensätze gemerged werden, um das "gute" aus beiden zu vereinen. + * Evtl in richtung "Schau den Bereich der Contour (+ Toleranz?) im hough bild an. Wenn keine Linie im Bereich ist, ist die Contour eine Reflektion" + * + * Aktuell nehmen wir die abkürzung, die segmente rauszuwerfen, sobald keine Linie im Bild ist. + * Funktioniert für unsere Daten auch ziemlich gut + */ + + if(lines.size() == 0) + { + return false; + } + return true; +} + + void Processing::processImage(Mat& inputPicture, int thresholdBinary, int gaussKernelSize) { //Idea here is: Processing module consists of two methods: @@ -101,15 +105,8 @@ FrameData Processing::calculateLineSegments(Mat& inputPicture, const cv::Rect& r Mat inputPictureRoi = inputPicture(roi); cv::findContours(inputPictureRoi, data.contours, RETR_LIST, CHAIN_APPROX_SIMPLE); - /* TODO: - * Was ich mir hier vorstelle: - * Wir haben die konturen und die hough linien - * Konturen haben schwäche mit Reflektionen, hough linien sind unvollständig. - * Irgendwie sollten die beiden Datensätze gemerged werden, um das "gute" aus beiden zu vereinen. - * Evtl in richtung "Schau den Bereich der Contour (+ Toleranz?) im hough bild an. Wenn keine Linie im Bereich ist, ist die Contour eine Reflektion" - */ - vector lines; + std::vector> houghLines; Canny(inputPicture, inputPicture, 50, 100, 3); HoughLinesP(inputPicture, lines, 1, CV_PI/180, 100, 30, 150); //Draw lines @@ -118,6 +115,10 @@ FrameData Processing::calculateLineSegments(Mat& inputPicture, const cv::Rect& r for( size_t i = 0; i < lines.size(); i++ ) { line( inputPicture, Point(lines[i][0], lines[i][1]), Point(lines[i][2], lines[i][3]), Scalar(255,255,255), 3, 8 ); + std::vector line; + line.push_back(Point(lines[i][0], lines[i][1])); + line.push_back(Point(lines[i][2], lines[i][3])); + houghLines.push_back(line); } @@ -129,8 +130,15 @@ FrameData Processing::calculateLineSegments(Mat& inputPicture, const cv::Rect& r { iterator = data.contours.erase(iterator); } + else if (!checkIntersection(houghLines, *iterator)) + { + iterator = data.contours.erase(iterator); + } else { + //Check for intersection with lines: + + Rect boundingBox = boundingRect(*iterator); boundingBox.x += roi.x; boundingBox.y += roi.y; diff --git a/AutonomousMode/Processing/processing.h b/AutonomousMode/Processing/processing.h index 7586655..522cb9f 100644 --- a/AutonomousMode/Processing/processing.h +++ b/AutonomousMode/Processing/processing.h @@ -10,6 +10,7 @@ class Processing { private: /* data */ + bool checkIntersection(const std::vector>& lines, const std::vector& outline); public: Processing(/* args */); // To do: