基于图像的车道偏离预警,基于openCV
来源:互联网 发布:工业英语电子词典软件 编辑:程序博客网 时间:2024/05/09 23:35
前言:
算法自己写,只用到openCV的IO函数等。之前的毕业设计,现在很闲,拿出来改改,发出来。
目标:
检测出视频中的车道线
思路:
1.摄像机拍摄的视频有透视投影变换,所以先进行反透视变换。因为车道线是平行的,两条车道线之间的距离和平行信息是很重要的鲁棒性信息
2.道路是曲线的,要将图像分成多个片段,每个片段内近似认为是直线,最后将直线拟合成曲线
3.使用Hough变换进行直线检测,同时建立感兴趣区域(上帧图片中车道线附近的区域)以提高算法的性能。
4.使用kalman滤波进行车道线预测
5.由于没有硬件,全部使用电脑模拟,开了3个线程用来进行图像预处理,开了1个线程用来检测车道线,大约1s能处理16帧。
6.图像需要预处理,这部分不写了
效果:
原图:
反透视:
先腐蚀,后膨胀:
边缘检测:
感兴趣区域,hough变换,kalman滤波:
int lineHough(cv::Mat &I,HoughLine &lines,InterestPoint &int_point,double theta_min,double theta_max,double theta_step,double p_step){std::vector<double> rho,theta;//used to generate the gridsstd::vector<int> votes_of_chosen_line;//save the votes of each linecv::Mat vote;//used to save the votesunsigned int i=0,j=0;//used to index the hough lines int row=0,col=0;//used to index the interest areaint half_size_of_rho=0;//value of half size of rho arrayint rho_index=0;//used to index rho arrayint max_vote=0;//used to save the maximum value of votedouble rho_max=0,rho_min=0,rho_tmp=0,theta_tmp=0.0;//used to generate rho and theta griddouble cos_tmp=0.0,sin_tmp=0.0;//sin and cos valueVec2d point_tmp;// tmp linebool l_line_repeat=false;//if the line is repeat int thresh=0;//used to filter the hough peaks//check if the input image is valid, only 8 depth and 1 channels image are okassert(I.depth()==CV_8U);assert(I.channels()==1);//generate the grids of theta and rhotheta_tmp=theta_min;do{theta.push_back(theta_tmp);theta_tmp+=theta_step;}while(theta_tmp<theta_max);rho_max=(int)(1.0*sqrt(pow(I.rows,2.0)+pow(I.cols,2.0))+0.5);rho_min=-rho_max;rho_tmp=rho_min;do{rho.push_back(rho_tmp);rho_tmp+=p_step;} while (rho_tmp<rho_max);//cout<<"theta and rho grids are generated."<<endl;half_size_of_rho=(int)(rho.size()/2);//create the vote matrixvote=cv::Mat::zeros(rho.size(),theta.size(),CV_32SC1);//generate the hough peaksmax_vote=0;for (i=0;i<theta.size();++i){cos_tmp=cos(theta.at(i));sin_tmp=sin(theta.at(i));for (j=0;j<int_point.size();++j){rho_index=(int)((int_point.at(j)[1]*cos_tmp+int_point.at(j)[0]*sin_tmp)/p_step+half_size_of_rho);if((rho_index>=0)&&(rho_index<vote.rows)){vote.at<int>(rho_index,i)+=1;//get the maximum voteif(vote.at<int>(rho_index,i)>max_vote){max_vote=vote.at<int>(rho_index,i);}}}}//filter the peaks by threshthresh=(int)(VOTE_RATIO*max_vote);thresh=thresh>VOTE_MIN?thresh:VOTE_MIN;for (row=0;row<vote.rows;++row){for (col=0;col<vote.cols;++col){if(vote.at<int>(row,col)>thresh){//cout<<"votes at (rho="<<rho.at(row)<<",theta="<<theta.at(col)<<"):"<<vote.at<int>(row,col)<<"row="<<row<<",col="<<col<<"\n";point_tmp[0]=rho.at(row);point_tmp[1]=theta.at(col);lines.push_back(point_tmp);}}}//cout<<"hough lines detection done.\n";return 0;}
1 0
- 基于图像的车道偏离预警,基于openCV
- 基于单目视觉的车道偏离预警算法研究
- 基于OpenCV的图像检索系统
- 基于OpenCV的图像拼接
- 基于OpenCV的图像测量
- 基于OpenCV的图像旋转
- 基于matlab的车道和车道线检测样例
- 基于Gabor滤波器的车道线识别
- 基于霍夫变换条件筛选的车道线识别-Opencv实现
- 基于OpenCV 图像分割
- 基于OpenCV平滑图像
- 浅谈车道偏离预警系统
- 车道偏离预警系统
- 车道偏离报警系统
- OpenCV-基于特征点的图像匹配
- 基于OpenCV的图像去雾程序
- openCV基于图像处理的自动聚焦
- OpenCV基于直方图特征的图像搜索
- 一起看代码来玩玩QT之07 Painter
- Jquery JS 正确的比较两个数字大小的方法
- HDU 3127 WHUgirls(二维背包)
- ServiceLoader实现原理
- Dispatcher initialization failed
- 基于图像的车道偏离预警,基于openCV
- UVALive 4725 Airport 贪心 二分 模拟
- Solr基础教程之solrconfig.xml(三)
- 自定控件时 三个构造方法的调用
- 学习记录1
- Linux常用命令(一)
- iOS 设置APP模拟网络不佳情况
- 真要救经济,就应该放掉房地产,减税
- 传递参数给Sed