使用opencv实现车道线检测实战代码

这篇文章主要介绍了opencv车道线检测实战,效果非常逼真,代码简单易懂,对opencv车道线检测实战代码感兴趣的朋友一起看看吧

效果

 void lane_detection(cv::Mat &src, cv::Mat &dst) { dst = cv::Mat::zeros(src.size(),src.type()); cv::Mat grid =cv::Mat::zeros(src.size(),src.type()); int iStep = 25; int iNUmsX = src.cols / iStep; int inUmsY = src.rows / iStep; for(int i = 1; i <= inUmsY; i++) { int yPos = i * iStep + src.cols / 5; cv::Point2d pt1,pt2; int iOffset = 10; pt1.x = 0 + iOffset; pt1.y = yPos; pt2.x = src.cols - iOffset; pt2.y = yPos; cv::line(grid,pt1,pt2,cv::Scalar(255), 1, cv::LINE_4); } for(int i = 1; i <= iNUmsX; i++) int xPos = i * iStep; pt1.x = xPos; pt1.y = 0 + iOffset + src.rows / 5; pt2.x = xPos; pt2.y = src.rows - iOffset; cv::imshow("grid", grid); cv::Mat bitNot; cv::bitwise_and(src, grid, bitNot); cv::Mat add = cv::Mat::zeros(bitNot.rows, bitNot.cols,bitNot.type()); int iDiffTh = 200; QTime timer; timer.start(); //#pragma omp parallel for num_threads(10) for (int i = 1; i (i, j); int iValueXPre = (int)bitNot.at(i-1, j); int iValueXNext = (int)bitNot.at(i+1, j); int iValueY = (int)bitNot.at(i, j); int iValueYPre = (int)bitNot.at(i, j-1); int iValueYNext = (int)bitNot.at(i, j+1); if((iValueX - iValueXPre > iDiffTh && iValueX - iValueXNext > iDiffTh) || (iValueY - iValueYPre > iDiffTh && iValueY - iValueYNext > iDiffTh)) { add.at(i, j) = 255; } } } qDebug()<<"process time: "<> contours; //cv::findContours(matThresh,contours,) std::vector > contoursDefect; std::vector hierarchyDefect; cv::Mat canves; cv::cvtColor(src, canves,cv::COLOR_RGBA2RGB); cv::findContours(matThresh, contoursDefect, hierarchyDefect, cv::RETR_EXTERNAL, cv::CHAIN_APPROX_NONE); for (size_t i = 0; i =  50) cv::Moments moment;//矩 moment = moments(contour, false); cv::Point2d pt1; double m00 = moment.m00 + 0.01; pt1.x = moment.m10 / m00;//计算重心横坐标 pt1.y = moment.m01 / m00;//计算重心纵坐标 cv::drawContours(canves, contoursDefect, i, cv::Scalar(255, 255, 0), -1); } cv::imshow("canves", canves); cv::waitKey(0); } void test_lane_detection() int i = 0; while(1) cv::Mat src; QString  dir("D:\\QtProject\\Opencv_Example\\gen_grid_region\\scene_"); QString path; if(i>9)  path =  QString("%1%2%3").arg(dir).arg(i++).arg(".png-600"); else path = QString("%1%2%3%4").arg(dir).arg("0").arg(i++).arg(".png-600"); cout<

到此这篇关于opencv车道线检测实战的文章就介绍到这了,更多相关opencv车道线检测内容请搜索0133技术站以前的文章或继续浏览下面的相关文章希望大家以后多多支持0133技术站!

以上就是使用opencv实现车道线检测实战代码的详细内容,更多请关注0133技术站其它相关文章!

赞(0) 打赏
未经允许不得转载:0133技术站首页 » C语言