Saurabh
Saurabh

Reputation: 1672

How to detect street lines in satellite aerial image using openCV?

I am really new to openCV,I have to detect lines of streets in sattelite imagery

this is the original image

enter image description here

I applied different thresholds and I am able to differentiate background and fg

retval, threshold = cv2.threshold(img1,150, 255, cv2.THRESH_BINARY)
plt.imshow(threshold)

enter image description here

after this, I smoothened to remove noise for HoughLines

# Initialize output
out = cv2.cvtColor(threshold, cv2.COLOR_GRAY2BGR)

# Median blurring to get rid of the noise; invert image
threshold_blur = 255 - cv2.medianBlur(threshold, 5)

plt.imshow(threshold_blur,cmap='gray', vmin = 0, vmax = 255)

enter image description here

Now when I applied hough lines I am getting this

# Detect and draw lines
lines = cv2.HoughLinesP(threshold_blur, 1, np.pi/180, 10, minLineLength=10, maxLineGap=100)
for line in lines:
    for x1, y1, x2, y2 in line:
        cv2.line(out, (x1, y1), (x2, y2), (0, 0, 255), 2)

plt.imshow(out)

enter image description here

I need lines like this

enter image description here

Why it's not working and what should I do?

Upvotes: 4

Views: 2415

Answers (1)

Jop Knoppers
Jop Knoppers

Reputation: 714

Not sure if you would want to do this with only with openCV you may also want to use something like tensorflow.

But if you want to use only openCV here are a few options:

You could try to do dilate and erode. And use findContours, and loop through those contours to find objects with a certain minimum length, and use that to create a line from A to B.

Another solution would be to train a cascade to detect parts of the images that are street sections and connect those points. This is a lot more time consuming though.

Upvotes: 1

Related Questions