车道检测器分隔线 C ++ 与 OpenCV

2024-04-06

现在我一直在用OpenCV进行图像分析,我想做的是识别车道分割线,我所做的如下:

1.I receive a image,
2. Then transform it to grayscale
3.I apply the GaussianBlur
4.After I place me in the ROI
5.I apply the canny
6.then I look for lines with hough transform Lines 
7.Draw the lines obtained from hough

但我遇到了一个问题: 既不识别分界线,也不识别黄线。

我希望能帮我解决这个问题,你会非常感谢的。 然后我把代码

#include "opencv2/highgui/highgui.hpp"
#include <opencv2/objdetect/objdetect.hpp>
#include <opencv2/imgproc/imgproc.hpp>
#include <iostream>
#include <vector>
#include <stdio.h>
#include "linefinder.h"

using namespace cv;

int main(int argc, char* argv[]) {
int houghVote = 200;
string arg = argv[1];
Mat image;
image = imread(argv[1]);    
    Mat gray;
    cvtColor(image,gray,CV_RGB2GRAY);
   GaussianBlur( gray, gray, Size( 5, 5 ), 0, 0 );
    vector<string> codes;
    Mat corners;
    findDataMatrix(gray, codes, corners);
    drawDataMatrixCodes(image, codes, corners);
 //Mat image = imread("");
    //Rect region_of_interest = Rect(x, y, w, h);
    //Mat image_roi = image(region_of_interest);
 std::cout << image.cols << "\n";
 std::cout << image.rows << "\n";
 Rect roi(0,290,640,190);// set the ROI for the image
 Mat imgROI = image(roi);
 // Display the image
 imwrite("original.bmp", imgROI);
// Canny algorithm
Mat contours;
Canny(imgROI, contours, 120, 300, 3); 
imwrite("canny.bmp", contours);
Mat contoursInv;
threshold(contours,contoursInv,128,255,THRESH_BINARY_INV);
// Display Canny image
imwrite("contours.bmp", contoursInv);

/* 
Hough tranform for line detection with feedback
Increase by 25 for the next frame if we found some lines.  
This is so we don't miss other lines that may crop up in the next frame
but at the same time we don't want to start the feed back loop from scratch. 
*/
std::vector<Vec2f> lines;
if (houghVote < 1 or lines.size() > 2){ // we lost all lines. reset 
    houghVote = 200; 
}else{ 
    houghVote += 25;
} 
while(lines.size() < 5 && houghVote > 0){
    HoughLines(contours,lines,1,PI/180, houghVote);
    houghVote -= 5;
}
std::cout << houghVote << "\n";
Mat result(imgROI.size(),CV_8U,Scalar(255));
imgROI.copyTo(result);
// Draw the limes
std::vector<Vec2f>::const_iterator it= lines.begin();
Mat hough(imgROI.size(),CV_8U,Scalar(0));
while (it!=lines.end()) {
    float rho= (*it)[0];   // first element is distance rho
    float theta= (*it)[1]; // second element is angle theta
    if ( theta > 0.09 && theta < 1.48 || theta < 3.14 && theta > 1.66 ) { 
    // filter to remove    vertical and horizontal lines
        // point of intersection of the line with first row
        Point pt1(rho/cos(theta),0);        
        // point of intersection of the line with last row
        Point pt2((rho-result.rows*sin(theta))/cos(theta),result.rows);
        // draw a white line
        line( result, pt1, pt2, Scalar(255), 8); 
        line( hough, pt1, pt2, Scalar(255), 8);
    }
    ++it;
   }

   // Display the detected line image
   std::cout << "line image:"<< "\n";
   namedWindow("Detected Lines with Hough");
   imwrite("hough.bmp", result);

   // Create LineFinder instance
   LineFinder ld;

  // Set probabilistic Hough parameters
   ld.setLineLengthAndGap(60,10);
   ld.setMinVote(4);

  // Detect lines
  std::vector<Vec4i> li= ld.findLines(contours);
  Mat houghP(imgROI.size(),CV_8U,Scalar(0));
  ld.setShift(0);
  ld.drawDetectedLines(houghP);
  std::cout << "First Hough" << "\n";
  imwrite("houghP.bmp", houghP);

  // bitwise AND of the two hough images
  bitwise_and(houghP,hough,houghP);
  Mat houghPinv(imgROI.size(),CV_8U,Scalar(0));
  Mat dst(imgROI.size(),CV_8U,Scalar(0));
  threshold(houghP,houghPinv,150,255,THRESH_BINARY_INV); // threshold and invert to black lines
  namedWindow("Detected Lines with Bitwise");
  imshow("Detected Lines with Bitwise", houghPinv);

  Canny(houghPinv,contours,100,350);
  li= ld.findLines(contours);
 // Display Canny image
 imwrite("contours.bmp", contoursInv);

 // Set probabilistic Hough parameters
  ld.setLineLengthAndGap(5,2);
  ld.setMinVote(1);
  ld.setShift(image.cols/3);
  ld.drawDetectedLines(image);

  std::stringstream stream;
  stream << "Lines Segments: " << lines.size();

  putText(image, stream.str(), Point(10,image.rows-10), 2, 0.8, Scalar(0,0,255),0); 
  imwrite("processed.bmp", image);

  char key = (char) waitKey(10);
  lines.clear();
  }

The following are the input images respectively: input 1 input 2

这里我展示了两张照片,一张识别白线,另一张不识别黄线,我需要的是识别分界线,因为我监控车道,但对我来说很复杂,它不能识别所有的存在分界线,我希望能帮助我,因为我已经诚实地尝试了一切,但没有得到好的结果。


我认为这是因为您正在对概率霍夫变换和常规霍夫变换进行按位加法。这意味着输出的图像将仅包含在这两种变换中出现的线条。我很确定在常规变换中未检测到该线,但在概率霍夫输出中检测到该线。最好的办法是分别输出两个转换并进行调试。我正在做一个类似的项目,我想你可以包含一个单独的 ROI 以从按位加法中排除,并且该区域将沿着车道标记的中心。

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

车道检测器分隔线 C ++ 与 OpenCV 的相关文章

随机推荐

  • postgreSQL 使用时间戳排序

    我有以下 SQL 语句 SELECT FROM schema table WHERE TimeStamp timestamp gt 2016 03 09 03 00 05 ORDER BY TimeStamp date asc LIMIT
  • django-pipeline DEBUG=True,未找到压缩文件

    好的 我对 django pipeline 的使用简直要发疯了 离完全不使用它只有一步之遥了 我还没有投入生产 以下所有内容都在开发中发生 DEBUG True 模式 我的 css 静态文件位于名为 project static css 的
  • 如何找出当前焦点是哪个对象

    我有几个TextFields in my Frame 我想知道哪个TextField目前有重点 我怎样才能找到这些信息 KeyboardFocusManager getCurrentKeyboardFocusManager getFocus
  • Python导入MySQLdb,Apache内部服务器错误

    我遇到了与 中描述 的类似问题 Web 服务器的 cgi 问题 https stackoverflow com questions 621874 cgi problem with web server 尽管我审查并测试了之前建议的解决方案
  • 如何获取 HTML 完成的网络请求列表

    我如何使用 HTML 完成的 Javascript 获取网络请求列表 如 chrome devtools 中所示 For example 这是 google com 的开发工具 我想使用 javascript 将所有这些请求放在一个列表中
  • 复制普通可复制对象是否总是在 C++14 中定义?

    For a 可以简单地复制 http en cppreference com w cpp concept TriviallyCopyableT 型考虑 void f T z T a T b std memcpy b a sizeof T a
  • 在 ES6/ES2015 中是否有一种更简洁的方法将一个对象的属性映射到另一个对象?

    说我有一个对象foo有属性a and b但我想将这些属性的值传输到另一个对象bar有属性x and y where bar x得到的值foo a and bar y得到的值foo b 使用 ES5 实现此目的的第一个方法如下所示 var f
  • AlexNet 中的神经元数量

    In AlexNet http www cs toronto edu 7Efritz absps imagenet pdf 图像数据为3 224 224 第一个卷积层用96个大小的核对图像进行过滤11 11 3步幅为 4 像素 我对第一层的
  • React Native Android 位置请求超时

    在 IOS 中查找 GPS 坐标时没有问题 效果很好 Android 端不如 IOS 稳定 在真机和模拟器中都会出现这个问题 有时它可以找到位置 但有时却找不到 寻找了3天 但没有找到解决方案 当我的应用程序无法找到我的位置时 我尝试通过谷
  • 如何加快 Java / Android 中的解压时间?

    在 Android 上解压缩文件似乎非常慢 起初我以为这只是模拟器 但在手机上似乎是一样的 我尝试了不同的压缩级别 最终降到存储模式 但仍然需要很长时间 无论如何 总得有个理由吧 还有其他人有这个问题吗 我的解压方法如下所示 public
  • 如何在不引入竞争条件的情况下等待 RX 主体的响应?

    我有一项服务允许调用者异步发送命令和接收响应 在真实的应用程序中 这些操作是相当断开的 某些操作将发送命令 并且响应将被独立处理 但是 在我的测试中 我需要能够发送命令 然后等待 第一个 响应 然后再继续测试 响应是使用 RX 发布的 我对
  • Android 拖放问题不显示

    我正在开发一个拖放应用程序 一切正常 但我看到了一个问题 我有 3 个 ImageView 其中两个是可拖动对象 另一个是放置目标 每次我将物体扔到除放置目标之外的任何位置时 它都会完全消失 下面是我使用的代码 ImageView iv1
  • s3 临时签名 URL 中缺少对象的自定义 404 页面

    我正在为 Amazon S3 中的一些私人信息生成一些签名 URL 如果签名链接已过期或对象不存在 则会报告 XML 错误以及 404 错误 或 403 禁止 是否可以将签名链接 404 重定向到自定义错误页面 这似乎与 S3 静态网站设置
  • VS2010没有断点时调试器停止

    我最近更改了调试器中的一个选项 我认为这就是导致此问题的原因 但我似乎无法 撤消 它 我谷歌 所有命中都返回相反的 为什么调试器 not在断点处停止 无论如何 有人可以透露一些信息吗 编辑 当我在调试模式下按 f5 时 每次 它进入 Pro
  • Logstash创建管道但未创建索引

    我正在尝试使用 json 文件在 elasticsearch 云上创建索引 我已经创建了如下所示的配置 input file path gt root leads json start position gt beginning ignor
  • 在WPF中画一个十字

    我有一个 WPF 控件 I need to have in background a cross like this After that I d be able to add other controls over my crossed
  • 对数组元素(带有数字的字符串)进行排序,自然排序

    我有一个像这样的数组 IL0 Foo PI0 Bar IL10 Baz IL3 Bob says hello 并且需要对其进行排序 使其看起来像 IL0 Foo IL3 Bob says hello IL10 Baz PI0 Bar 我尝试
  • PHP 循环动态变量

    我正在尝试创建一个动态变量 我有一个循环 我希望它循环记录并为每个记录创建一个变量 我的代码 ct 1 foreach record as rec var ct rec Name ct ct 1 echo var1 当我尝试使用上面的代码时
  • 将 ToolBar 添加到 UITableView 的正确方法是什么?

    我正在编写一个基于导航的 iPhone 应用程序 我希望将 UIToolBar 停靠在屏幕底部 并在工具栏和导航栏之间滚动 UITableView 我见过几个论坛 其中有人建议处理此视图的视图控制器应该是标准 UIViewControlle
  • 车道检测器分隔线 C ++ 与 OpenCV

    现在我一直在用OpenCV进行图像分析 我想做的是识别车道分割线 我所做的如下 1 I receive a image 2 Then transform it to grayscale 3 I apply the GaussianBlur