{"id":26896076,"url":"https://github.com/sofiasawczenko/lane_detection_opencv","last_synced_at":"2025-04-01T02:59:34.489Z","repository":{"id":82609544,"uuid":"588271519","full_name":"sofiasawczenko/lane_detection_OpenCV","owner":"sofiasawczenko","description":"Utilizando o OpenCV para processamento de imagem","archived":false,"fork":false,"pushed_at":"2024-12-18T00:20:24.000Z","size":1508,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"main","last_synced_at":"2024-12-18T01:26:28.968Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Jupyter Notebook","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/sofiasawczenko.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,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2023-01-12T18:24:15.000Z","updated_at":"2024-12-18T00:20:27.000Z","dependencies_parsed_at":"2024-12-18T01:26:33.318Z","dependency_job_id":"ebdaf619-ba8a-4f0c-b8d8-656832fa50a2","html_url":"https://github.com/sofiasawczenko/lane_detection_OpenCV","commit_stats":null,"previous_names":["sofiasawczenko/image_processing_using_opencv","sofiasawczenko/lane_detection_opencv"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sofiasawczenko%2Flane_detection_OpenCV","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sofiasawczenko%2Flane_detection_OpenCV/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sofiasawczenko%2Flane_detection_OpenCV/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sofiasawczenko%2Flane_detection_OpenCV/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/sofiasawczenko","download_url":"https://codeload.github.com/sofiasawczenko/lane_detection_OpenCV/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":246574843,"owners_count":20799221,"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":[],"created_at":"2025-04-01T02:59:34.000Z","updated_at":"2025-04-01T02:59:34.484Z","avatar_url":"https://github.com/sofiasawczenko.png","language":"Jupyter Notebook","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Lane Detection using OpenCV\n\n![image](https://github.com/user-attachments/assets/af443404-6097-4867-a909-48f07f77624a)\n\nThis project demonstrates the use of **OpenCV** for lane detection on street images. The goal is to process the image, detect edges using the Canny edge detector, apply a mask to focus on the region of interest, and then extract the lane boundaries.\n\n![image](https://github.com/user-attachments/assets/af2f5ddf-c50d-4ce8-9517-d0f45ed79a1a)\n\n## Requirements\n\nThis project requires the following libraries:\n\n- OpenCV (`cv2`)\n- NumPy (`numpy`)\n- Matplotlib (`matplotlib`)\n- Google Colab's file upload functionality (`google.colab`)\n\nYou can install the required libraries using `pip` if they are not already installed:\n\n```bash\npip install opencv-python numpy matplotlib\n```\n\n## Project Overview\n\n### 1. Import Libraries\nWe start by importing necessary libraries for image processing and visualization.\n\n```bash\nimport cv2 as cv\nfrom google.colab import files\nimport matplotlib.pyplot as plt\nimport numpy as np\n```\n\n### 2. Upload Image\nYou can upload your own image for lane detection using the file upload widget in Google Colab.\n\n```bash\nupload = files.upload()\n### 3. Image Preparation\nWe load the image, check its type, and print its dimensions.\n```\n\n```bash\nimagem = (r'lane_detection.jpeg')\nimg_cv = cv.imread(imagem)\nprint(type(img_cv))\nprint('Tamanho da imagem: ', img_cv.shape)\n```\n\n###4. Convert Image to RGB\nNext, we convert the image from BGR (default in OpenCV) to RGB for visualization.\n\n```bash\nimg = cv.cvtColor(img_cv, cv.COLOR_BGR2RGB)\nplt.imshow(img)\n```\n\n### 5. Convert Image to Grayscale\nSince edge detection works best with grayscale images, we convert the image to grayscale.\n\n```bash\nimg_gray = cv.cvtColor(img, cv.COLOR_RGB2GRAY)\nplt.imshow(img_gray, cmap=plt.cm.gray)\n```\n\n### 6. Canny Edge Detection\nWe use the Canny edge detection algorithm to detect edges in the grayscale image.\n\n```bash\nlinhas = cv.Canny(img_gray, 100, 200)\nplt.imshow(linhas, cmap='gray')\nplt.show()\n```\n\n### 7. Automatic Threshold for Canny Edge Detection\nA function auto_canny is created to automatically determine the threshold values for Canny edge detection.\n\n```bash\ndef auto_canny(image, sigma=0.33):\n    v = np.median(image)\n    lower = int(max(0, (1.0 - sigma) * v))\n    upper = int(min(255, (1.0 + sigma) * v))\n    edged = cv.Canny(image, lower, upper)\n    return edged\n\nimg_canny = auto_canny(img)\nplt.imshow(img_canny)\n8. Creating a Mask for Region of Interest\nWe define a polygon that isolates the region of interest (the area where the lane is located) and apply it as a mask.\n```\n\n```bash\nmask = np.zeros_like(img_canny)\nh, w = img_canny.shape\npts = np.array([[50,h],[300,240],[400,240],[650,h]], dtype=np.int32)\nmask_filled = cv.fillPoly(mask, [pts], (255, 255, 255))\nplt.imshow(mask_filled)\n```\n\n### 9. Apply Mask to Edge Image\nWe apply the mask to the edge-detected image to focus on the region of interest.\n\n```bash\nmasked_image = cv.bitwise_and(img_canny, mask_filled)\nplt.imshow(masked_image)\n```\n\nImage Transformation Techniques\nIn addition to lane detection, other image processing techniques like translation, rotation, and flipping are demonstrated.\n\nTranslation\nWe perform a translation on the image by shifting it in both the X and Y directions.\n\n```bash\ndeslocamento = np.float32([[1,0,100],[0,1,100]])\nimg_trans = cv.warpAffine(img, deslocamento, (largura, altura))\nplt.imshow(img_trans)\nRotation\nWe rotate the image around its center by a specified angle.\n```\n\n```bash\nrotacao = cv.getRotationMatrix2D(ponto, 30, 1.0)\nimg_rot = cv.warpAffine(img, rotacao, (largura, altura))\nplt.imshow(img_rot)\nFlipping\nWe flip the image along different axes (X, Y, or both).\n```\n\n```bash\nespelhar = cv.flip(img, -1)\nplt.imshow(espelhar)\n```\n\n## Conclusion\nThis project showcases basic image processing techniques using OpenCV, including edge detection, region of interest masking, and image transformations. These techniques are essential for many computer vision tasks such as lane detection in autonomous driving systems.\n\n## License\nThis project is open-source and available under the MIT License.\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsofiasawczenko%2Flane_detection_opencv","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsofiasawczenko%2Flane_detection_opencv","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsofiasawczenko%2Flane_detection_opencv/lists"}