introduce checkIntersection
This commit is contained in:
parent
103eeadf0b
commit
d66e5d05b2
@ -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<Vec4i> 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<std::vector<Point>>& lines, const std::vector<Point>& 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<Vec4i> lines;
|
||||
std::vector<std::vector<Point>> 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<Point> 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;
|
||||
|
@ -10,6 +10,7 @@ class Processing
|
||||
{
|
||||
private:
|
||||
/* data */
|
||||
bool checkIntersection(const std::vector<std::vector<Point>>& lines, const std::vector<Point>& outline);
|
||||
public:
|
||||
Processing(/* args */);
|
||||
// To do:
|
||||
|
Loading…
x
Reference in New Issue
Block a user