{"id":25155476,"url":"https://github.com/ddayto21/self-driving-car-","last_synced_at":"2025-10-13T01:39:31.271Z","repository":{"id":43920222,"uuid":"511777034","full_name":"ddayto21/Self-Driving-Car-","owner":"ddayto21","description":"This Python repository implements lane detection techniques using OpenCV which is the open-source library used for computer vision, machine learning and image processing. ","archived":false,"fork":false,"pushed_at":"2022-07-18T22:46:51.000Z","size":30421,"stargazers_count":11,"open_issues_count":0,"forks_count":3,"subscribers_count":1,"default_branch":"main","last_synced_at":"2023-08-26T20:25:15.806Z","etag":null,"topics":["computer-vision","opencv","python","self-driving-car"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/ddayto21.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2022-07-08T05:44:58.000Z","updated_at":"2023-04-24T15:25:41.000Z","dependencies_parsed_at":"2022-08-19T07:51:08.687Z","dependency_job_id":null,"html_url":"https://github.com/ddayto21/Self-Driving-Car-","commit_stats":null,"previous_names":[],"tags_count":0,"template":null,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ddayto21%2FSelf-Driving-Car-","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ddayto21%2FSelf-Driving-Car-/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ddayto21%2FSelf-Driving-Car-/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ddayto21%2FSelf-Driving-Car-/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ddayto21","download_url":"https://codeload.github.com/ddayto21/Self-Driving-Car-/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":237890767,"owners_count":19382564,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["computer-vision","opencv","python","self-driving-car"],"created_at":"2025-02-09T00:51:56.760Z","updated_at":"2025-10-13T01:39:26.238Z","avatar_url":"https://github.com/ddayto21.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Repository Overview \nThis repository contains Python code for self-driving cars that use computer vision and deep learning techniques to address problems that autonomous vehicles face, such as detecting lane lines and predicting steering angles in real-time.\n\n\n## Project Setup\n\n### OpenCV Installation\n![OpenCV](screenshots/opencv.png)\n\nOpenCV stands for “Open Source Computer Vision” is a library for computer vision and machine learning software library. OpenCV has C++, Python, Java and MATLAB interfaces and supports Windows, Linux, Android, and Mac OS. \n\n```\n$ pip install opencv-python\n```\n\n## Use OpenCV to Load Image \nThe cv2.imread() method loads an image from the specified file. We read the .jpg file as an RGB image. If the image cannot be read (because of missing file, improper permissions, unsupported or invalid format) then this method returns an empty matrix.\n\n```python\nimage = cv2.imread('/data/Lane_Original.jpg')\n```\n### Original Image\n![Original-Image](screenshots/Lane_Original.jpg)\n\nIn a real-life scenario, an autonomous vehicle would process a video instead of an image, but for the sake of learning, we demonstrate how to detect the lanes in a particular image first. \n\n## Apply Edge Detection Algorithm to Image\nThe Canny Edge Detector is an edge detection operator that uses a multi-stage algorithm to detect a wide range of edges in images\n\n```python\ndef detect_edges(image):\n    grayscale_image = cv2.cvtColor(image, cv2.COLOR_RGB2GRAY)    \n    blurred_image = cv2.GaussianBlur(grayscale_image, (5,5), 0)\n    edges = cv2.Canny(blurred_image, 50, 150)  \n    return edges   \n```\n\n### Convert RGB Image to Grayscale\nBefore applying the lane detection algorithm to our image, we need to convert the RGB Image to a Grayscale Image because the Canny Detection Algorithm can only be applied on a 2-Dimensional Image. In order to achieve this, use the cvtColor function to convert the image from a color space to another.\n\n```python\ngrayscale_image = cv2.cvtColor(image, cv2.COLOR_RGB2GRAY)    \n```\n\n![Gray-Image](screenshots/Lane_GrayScale.jpg)\n\nAs first input, this function receives the original image. As second input, it receives the color space conversion code. Since we want to convert our original image from the BGR color space to gray, we use the code COLOR_BGR2GRAY. Essentially, we are reducing the complexity of the image by transforming a 3D Array (RGB Image) into a 2D Array (Grayscale Image). \n\n### Reduce Image Noise\nWe apply a Gaussian Blur to the 2-D Grayscale Image using the OpenCV library by calculating the gradient in all directions in the image. The second and third parameter of the GaussianBlur() function represent the kernel size and the number of dimensions.\n\n```python\nblurred_image = cv2.GaussianBlur(grayscale_image, (5,5), 0) \n```\n\n### Canny Edge Detection Algorithm\nWe use the OpenCV Library to implement the Canny Edge Detection Algorithm to the blurred image. The second and third parameters represent the low and high threshold of the image.\n\n```python\nedges = cv2.Canny(blurred_image, 50, 150)  \n```\n\n## Generate Region of Interest Mask\nThe following block of code uses NumPy to generate a matrix of 0s and 1s to represent our region of interest, the road in the image. \n\n```python\nheight = image.shape[0]\nvertices = np.array([(200, height), (1100, height), (550, 250)])\nmask = np.zeros_like(image) \ncv2.fillPoly(mask, np.int32([vertices]), 255) \n```\n\n![ROI-White-Mask](screenshots/Region-Of-Interest-Mask.jpg)\nThe white and black regions are represented by pixel values of 1 and 0, respectively.\n\n\n## Hough Transformation\n```python\ndetected_lines = cv2.HoughLinesP(cropped_image, 2, np.pi/180, 100, np.array([]), minLineLength=40, maxLineGap=5)\n```\n\n### Make Coordinates\n```python\ndef make_coordinates(image, line_parameters):\n    slope, intercept = line_parameters\n    y1 = image.shape[0]\n    y2 = int(y1 * (3/5))    \n    x1 = int((y1 - intercept) / slope) # The function: [x = (y-b) / x] is derived from the function: [y = mx+b]\n    x2 = int((y2 - intercept)/ slope)\n    return np.array([x1, y1, x2, y2])\n```\n\n### Average Slope Intercept\n```python\ndef average_slope_intercept(image, lines):\n    left_fit = [] \n    right_fit = [] \n    for line in lines:\n        x1, y1, x2, y2 = line.reshape(4)\n        parameters = np.polyfit((x1, x2), (y1,y2), 1)\n        slope = parameters[0]\n        intercept = parameters[1]\n        if slope \u003c 0: \n            left_fit.append((slope, intercept))\n        else:\n            right_fit.append((slope, intercept))\n    left_fit_avg = np.average(left_fit, axis=0)\n    right_fit_avg = np.average(right_fit, axis=0)    \n    left_line = make_coordinates(image, left_fit_avg)\n    right_line = make_coordinates(image, right_fit_avg)\n    return np.array([left_line, right_line])\n```\n\n\n\n## Use Mask to Display Lane Lines\n```python\ndef display_lines(image, lines):\n    line_image = np.zeros_like(image)\n    if lines is not None:\n        for line in lines:\n            x1, y1, x2, y2 = line.reshape(4)\n            cv2.line(line_image, (x1, y1), (x2, y2), (255,0,0), 10)\n    return line_image\n```\n\n![Detected-Lines](screenshots/Combo-Image.jpg)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fddayto21%2Fself-driving-car-","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fddayto21%2Fself-driving-car-","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fddayto21%2Fself-driving-car-/lists"}