Quantcast
Channel: Active questions tagged python - Stack Overflow
Viewing all articles
Browse latest Browse all 23131

Unable to get left and right road edge

$
0
0

I am trying to find the points representing the left and right edge of a road mask(binary image). I have tried using contour detection but it is giving contour of whole image(including upper and lower edge, have attached image of it).

What I want is 2 array, representing the points of left and right road edge. What i am getting is a long list(Contour) of points including the lower part of the road as well. I have tried filtering unnecessary points by removing those points from the array which are close to the boundary and now i am left with an array containing the points from only left and right road edge but now it is difficult to tell which point belongs to which road edge(left or right).
Apart from this, i have used sobel edge detection but it dosent tells the points and only produces an image. I even thought of applying contour detection on the output of sobel edge detector but it is leading to some incompatibility issue.

Code:

import cv2import numpy as npimage = cv2.imread('/home/user/Desktop/seg_output/1.jpg')gray_image = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)_, binary_image = cv2.threshold(gray_image, 127, 255, cv2.THRESH_BINARY)contours, _ = cv2.findContours(binary_image, cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_SIMPLE)# Sort contours based on their areacontours = sorted(contours, key=cv2.contourArea, reverse=True)print("Contours: ", np.squeeze(contours[0]))print("Contours shape: ", len(contours))contour_image = cv2.drawContours(image.copy(), contours, 0, (0, 255, 0), 2)print("Output Shape: ", contour_image.shape)cv2.imshow('Contours', contour_image)cv2.waitKey(0)cv2.destroyAllWindows()

Input Image:Initial Input Image

Output Image:Image representing the whole contout including lower boundary


Viewing all articles
Browse latest Browse all 23131

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>