Lane detection with a classical and with a deep learning based approach for Computer Vision for Vehicle course. Contains a simple lane detection algorithm and inference in C++/libtorch for a pretrained ERFNet on TuSimple with Hsu clustering loss.
- Load the KITTI odometry01 directory in greyscale and visualize it
- Obtain a IPM image applying the homography matrix given
- Process the IPM with a DLD kernel
- Binarize the obtained image with a fixed threshold
- Binarize the obtained image with an adaptive threshold:
LANE(x,y) = (DLD(x,y) > alpha*AVG(x,y)) ? 255 : 0
- Cluster the points together. A point belongs to a cluster if it is near (NxN) to a point in that cluster.
- Bonus: fitting with Hough Transform
- Start from the bottom of the binarized image and proceed
- Use
cv::Point2d
if you wantstd::vector< std::vector <cv::Point2d> >
- Visualize the clusters with random colors using
rand()
or color palette
- The conversion between the cartesian and polar space is
r = cos(t) * (x) + sin(t) * (y)
- Pay attention to degrees and radiants!
- Load the CNN using
std::shared_ptr<torch::jit::script::Module> module = torch::jit::load("../res/model_cpp.cnn");
- Read the images in the 0531 folder in
READ_COLOR
mode - Resize the images (512x256) with
cv::resize(scr_im, dst_im, cv::Size(w, h));
- Convert the images using
tc.toTensor(image)
initializing an objecttc = TConverter();
- Create a
std::vector
oftorch::jit::IValue
andpush_back
the Tensor - Forward the array inside the neural network with
at::Tensor output = module->forward(inputs).toTensor();
- Get the output with
std::tuple<at::Tensor, at::Tensor> output_max = at::max(output, 1); at::Tensor argmax = std::get<1>(output_max); argmax = argmax.to(at::kByte);
- Visualize the different lanes with different colors. Get the prediction image with
cv::Mat prediction_vectors = tc.toImage(argmax, TConverter::CONVERT_GRAYSCALE, image.size());
. You will get a matrix where 0=background, 1/2/3/4 = different lanes.
- libprotobuf not found when compiling Lane_CNN:
sudo apt-get install libprotobuf-dev
- Issues with
imshow
: try to manually download and compile OpenCV - Other issues with libtorch: manually download libtorch and link it with
cmake -DCMAKE_PREFIX_PATH=path/to/libtorch ..
- Issues with libmklml: download it from the repo and place it in
libtorch/lib