opencv 画延长线
2016-04-10 13:53 GarfieldEr007 阅读(1504) 评论(0) 编辑 收藏 举报hough变换可以让我们检测到直线,这在前面已有详解,对于车道检测,我们需要其到图像边界的延长线一遍之后数据帧分析。
以下代码帮助我们在opencv中画延长线,本来想用虚线表示延长线的,无奈参数调不好了……只好把bug的虚线贴上去注释掉了,希望牛人能给点帮助帮我调下吧
其他的代码部分可供参考
- void CCVMFCView::OnDottedLine(CvPoint p1,CvPoint p2,IplImage *workimg)
- {
- double k=(p2.y-p1.y)/(p2.x-p1.x+0.000001);
- double DOT_STEP;
- CvPoint pa=p1,pb=p1;
- cvLine(workimg,p1,p2,CV_RGB(255,255,0),3, CV_AA, 0 );
- //dotted line , has bug ╮(╯_╰)╭
- //while(pb.x>0&&pb.x<workimg->width&&pb.y<p2.y)
- //{
- // pb.x+=DOT_STEP;
- // pb.y+=DOT_STEP*k;
- // cvLine(workimg,pa,pb,CV_RGB(255,255,0),3, CV_AA, 0 );
- // pb.x+=DOT_STEP;
- // pb.y+=DOT_STEP*k;
- // pa=pb;
- // pb.x+=DOT_STEP;
- // pb.y+=DOT_STEP*k;
- //}
- }
- // find two endpoint of the faint line
- void CCVMFCView::OnDrawDotline(CvPoint s, CvPoint e,IplImage *workimg)
- {
- CvPoint pa,pb;
- if(s.y>e.y)//swap
- {
- pa=s;
- s=e;
- e=pa;
- }
- double k=(e.y-s.y)/(e.x-s.x+0.000001);
- double h=workimg->height,w=workimg->width;
- pb=s;
- pa.y=0,pa.x=s.x-s.y/k; //start point on the low line
- if(pa.x<0) //start point on the left line
- pa.x=0, pa.y=k*s.x;
- else if(pa.x>=w)
- pa.x=w, pa.y=s.y+k*(w-s.x);
- OnDottedLine(pb,pa,workimg);
- pa=pb=e;
- pb.y=h; pb.x+=(h-e.y)/k;
- if(pb.x>w)
- pb.y=e.y+k*(w-e.x), pb.x=w;
- else if(pb.x<0)
- pb.y=e.y-k*e.x, pb.x=0;
- OnDottedLine(pa,pb,workimg);
- }
实验结果:
原图:
车道检测结果:
hough变换检测+延长线(绿:检测结果。黄:延长线)
from: http://blog.csdn.net/abcjennifer/article/details/7440887