Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Need code with improvements for project presentation and explanation what improvements made in project topic - Road Lane line Detection opencv python Need code with

Need code with improvements for project presentation and explanation what improvements made in project

topic - Road Lane line Detection opencv python

Need code with improvements with explation what improvements made for show in project

import cv2 import numpy as np

# Read in the image img = cv2.imread('road.jpg')

# Convert the image to grayscale gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)

# Apply Gaussian blur to reduce noise blur = cv2.GaussianBlur(gray, (5, 5), 0)

# Apply Canny edge detection to detect edges edges = cv2.Canny(blur, 50, 150)

# Apply a region of interest mask to focus on the area where the lane lines are mask = np.zeros_like(edges) height, width = img.shape[:2] vertices = np.array([[(0, height), (width/2, height/2), (width, height)]], dtype=np.int32) cv2.fillPoly(mask, vertices, 255) masked_edges = cv2.bitwise_and(edges, mask)

# Apply Hough transform to detect lines rho = 1 theta = np.pi/180 threshold = 30 min_line_length = 50 max_line_gap = 20 lines = cv2.HoughLinesP(masked_edges, rho, theta, threshold, np.array([]), min_line_length, max_line_gap)

# Draw the detected lines on the original image line_img = np.zeros_like(img) for line in lines: for x1, y1, x2, y2 in line: cv2.line(line_img, (x1, y1), (x2, y2), (0, 0, 255), 5)

# Combine the original image with the detected lines result = cv2.addWeighted(img, 0.8, line_img, 1, 0)

# Display the result #cv2.imshow('img', img) #cv2.imshow('Grey', gray) #cv2.imshow('Blur', blur) cv2.imshow('Edges', edges) cv2.imshow('masked_edges', masked_edges) #cv2.imshow('lines', lines) cv2.imshow('line_img', line_img) cv2.imshow('Result', result)

cv2.waitKey() cv2.destroyAllWindows()

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Joe Celkos Data And Databases Concepts In Practice

Authors: Joe Celko

1st Edition

1558604324, 978-1558604322

More Books

Students also viewed these Databases questions