怎么使用opencv实现车道线检测

怎么使用opencv实现车道线检测

这篇“怎么使用opencv实现车道线检测”文章的知识点大部分人都不太理解,所以小编给大家总结了以下内容,内容详细,步骤清晰,具有一定的借鉴价值,希望大家阅读完这篇文章能有所收获,下面我们一起来看看这篇“怎么使用opencv实现车道线检测”文章吧。

效果

voidlane_detection(cv::Mat&src,cv::Mat&dst){dst=cv::Mat::zeros(src.size(),src.type());cv::Matgrid=cv::Mat::zeros(src.size(),src.type());intiStep=25;intiNUmsX=src.cols/iStep;intinUmsY=src.rows/iStep;for(inti=1;i<=inUmsY;i++){intyPos=i*iStep+src.cols/5;cv::Point2dpt1,pt2;intiOffset=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(inti=1;i<=iNUmsX;i++)intxPos=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::MatbitNot;cv::bitwise_and(src,grid,bitNot);cv::Matadd=cv::Mat::zeros(bitNot.rows,bitNot.cols,bitNot.type());intiDiffTh=200;QTimetimer;timer.start();//#pragmaompparallelfornum_threads(10)for(inti=1;i(i,j);intiValueXPre=(int)bitNot.at(i-1,j);intiValueXNext=(int)bitNot.at(i+1,j);intiValueY=(int)bitNot.at(i,j);intiValueYPre=(int)bitNot.at(i,j-1);intiValueYNext=(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()<<"processtime:"<>contours;//cv::findContours(matThresh,contours,)std::vector>contoursDefect;std::vectorhierarchyDefect;cv::Matcanves;cv::cvtColor(src,canves,cv::COLOR_RGBA2RGB);cv::findContours(matThresh,contoursDefect,hierarchyDefect,cv::RETR_EXTERNAL,cv::CHAIN_APPROX_NONE);for(size_ti=0;i=50)cv::Momentsmoment;//矩moment=moments(contour,false);cv::Point2dpt1;doublem00=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);}voidtest_lane_detection()inti=0;while(1)cv::Matsrc;QStringdir("D:\\QtProject\\Opencv_Example\\gen_grid_region\\scene_");QStringpath;if(i>9)path=QString("%1%2%3").arg(dir).arg(i++).arg(".png");elsepath=QString("%1%2%3%4").arg(dir).arg("0").arg(i++).arg(".png");cout<

以上就是关于“怎么使用opencv实现车道线检测”这篇文章的内容,相信大家都有了一定的了解,希望小编分享的内容对大家有帮助,若想了解更多相关的知识内容,请关注恰卡编程网行业资讯频道。

发布于 2022-03-18 22:47:30
分享
海报
20
上一篇:Springboot @Value注入boolean如何设置默认值 下一篇:如何使用controller传boolean形式值
目录

    忘记密码?

    图形验证码