My project is to detect the lines on a picture, I know using houghline function(openCVsharp), but the result gives me many parallel lines. Could you guide me on how to merge these parallel lines?
var gray = OpenCvSharp.Cv2.ImRead(filename, OpenCvSharp.ImreadModes.Grayscale);
var binary = gray.Threshold(0, 255, OpenCvSharp.ThresholdTypes.BinaryInv | OpenCvSharp.ThresholdTypes.Otsu);
var element = Cv2.GetStructuringElement(MorphShapes.Rect, new OpenCvSharp.Size(5, 5),
new OpenCvSharp.Point(-1, -1));
var Morp_out = new Mat();
Cv2.MorphologyEx(binary, Morp_out,MorphTypes.Open,element);
var Ero_out = new Mat();
Cv2.Erode(Morp_out, Ero_out, element);
using (new Window("Erode Image", WindowMode.AutoSize, Ero_out))
{
Window.WaitKey(0);
}
var processed_img = Ero_out;
double min_Line_length = 100;
double max_line_gap = 10;
double rho = 1;
double theta = Math.PI / 180;
int threshold = 100;
LineSegmentPoint[] setH_P = Cv2.HoughLinesP(processed_img, rho, theta, threshold, min_Line_length, max_line_gap);
Mat Img_outPut = processed_img.EmptyClone();
foreach (LineSegmentPoint s in setH_P)
{
Img_outPut.Line(s.P1, s.P2, Scalar.White, 1);
}
using (new Window("HoughLinesP", WindowMode.AutoSize, Img_outPut))
{
Window.WaitKey(0);
}
What I have tried:
My idea is
compare all possible line segment pairs, then check the distance between all possible endpoints, then compare it with a threshold, and draw it. However, I do not have any experience with programming, so it is kind of difficult for me to implement it