0

I'm struggling with a task in my project.
My task is to detect the border of solar panel in an image taken from UAV to further detect the solar panel itself. So first, I try to draw all horizontal lines from the image using HoughP with condition that the slope~0 and this is the result (lines found are shown in red color):

horizontal lines detected using HoughP

As you can see, there are several spurious lines. From this point, I need to filter out all those spurious lines and get the only line that represent to border of those solar panels, like this:

lines indicate border of solar panel

Actually I'm reading from a research document telling that they used Hierarchical clustering algorithm to fuse all the line close together within a certain distance d?
I learn about this Hierarchical clustering algorithm and the thing is I don't know how to apply this algorithm for linear lines and how to actually "fuse" several lines that are close together into one?
Can someone enlighten me please.

1 Answers1

0

To apply any clustering algorithm you need to define some distance measure on the objects you want to cluster. For line segments, the most obvious distance I can think of is the minimum distance between any pair of points from the two segments, i.e.:

def line_distance(line1, line2):
    return min( point_distance(point1, point2) for point1 in line1 for point2 in line2 )

You can then apply hierarchical clustering on the set of lines you get, using this distance measure and some threshold distance d to merge two lines.

However, I feel it's better to binarize the image before passing it to edge detector since the panel and its border has quite contrasting colors and that alone might reduce many spurious lines.

zwang
  • 357
  • 1
  • 8
  • so many thanks @zwang, your answer help me a lot. I think now I know what do to with the Hierarchical Clustering algorithm. But I have one question left, how can you actually merge the lines together? My idea is, for each cluster, take the average rho and theta of the lines and draw the line with average rho and theta in that cluster? Do you think this is an proper approach? – KhoaLearnToCode Aug 03 '20 at 08:34
  • @KhoaLearnToCode That seems fine to me. Just bear in mind that when averaging over lines, each line receives equal weights so if you want longer line segments to have more weights you need to adjust for that. – zwang Aug 03 '20 at 08:51
  • oh I see. Thanks again zwan – KhoaLearnToCode Aug 03 '20 at 08:59