1

Actually, I am noob for working with Computer Vision. Sorry in advance.

I want to detect edges of tram lane. Mostly, the code works well but sometimes It cannot even draw a line. I don't know why.

cropped_Image function is just cropping the polygonal area of the current frame.

display_lines function draw lines whose absolute value of angle is between 30 and 90. It uses cv2.line to draw lines.

Here is the code:

_,frame = cap.read()
gray = cv2.cvtColor(frame, cv2.COLOR_RGB2GRAY)  # convert image to gray to be one layer
blur = cv2.GaussianBlur(gray, (1, 1), 0)  # to reduce noise in gray scale image
canny = cv2.Canny(blur, 150, 200, apertureSize=3)
cropped_image = region_of_interest(canny) # simply, it crops bottom  of image 
lines = cv2.HoughLinesP(cropped_image, 1, np.pi / 180, 100, np.array([]), 
minLineLength=5, maxLineGap=5)

hough_bundler = HoughBundler()
lines_merged = hough_bundler.process_lines(lines, cropped_image)
line_image = display_lines(frame, lines_merged)
combo_image = cv2.addWeighted(frame, 0.8, line_image, 1, 1)
cv2.imshow(‘test’, combo_image)

To see it: HoughBundler

Expected: expected img

Canny: canny img of wrong result

Result: wrong result

Metomania
  • 11
  • 3

1 Answers1

2

First of all I'd start by fixing the cv2.GuassianBlur() line. You've used a 1x1 kernel which doesn't do anything, you need to use at least a 3x3 kernel. Look into how convolutions are applied if you want to know why a 1x1 filter doesn't work. Secondly, I would play with the Canny aperture size to suit my needs. Also after edge detection you can use cv2.erode() with a 3x3 or 5x5 kernel so that you don't get a broken line in the image.