2

I have written a program to

  1. Combined Edge information and colour information to form the image I would need to detect straight line from
    EdgeMap ColourMap Combined Map or Frame
  2. Then I use findContour and drawContour to redraw the evidence map Output from findcontour

  3. after which I use some thinning algorithm to collapse the line into one single line thin line

  4. Use HoughLinesP to calculate for line Segment. Only have traces of the line. And most importantly have missed out the horizontal line

Output from Hough

  1. From these set of line Segment, calculate the intersection point (not included in code)
  2. From the intersection, draw a quadrilateral from the intersection point, vertices(called it v1 and v2, furthest from the intersection point) of the horizontal/vertical line and a vertex calculate based on the reflection of the intersection point on the line between v1 and v2

However, it is not working as i think it should. I think the problem lies with that the interior border of the rectangle is not filled. Should I use morphology eg dilation then erode. I have run out of ideas to preprocess the two "cues" image before trying to detect for intersection with Hough Transform

Need everyone help!

THanks in advance

Below is my code snippet to generate the following

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;
}
user1538798
  • 1,075
  • 3
  • 17
  • 42
  • 1
    Could you please provide the original input image, so that one can get an impression, what the context is? Nevertheless, I would suggest NOT to thin your binary image before using `HoughLinesP`, better do this afterwards. Also, increase the angle resolution in `HoughLinesP`. I'd assume, that `CV_PI/90` (i.e. 2 degree steps) might be too coarse. – HansHirse Mar 28 '19 at 09:26
  • @HansHirse Sorry, not sure I could post the original image. is there ways to pm u? We are trying to detect the rectangle or quadrilateral (partial or full) in the image down here. But I took your suggestion of increasing the coarse step and to not use the thin algorithm before houghs transform. Also i have increased the minlineGap – user1538798 Mar 28 '19 at 09:44

0 Answers0