首页 > 解决方案 > 在 HoughLines 之前要采取什么预处理步骤

问题描述

我写了一个程序

  1. 结合边缘信息和颜色信息来形成我需要检测直线的图像
    边图 彩图 组合地图或框架
  2. 然后我使用 findContour 和 drawContour 重新绘制证据图 findcontour 的输出

  3. 之后我使用一些细化算法将线折叠成一条线 细线

  4. 使用 HoughLinesP 计算线段。只剩下线的痕迹。最重要的是错过了水平线

霍夫的输出

  1. 从这组线段中,计算交点(不包含在代码中)
  2. 从交点,从交点画一个四边形,水平/垂直线的顶点(称为v1和v2,离交点最远)和一个顶点基于交点在v1和之间的线上的反射计算v2

但是,它并没有像我认为的那样工作。我认为问题在于矩形的内部边框没有被填充。我应该使用形态,例如扩张然后侵蚀。在尝试检测与霍夫变换的交集之前,我已经没有办法预处理两个“提示”图像

需要大家帮忙!

提前致谢

下面是我生成以下代码的代码片段

int FindBoxes(cv::Mat& colorMap,cv::Mat& edgeMap)
{ 
    cv::Mat frame;
    // colorMap is a coloured filtered map while edgeMap is an edge  filter Map. frame will be the colour i want 
    cv::bitwise_and(colorMap, edgeMap, frame);

    // A trial method by using findContour to get the interior line filled up 
    std::vector<std::vector<cv::Point> > contours;
    std::vector<cv::Vec4i> hierarchy;
    cv::findContours(frame, contours, hierarchy, CV_RETR_EXTERNAL,
        cv::CHAIN_APPROX_SIMPLE);

    cv::Mat Map = cv::Mat::zeros(cueMap1.size(), CV_8U);
    cv::drawContours(Map, contours, -1, cv::Scalar(255, 255, 255), CV_FILLED);

   // thin the line to collapse it into one single line for Hough Detection
   cv::Mat thin;
   thinning(Map, Map);

   cv::GaussianBlur(Map, Map, cv::Size(5,5),1.0,1.0);

   std::vector<cv::Vec4i> lines;
   cv::HoughLinesP(Map, lines,1, CV_PI/90, 2, 30, 0);

   return 0;
}

标签: c++opencvimage-processinghoughlinesp

解决方案


推荐阅读