资源简介
基于OpenCV3( Python / C++ ) 的车道检测代码和测试视频
代码片段和文件信息
// Author: Francis Liu
// Email: francislucien2017@126.com
// This code is about lane detection by using OpenCV3.
#include
#include
#include
#include
#include
#include
#include
#include
using std::cout;
typedef std::vector linesType;
const double PI = 3.1415926535;
bool show_steps = false;
// m: 斜率 b: 截距 norm: 线长
struct hough_pts {
double m b norm;
hough_pts(double m double b double norm) :
m(m) b(b) norm(norm) {};
};
void getROI(cv::Mat img std::vector vertices cv::Mat& masked) {
cv::Mat mask = cv::Mat::zeros(img.size() img.type());
if (img.channels() == 1) {
cv::fillConvexPoly(mask vertices cv::Scalar(255));
}
else if(img.channels() == 3){
cv::fillConvexPoly(mask vertices cv::Scalar(255255255));
}
int a = 10;
cv::bitwise_and(img img masked mask);
}
void drawLines(cv::Mat& img linesType lines cv::Scalar color) {
for (int i = 0; i < lines.size(); ++i) {
cv::Point pt1 = cv::Point(lines[i][0] lines[i][1]);
cv::Point pt2 = cv::Point(lines[i][2] lines[i][3]);
cv::line(img pt1 pt2 color 4 8);
}
}
void averageLines(cv::Mat linesType lines double y_min double y_max linesType& output) {
std::vector left_lane right_lane;
for (int i = 0; i < lines.size(); ++i) {
cv::Point2f pt1 = cv::Point2f(lines[i][0] lines[i][1]);
cv::Point2f pt2 = cv::Point2f(lines[i][2] lines[i][3]);
double m = (pt2.y - pt1.y) / (pt2.x - pt1.x);
double b = -m * pt1.x + pt1.y;
double norm = sqrt((pt2.x - pt1.x)*(pt2.x - pt1.x) + (pt2.y - pt1.y)*(pt2.y - pt1.y));
if (m < 0) { // left lane
left_lane.push_back(hough_pts(m b norm));
}
if (m > 0) { // right lane
right_lane.push_back(hough_pts(m b norm));
}
}
double b_avg_left = 0.0 m_avg_left = 0.0 xmin_left xmax_left;
for (int i = 0; i < left_lane.size(); ++i) {
b_avg_left += left_lane[i].b;
m_avg_left += left_lane[i].m;
}
b_avg_left /= left_lane.size();
m_avg_left /= left_lane.size();
xmin_left = int((y_min - b_avg_left) / m_avg_left);
xmax_left = int((y_max - b_avg_left) / m_avg_left);
// left lane
output.push_back(cv::Vec4i(xmin_left y_min xmax_left y_max));
double b_avg_right = 0.0 m_avg_right = 0.0 xmin_right xmax_right;
for (int i = 0; i < right_lane.size(); ++i) {
b_avg_right += right_lane[i].b;
m_avg_right += right_lane[i].m;
}
b_avg_right /= right_lane.size();
m_avg_right /= right_lane.size();
xmin_right = int((y_min - b_avg_right) / m_avg_right);
xmax_right = int((y_max - b_avg_right) / m_avg_right);
// right lane
output.push_back(cv::Vec4i(xmin_right y_min xmax_right y_max));
// left lane: output[0]
// right lane: output[1]
}
void bypassAngleFilter(linesType lines double low_thres double high_thres linesType& output) {
for (int
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
文件 6980 2018-10-27 09:52 lane detection.cpp
文件 6720 2018-10-26 22:26 lane detection.py
目录 0 2018-10-27 10:18 test_videos\
文件 15093678 2018-04-23 23:06 test_videos\test.mp4
- 上一篇:17个VC++与OPENGL写的游戏程序代码
- 下一篇:C/C++编译仿真器
相关资源
- MFC+VS2013+OPENCV3.0打开摄像头,拍照并处
- 基于MFC的OpenCV视频图像显示小工具
- 学习OpenCV(中文版)252853
- VS2017C++windows桌面应用程序项目OpenCV及
- 车流量统计
- 基于C++的基础车牌识别
- 基于opencv的C++车牌识别
- MFCVC++读写DXF文件
- 基于OpenCV的运动目标检测与跟踪
- MFC下利用OPENCV添加显示图片
- C#+opencv拍照和图片对比
- 基于OpenCV和MFC实现布匹瑕疵检测.rar
- opencv SVM图像分类工程文件
- C++运用opencv进行二维多张全景图拼接
- 基于opencv和MFC的多功能视频、图像处
- opencv-3.4.6.zip
- opencv+MFC实现图像拼接
- 车牌识别的mfc加opencv
- VS2015MFC+Opencv2 打开图片及简单的图像
- 车牌识别系统源代码
- Learning OpenCV 3 Computer vision in C++ 无水印
- C++车道线检测例程,环境为VS2015以上
- LSD线特征提取方法+Opencv实现C++
- mfc+opencv读取摄像头视频并实现抓图
- 基于SVM与人工神经网络的车牌识别O
- c++ 用opencv比较两张人脸照片是否相似
- MATLAB单双目标定程序(Opencv C++)
- 基于OpenCV的人脸验证和人脸识别MFC程
- C++ 解析rtsp流后返回Iplimage,用Opengl显
- MFC通过OpenCV 显示到Picture control
评论
共有 条评论