How to combine the dotted line algorithm

I am writing a tool where I can detect A4 paper. While I am doing this blurring of the image, I get the contours of the image. Then I use the Hough line definition to get all the lines in the image. The lines in the image below come out of my discovery.

What I want to do next is to combine all the lines with almost the same angle relative to each other. But I can't get this to work. So in the image below you can see that there are 5 lines on the top of the paper, and I need to combine them into 1. The same goes for all the other lines.

houghdetection

, ( ), . , , .

enter image description here

, , <= 2

Dim remove As New List(Of Integer)
    For i As Integer = 0 To lines.Length - 1
        For j As Integer = i + 1 To lines.Count - 1
            If Not remove.Contains(i) AndAlso Not remove.Contains(j) Then
                Dim pt As PointF = computeIntersect(lines(i).P1, lines(i).P2, lines(j).P1, lines(j).P2)
                If pt.X >= 0 AndAlso pt.Y >= 0 Then
                    Dim angle1 As Integer = GetAngleBetweenPoints(lines(i).P1, lines(i).P2)
                    Dim angle2 As Integer = GetAngleBetweenPoints(lines(j).P1, lines(j).P2)
                    If Math.Abs(angle1 - angle2) <= 2 Then
                        remove.Add(i)
                    End If
                End If
            End If
        Next
    Next
    Dim tmp As New List(Of LineSegment2D)
    For i As Integer = 0 To lines.Length - 1
        If Not remove.Contains(i) Then
            tmp.Add(lines(i))
        End If
    Next

, : , ?

+4
1

​​ . . - , " " " " 90 .

, , , (x1, y1) (x2, y2). ((x1 + x2)/2, (y1 + y2)/2). ((x1 + x2)/2 + y2 - y1, (y1 + y2)/2 + x1 - x2). ( y2-y1 x1-x2, .)

, , 10 , 88 92 , .

+1

Source: https://habr.com/ru/post/1618655/


All Articles