Lane Detection: Step 1: Inverse/Wrap perspective mapping

To detect lane we first do some image transformation. First lets consider the following image. It has lane marking (green). The lanes are almost parallel in real world, but as we see in the image the lanes seem wider at the bottom and narrower at the top.

To make it easier we want to have a bird eye view so that the lane lines become parallel to each other. OpenCV has built-in function to do the transformation. So we just use that. The process is called wrap perspective mapping (WPM) and we need to provide 4 points on the original image (I have marked them red in the image above) and a corresponding real world co-ordinate. I have just made up the numbers to make them parallel.
Here is the result:
And here is the code (just a demo- without error handling):
#include "iostream"

#include "cv.h"
#include "highgui.h"

using namespace std;
using namespace cv;

void ipm(const char *input_path, const char *output_path)
    Mat src, dst;
    src=imread(input_path, 1);

    Point2f img_vertices[4];
    img_vertices[0] = Point(213, 104);
    img_vertices[1] = Point(410, 106);
    img_vertices[2] = Point(6, 372);
    img_vertices[3] = Point(540, 400);

    Point2f world_vertices[4];
    world_vertices[0] = Point(26, 104);
    world_vertices[1] = Point(540, 106);
    world_vertices[2] = Point(26, 400);
    world_vertices[3] = Point(540, 400);

    Mat warpMatrix = getPerspectiveTransform(img_vertices, world_vertices);
    warpPerspective(src, dst, warpMatrix, dst.size(), INTER_LINEAR);

    imwrite(output_path, dst);    

int main(int argc, char** argv)
    ipm(argv[1], "ipm.jpg");
    return 0;

At the end of all steps the goal is to detect all paths and objects 
in the dataset.

No comments:

Post a Comment

Student registration reached 365 in less than a week

As I have posted previously, I asked students to register for Autonomous Vehicle course and within less than a week we have 365 registration...