Lines and edges detector, opencv

Refresh

April 2019

Views

974 time

1

I'm trying to process the following images from a maze. My Question is about how to process the edges. I'm using OpenCV 2.4 with c++. I'd like to know if there is any way to discriminate the edges between the floor and the wall from the lines painted in the floor?

The floor is black, the walls are white and the lines painted in the floor are white too.

What I am trying to do is distinguish between wall and marks in floor. The lines on the floor will give me a distance reference and if I can turn in the maze. While the walls just tell the limit of the halls of the maze.

here you'll find the process images I've done.

http://oi61.tinypic.com/34hx7a0.jpg

http://oi60.tinypic.com/2zpqfq0.jpg

I'm using Canny and HoughLinesP functions to detect and save the lines. But as you can see in the images the program doesn't separate the lines from the edges.

The code:

vector<Vec4i> get_lines(Mat dst, Mat cdst)
{
    vector<Vec4i> lines;
    HoughLinesP(dst, lines, 1, CV_PI/180, 100, 50, 10 );
    for( size_t i = 0; i < lines.size(); i++ )
    {
        Vec4i l = lines[i];
        double size = norm(Mat(Point(l[0], l[1])), Mat(Point(l[2], l[3])) );
        if(size > 100)
            line( cdst, Point(l[0], l[1]), Point(l[2], l[3]), Scalar(0,0,255), 3, CV_AA);
    }

    return lines;
}

And main function is:

int main(int argc, char** argv)
{
    const char* filename = argc >= 2 ? argv[1] : "pic1.jpg";

    Mat src = imread(filename, 0);

    if(src.empty())
    {
        help();
        cout << "can not open " << filename << endl;
        return -1;
    }

    Mat dst, cdst;

    Canny(src, dst, 50, 200, 3);

    cvtColor(dst, cdst, CV_GRAY2BGR);
    vector<Vec4i> lines = get_lines(dst, cdst);

    imshow("source W&B", src);
    imshow("edges", dst);
    imshow("detected lines", cdst);

    imwrite("lines.jpg",cdst);
    imwrite("src.jpg",src);
    imwrite("canny.jpg",dst);

    waitKey();

    return 0;
}

1 answers

1

The obvious thing to try would be to compare the brightness of pixels on either side of the line.

make three regions: pixels a little distance to one side of the line, pixels a little distance to the other side of the line, and pixels close to the line. Calculate the average brightness in either region.

The walls are light grey, the floor is black and the lines are white, so

  • if one side is significantly brighter than the other side, it is probably an edge (and you can even tell which side is the floor),
  • if both sides are significantly darker than the middle it is probably a marking on the floor.
  • (and if the line is vertical, it is a wall-wall edge)