Computer vision

Lane detection, classical vs deep

The same problem solved twice, with a hand-built OpenCV pipeline and a U-Net, and scored head to head on the full TuSimple test set.

Dashcam video with the detected lane area, curvature and offset drawn on it

The problem

Lane keeping needs to know where the two lines around the car are, and a hand-tuned OpenCV pipeline can often find them. Deep networks are the default now, but the comparison is rarely made on equal terms. I built both, gave them the same output format and scored them once on the same test set to see where each one wins and fails.

What I built

  1. Classical pipeline: chessboard calibration, a bird's-eye homography, colour and gradient thresholds, sliding windows and a polynomial fit per lane. Its parameters are grid-searched on 1,000 training images.
  2. A U-Net with a pretrained ResNet-34 encoder that labels each pixel with its lane slot, trained with weighted cross-entropy plus Dice because lane pixels are about 2 % of the image. The checkpoint is picked on validation accuracy.
  3. Both detectors feed the same TuSimple metric, curvature and offset measurement and lane-departure warning, and are scored once on the full test set.
  4. Exported the network to ONNX (FP32, FP16, INT8) and CoreML, re-scored every variant, and ported the post-processing to JavaScript so the INT8 model runs in the browser.

Results

TuSimple accuracy, false positives and false negatives on the full test set of 2,782 images.
MethodEgo accEgo FPEgo FNAll-lanes accms / frame
Classical, tuned on train0.7730.3300.3950.5419.8
U-Net ResNet-340.9510.0530.0510.95020.7

What the results show

  • On its home domain the network cuts false positives and negatives from 33–40 % to about 5 %. Most classical failures are faint dashes and Botts' dots that fixed thresholds can't see.
  • The classical pipeline is twice as fast, needs no training data, and every failure can be traced in its debug views.
  • More data helped the network more than more epochs: a model trained on a 233-image subset for 60 epochs reached 0.914 ego accuracy on that subset's own test split.
  • INT8 costs 0.001 ego accuracy at a quarter of the size. CoreML FP16 moves lane points by a median 8 px, still inside TuSimple's 20 px tolerance.

Limitations

  • Neither method holds up off-domain. On Udacity's challenge video the classical pipeline follows an asphalt seam, and the network gives unstable curves and a false departure warning.
  • The departure warning uses a homography calibrated on straight road, so tight bends can trigger false warnings.
  • Daytime highway data only, and no temporal smoothing of the network output in video.

Full results, commands and figures are in the repository README.