{"id":22884601,"url":"https://github.com/w2874382167/lane-detection","last_synced_at":"2026-01-27T06:32:44.603Z","repository":{"id":262661724,"uuid":"830599909","full_name":"w2874382167/lane-detection","owner":"w2874382167","description":"在大一上学期时，完成编程作业，选题为利用OpenCV进行车道线的检测","archived":false,"fork":false,"pushed_at":"2024-11-14T02:39:22.000Z","size":29118,"stargazers_count":2,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-05-07T07:42:55.794Z","etag":null,"topics":["cpp","detection","opencv"],"latest_commit_sha":null,"homepage":"","language":"C++","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/w2874382167.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,"zenodo":null}},"created_at":"2024-07-18T15:25:46.000Z","updated_at":"2024-11-13T16:29:39.000Z","dependencies_parsed_at":"2025-05-07T07:48:38.041Z","dependency_job_id":null,"html_url":"https://github.com/w2874382167/lane-detection","commit_stats":null,"previous_names":["siesta-jiong/lane-detection","w2874382167/lane-detection"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/w2874382167/lane-detection","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/w2874382167%2Flane-detection","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/w2874382167%2Flane-detection/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/w2874382167%2Flane-detection/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/w2874382167%2Flane-detection/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/w2874382167","download_url":"https://codeload.github.com/w2874382167/lane-detection/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/w2874382167%2Flane-detection/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28806353,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-27T06:25:51.065Z","status":"ssl_error","status_checked_at":"2026-01-27T06:25:50.640Z","response_time":168,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"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":["cpp","detection","opencv"],"created_at":"2024-12-13T19:18:34.944Z","updated_at":"2026-01-27T06:32:44.569Z","avatar_url":"https://github.com/w2874382167.png","language":"C++","funding_links":[],"categories":[],"sub_categories":[],"readme":"# 车道线检测\n\n\u003e 引入：针对路面标线检测是实现车道偏离预警的关键技术，对于实现车辆的完全自主驾驶具有重要的意义。\n\n## 一、选题分析与理解：\n\n1. 车道线检测是自动驾驶和驾驶辅助系统中的关键任务之一，针对路面标线检测是实现车道偏离预警的关键技术，对于实现车辆的完全自主驾驶具有重要的意义。OpenCV是一个广泛使用的计算机视觉库，可以用来进行车道线检测。\n2. 车道线检测的基本原理是通过图像处理和计算机视觉技术在***\\*图像或视频帧中提取出车道线的位置信息\\****。具体如下几个模块处理：\n\n 图像预处理：将彩色图像转换为灰度图像，使用cvtColor函数来实现。\n\n 边缘检测：利用Canny边缘检测算法，使用Canny函数来实现。Canny算法能够检测图像中的边缘，并输出一个二值图像，其中只包含边缘点。\n\n 区域兴趣提取（ROI区域提取）：车道线通常在图像的下半部分出现，因此需要定义一个感兴趣的区域来提取车道线。fillPoly函数创建一个多边形mask，将非感兴趣区域的像素设为0。之后在使用bitwise_and函数将兴趣区域图像导入（简单来说就是将车道线的位置通过计算后抠出）\n\n 轮廓提取：提取轮廓，对轮廓的边框进行分析除去一些不符合的，在用借助椭圆进行拟合出轮廓。轮廓提取可以使用findContours函数，之后遍历所有的轮廓分析，除去角度、面积都过于不符合的，之后用drawContours函数将轮廓描出。\n\n 直线拟合：对轮廓分为左下部分（左车道）和右下部分（右车道）进行向量取点之后将点拟合得到目标线。这里向量取点使用push_pack填入找到的点，拟合时借助line函数得到。\n\n流程如下：\n\n![流程图](./img/wps7.jpg) \n\n## 二、自定义函数原型以及核心代码片段如下：\n\n```c++\nvoid process(Mat\u0026 frame,Point* left,Point* right_line);\nMat fitLines(Mat\u0026 image, Point* lift_line, Point* right_line);\n```\n\nprocess函数用于用于对图片进行操作得到目标线段（包括图片灰度化，边缘检测，区域提取.....）\n\n```c++\ncvtColor(frame, gray, COLOR_BGR2GRAY);//灰度化\nCanny(gray, binary, 100,150);//canny算子边缘检测\nbitwise_and(binary, mask, roi_binary);//对二值化（边缘）填入掩码\n//寻找轮廓findContours\n//二值化图像中查找对象的轮廓，并将找到的轮廓保存在contours这个容器中\n//二值化图片\t保存容器\t检测外侧\t压缩\nfindContours(roi_binary, contours, RETR_EXTERNAL,CHAIN_APPROX_SIMPLE);\n```\n\nfitLines函数主要是轮廓进一步的提取分析之后绘制出车道线（通过斜率的计算过滤一部分线段，）\n\n```c++\n//遍历左下部分，找到左车道线\nfor (int i = 100; i \u003c (cx - 10); i++)\n{\n\tfor (int j = cy; j \u003c height; j++)\n\t{\n\t\tint pv = image.at\u003cuchar\u003e(j, i);\n\t\tif (pv == 255)\n\t\t{\t//提取左车道线的点集\n\t\t\tleft_pts.push_back(Point(i, j));\n\t\t}\n\t}\n}\n\t//拟合左车道\n\tif (left_pts.size() \u003e 2)\t\t//点数大于2\n\t{\n\t\t//拟合一条直接到左车道点集上\n\t\tfitLine(left_pts, left, DIST_L1, 0, 0.01, 0.01);\n\t\tdouble k1 = left[1] / left[0];\n\t\tdouble step = left[3] - k1 * left[2];\n\t\tint x1 = int((height - step) / k1);\n\t\tint y2 = int((cx - 25) * k1 + step);\n\t\tPoint left_spot_1 = Point(x1, height);\n\t\tPoint left_spot_end = Point((cx - 25), y2);\n\t\tline(out, left_spot_1, left_spot_end, Scalar(128, 0, 128), 8, 8, 0);\n\t\t//承接上一张的点\n\t\tleft_line[0] = left_spot_1;\n\t\tleft_line[1] = left_spot_end;\n\t}\n\telse\n\t{\n\t\tline(out, left_line[0], left_line[1], Scalar(128, 0, 128), 8, 8, 0);\n\t}\n```\n\n## 三、运行界面截图：\n\n\u003cimg src=\"./img\\wps11.jpg\" alt=\"img\" style=\"width:350px;\" /\u003e\t \u003cimg src=\"./img/wps12.jpg\" alt=\"img\" style=\"width:350px;\" /\u003e\n\n​\t\t\t\t\t\t\t\t灰度化处理\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t边缘检测\n\n \n\n\u003cimg src=\"./img/wps13.jpg\" alt=\"img\" style=\"width:350px;\" /\u003e\t \u003cimg src=\"./img\\wps14.jpg\" alt=\"img\" style=\"width:350px;\" /\u003e\n\n​\t\t\t\t\t\t\t\t特定区域提取\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t绘制车道线\n\n \n\n## 四、总结\n\n车道线检测是自动驾驶和驾驶辅助系统中的关键任务之一，针对路面标线检测是实现车道偏离预警的关键技术，对于实现车辆的完全自主驾驶具有重要的意义。在我的算法中，运用边缘检测，POI区域获取，轮廓提取，点数拟合成线基本可以实现车道线的检测。除此以外，我还利用了椭圆拟合的算法，将轮廓的边缘进行修正和进行一步的加工，使后面更容易提取到所需的点集；在点集处理处，也通过遍历寻找车道线的点集，斜率评估和筛选，让符合要求的点集留下，不符合的进行微调或者移除，保证了绘制出的车道线可以更好的贴近实际车道线，更加符合实际的需求。\n\n算法也需要很多需要调整的地方，比如：ROI区域获取时如何能够将不同场景，不同尺寸的图像处理，在保证减少噪声的情况下，还能够得到需要检测的区域.....\n\n有一句这样说：“数学决定你学计算机的深度，英语决定你学计算机的广度。”在这个项目里我深有体会，需要不断的去测量坐标、计算坐标、计算斜率估计值...建立数学模型，将数学思维始终贯彻整个算法！\n\n具体可以联系邮箱：libai9123@outlook.com\n\n\u003c!--2024.1.11--\u003e **大一上学期期末作业：优秀**","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fw2874382167%2Flane-detection","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fw2874382167%2Flane-detection","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fw2874382167%2Flane-detection/lists"}