









Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
The process of analyzing and detecting lanes in images using the opencv library. It covers the key steps involved, including edge detection using the canny algorithm, creating a region of interest mask, and applying the hough transform to identify the lines representing the lanes. The document also discusses challenges such as image noise, blur ratio, and decimal precision issues in the slope and y-intercept calculations. The provided code demonstrates the implementation of these techniques and the resulting visualizations of the detected lanes. This information could be valuable for students and researchers interested in computer vision, advanced driver-assistance systems (adas), and autonomous vehicle development.
Typology: Transcriptions
1 / 16
This page cannot be seen from the preview
Don't miss anything!










Name: Chau Tu Uyen Student ID: 200109 Course: Intelligent Robot Studio: From Theory to Practice Instructor: Dr. Phung Manh Duong Date of submission: December 18th, 2022
the digital world is made up of pixels. In a black-and-white image, a pixel contains the intensity
2.1. Gaussian Blur The gaussian blur tool is used to smooth and reduce the noise of an image, which can be detected as an edge. In function cv.GaussianBlur(), the width and height value of gaussian kernel calculated in the function must be specified and the value must be positive and odd. The higher the value, the more blurrier the image. This image is blurred by function: cv2.GaussianBlur(image, (23,23),0). 23,23 stands for width and height value of Gaussian kernel. 2.2. Edge Detection An image contains many pixels. The image can be represented in 2d space in the computer world, where x is the width and y is the height. To detect an edge, Canny will scan for the strong gradient in the image and compute the image from all directions on the x-axis and y- axis to measure the change of the strong gradient for edge detection. This figure is made by the Canny's edge detect function:
2.4. Hough Transform Hough Transform will examine the pixels to check if it is on the same line to detect that line on the image. Its function on OpenCV is shown as below: cv.HoughLinesP(image, rho, theta, threshold, lines, minLineLength, maxLineGap) with the arguments: image: Output of Canna or any edge detected function lines: will store the parameters of detected line (xstart, ystart, xend, yend) rho: resolution of r in pixel theta: Resolution of θ calculated by radian, I will use 1 degree (np.pi/180) = pi/180 = 180/180 = 1 threshold: The minimum number of votes to detect a line minLineLength: the minimum number of points to create a line maxLineGap: The maximum gap between two points to be considered in the same line. The figure below shows the process of increasing one vote unit with a theta value of 22. degrees and a rho value of 1 pixel:
The figure below shows lines detected by Hough Transform used on the masked edge detection image.
Figure1c: Figure1d:
4.3. Finding mask In edge detection, I have to minimize the region of interest I want to capture the edge. The figures below show that if the region of interest is not masked, many unwanted edges are detected, resulting in unwanted lines being detected and affecting the accuracy of the average of the left, right and middle lines: 4.4. Hough Transform function Due to the low resolution of figure1a, I have to increase the rho value to 2, which will affect the accuracy of the detected line. To increase accuracy, a trial-and-error procedure is required to find the sweet spot of the threshold (60) and the minimum length (30) needed for the four provided figures. 4.5. Decimal problem in slope and y intercept equation The equation of slope and y-intercept creates a significant decimal problem, which lowers the program’s performance. To solve this problem, I minimize it to 2 decimals.
points = np.array([ [(0, img_edge.shape[0]), (img_edge.shape[1], img_edge.shape[0]), (img_edge.shape[1], int(img_edge.shape[0]/4)), (0, int(img_edge.shape[0]/4))] ]) #create black image with the same resolution of original image mask = np.zeros_like(img_edge) #add white(255.255.255) rectange (based on 4 points which created above) to the black image cv2.fillPoly(mask,points, color=(255, 255, 255)) #mask the original image to the rectange, the black still remain masked_image = cv2.bitwise_and(img_edge, mask) #Why create mask? To minimize region of edge detect => minimize detect error #Find line points with Hough transform algorithm on masked_img lines = cv2.HoughLinesP(masked_image, rho = 2, theta = np.pi/180, threshold = 60, lines = np.array([]), minLineLength=30,
x2_avg_R = int((y2_avg_R - right_average[1])/right_average[0]) # x = (y-y_intercept)/slope #create 4 points of middle line based on average of left line and right line y1_M = img.shape[0] #start point y (full img) y2_M = 0 #end point y (full img) x1_M = int((x1_avg_L+x1_avg_R)/2) # x1_M = (x1_L + x1_R)/ x2_M = int((x2_avg_L+x2_avg_R)/2) # x2_M = (x2_L + x2_R)/ #draw line on image cv2.line(img_line,(x1_avg_L,y1_avg_L),(x2_avg_L,y2_avg_L),(255,0,0),2) cv2.line(img_line,(x1_avg_R,y1_avg_R),(x2_avg_R,y2_avg_R),(255,0,0),2) cv2.line(img_line,(x1_M,y1_M),(x2_M,y2_M),(0,0,255),2) plt.figure(1) plt.subplot(331).axis('off'),plt.imshow(cv2.cvtColor(img, cv2.COLOR_BGR2RGB)),plt.title('Original image') plt.subplot(332).axis('off'),plt.imshow(cv2.cvtColor(img_gray, cv2.COLOR_BGR2RGB)),plt.title('Gray image') plt.subplot(333).axis('off'),plt.imshow(cv2.cvtColor(img_blur, cv2.COLOR_BGR2RGB)),plt.title('Blur the image') plt.subplot(334).axis('off'),plt.imshow(cv2.cvtColor(img_edge, cv2.COLOR_BGR2RGB),cmap = "gray"),plt.title('Edge detection') plt.subplot(335).axis('off'),plt.imshow(cv2.cvtColor(mask, cv2.COLOR_BGR2RGB)),plt.title('Mask') plt.subplot(336).axis('off'),plt.imshow(cv2.cvtColor(masked_image, cv2.COLOR_BGR2RGB)),plt.title('Masked edge detect image') plt.subplot(337).axis('off'),plt.imshow(cv2.cvtColor(img_line_add, cv2.COLOR_BGR2RGB)),plt.title('Detected lines') plt.subplot(338).axis('off'),plt.imshow(cv2.cvtColor(img_line, cv2.COLOR_BGR2RGB)),plt.title('Average lines') plt.show()