I'm a beginner and I'm trying to do some line detection in-game. This is the photo in which I'm trying to detect lanes This is the result The HoughLinesP code: ``` lines = cv2.HoughLinesP(cropped_image, 2, np.pi / 180, 100, np.array([]), minLineLength=50, maxLineGap=5)
# The displaying function:
def displayLines(image, lines):
line_image = np.zeros_like(image)
if lines is not None:
for line in lines:
x1, x2, y1, y2 = line.reshape(4)
cv2.line(line_image, (x1, x2), (x2, y2), (0,255,0), 10)
return line_image```
# Here is the cropping function:
def region(image):
height = image.shape[0]
polygons = np.array([[
(570, 640), (1600, 700), (863, 520)
]])
mask = np.zeros_like(image)
cv2.fillPoly(mask, polygons, 255)
masked_image = cv2.bitwise_and(canny, mask)
return masked_image
#As input I'm giving image with edges displayed. Function:
def canny(image):
gray = cv2.cvtColor(lane_image, cv2.COLOR_RGB2GRAY)
blur = cv2.GaussianBlur(gray, (5,5),0)
canny = cv2.Canny(blur, 50, 150)
return canny
I don't know what is the problem
I recommend you mask out the noise before attempting to detect lines:
Output:
Where the
are the lower and upper values for the HSV color mask. With the above mask, you won't even need the
cv2.HoughLinesP
method; you can simply detect the contours of the non-masked object and approximate the results:Output: