verbesserte Linienerkennung
This commit is contained in:
+10
-56
@@ -23,66 +23,20 @@ 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<Vec4i> lines;
|
||||
|
||||
cvtColor(inputPicture, inputPicture, COLOR_BGR2GRAY);
|
||||
threshold(inputPicture, inputPicture, thresholdValue, 255, THRESH_BINARY);
|
||||
GaussianBlur(inputPicture, inputPicture, Size(gaussKernelSize, gaussKernelSize), 0);
|
||||
|
||||
Canny(inputPicture, inputPicture, 50, 200, 3);
|
||||
|
||||
HoughLinesP(inputPicture, lines, 1, CV_PI/180, 150, 0, 0);
|
||||
//Draw lines
|
||||
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(0,0,255), 3, 8 );
|
||||
}
|
||||
vector<VectorOfLines> 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);
|
||||
destroyWindow("Result");
|
||||
|
||||
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(0,0,255), 3, 8 );
|
||||
|
||||
}
|
||||
|
||||
GaussianBlur(inputPicture, inputPicture, Size(gaussKernelSize, gaussKernelSize), 0);
|
||||
Canny(inputPicture, inputPicture, 50, 100, 3);
|
||||
}
|
||||
|
||||
std::vector<LFRLine> Processing::calculateLineSegments(const Mat& inputPicture)
|
||||
std::vector<Vec4i> Processing::calculateLineSegments(const Mat& inputPicture)
|
||||
{
|
||||
//See following link
|
||||
//https://stackoverflow.com/questions/45322630/how-to-detect-lines-in-opencv
|
||||
return std::vector<LFRLine>();
|
||||
vector<Vec4i> lines;
|
||||
VectorOfLines linesInVectors;
|
||||
HoughLinesP(inputPicture, lines, 1, CV_PI/360, 150, 0, 250);
|
||||
//lines = linesInVectors.findMiddleLine(lines);
|
||||
|
||||
return lines;
|
||||
}
|
||||
|
||||
@@ -21,5 +21,5 @@ public:
|
||||
|
||||
void processImage(Mat& inputPicture, int thresholdValue, int gaussKernelSize);
|
||||
|
||||
std::vector<LFRLine> calculateLineSegments(const Mat& inputPicture);
|
||||
std::vector<Vec4i> calculateLineSegments(const Mat& inputPicture);
|
||||
};
|
||||
Reference in New Issue
Block a user