资源简介
本程序基于OpenCv给出了一种车道线检测的算法,首先通过OSTU进行二值化处理,随后通过改进的霍夫变化进行车道线检测,具有比较好的效果。
代码片段和文件信息
//---------------------车道线检测-------------------------//
/*可以处理摄像头,也可以处理视频文件*/
#include
#include
#include
#include
#include
#include
using namespace cv;
using namespace std;
CvCapture* g_capture = NULL;
IplImage* PreProcessImg = NULL;
CvPoint point1 point2 point3 pointend pointtemp;
CvPoint pointmeet;//相交点
vector points;
vector pointsleft;
vector pointsright;
//结构体1,左侧的线,右侧的线
struct line
{
CvPoint pointbottom;
CvPoint pointtop;
}lineleft lineright;
//结构体2
struct greycount
{
uchar grey;
int count;
};
//大津阈值车道从背景中分离出来
void ImproveOTSU(IplImage* image IplImage* image2)
{
//int lc = cvRound((image->height / 2) + 1);
//cvSetImageROI(image cvRect(0 lc image->width image->height));
//如果只对下半幅图像做大津阈值,效果不好
//cvThreshold(image image 80 255 CV_THRESH_BINARY);//速度慢,与OSTU差100ms
//cvThreshold(image image2 180 235 CV_THRESH_BINARY_INV | CV_THRESH_OTSU);//BINARY能检测出视频3-2
cvThreshold(image image2 0 255 CV_THRESH_OTSU);//改变阈值没效果
//cvResetImageROI(image);
//cvCopy(image image2);
}
//改进的hough变换检测车道
int Hough(IplImage* image float* tabSin float *tabCos int *accum int numrho int &predistance1 int &preangle1 int &predistance2 int &preangle2)
{
int r angle1 = 1 angle2 = 1 distance1 = 0 distance2 = 0 n = 0;
long j;
int angelstart1 = 40;
int angleend1 = 70;
int anglestart2 = 110;
int angleend2 = 160;
if (preangle1 != 0)
{
angelstart1 = preangle1 - 5;
angleend1 = preangle1 + 5;
}
if (preangle2 != 0)
{
anglestart2 = preangle2 - 5;
angleend2 = preangle2 + 5;
}
int step = image->widthStep / sizeof(uchar);
uchar *data0 = (uchar *)image->imageData;
for (int i = image->height / 2; i < image->height; i++)
{
for (j = 0; j < image->width; j++)
{
if (data0[i*step + j] == 255)//??
{
for (n = angelstart1; n < angleend1; n++)//40--70
{
r = cvRound(j * tabCos[n] + i * tabSin[n]);
r += (numrho - 1) / 2;
accum[(n + 1) * (numrho + 2) + r + 1]++;
}
for (n = anglestart2; n < angleend2; n++)//110--160
{
r = cvRound(j * tabCos[n] + i * tabSin[n]);
r += (numrho - 1) / 2;
accum[(n + 1) * (numrho + 2) + r + 1]++;
}
}
}
}
//printf(“preangle1preangle2:%d %d\n “preangle1preangle2);
//找出数值最大的小格
int numbermax1 = 30 numbermax2 = 30;
for (r = 0; r < numrho; r++)//angle1\angle2 ????
{
for (n = 40; n < 70; n++)
{
int base = (n + 1) * (numrho + 2) + r + 1;
if (accum[base] > numbermax1)
{
numbermax1 = accum[base];
angle1 = n;
distance1 = cvRound(r - (numrho - 1)*0.5f);
}
}
for (n = 110; n<160; n++)
{
int base = (n + 1) * (numrho + 2) + r + 1;
if (accum[base] > numbermax2)
{
numbermax2 = accum[base];
angle2 = n;
distance2 = cvRound(r - (numrho - 1)*0.5f);
}
}
}
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
文件 18490 2017-11-20 18:23 车道线.cpp
文件 6457025 2017-11-21 08:59 1.mp4
----------- --------- ---------- ----- ----
6475515 2
相关资源
- 行人跟踪OPENCV代码
- 基于opencv的人脸检测
- 多目标跟踪
- opencv 求二值化图像的形心
- opencv 学习笔记,个人整理的
- 车牌识别代码arm-Linux,opencv
- OPENCV函数手册(带目录)+OpenCV中文参
- opencv实现行人检测
- VC +opencv识别图像中图形显示于界面
- opencv运动物体检测
- 基于opencv 的图像局部放大
- Opencv静态手势识别
- 双边滤波opencv实现
- 图像的平均亮度
- Opencv绘制物体轮廓,定位主要物件坐
-
OpenCV生成xm
l分类器文件 - Linux下QT及OpenCV搭建
- 张正友相机标定(OpenCV实现)223402
- Adaboost人头部检测 opencv vc
- OpenCv+Ocr 图片文字识别源码
- 于老师的人脸识别VS2015工程
- opencv相机检校
- 车型识别系统vc源码opencv
- opencv依靠颜色识别和跟踪物体
- OpenCV的PCA人脸识别
- openCV+qt视频传输
- OpenCV 现实高斯金字塔的源码,非常经
- opencv运动目标检测与跟踪源代码
- labview与Opencv 人眼识别
- opencv 将两幅等宽图像拼接在一起
评论
共有 条评论