voldemortX / pytorch-auto-drive

PytorchAutoDrive: Segmentation models (ERFNet, ENet, DeepLab, FCN...) and Lane detection models (SCNN, RESA, LSTR, LaneATT, BézierLaneNet...) based on PyTorch with fast training, visualization, benchmarking & deployment help
BSD 3-Clause "New" or "Revised" License
850 stars 138 forks source link

About bezier_control_points #155

Closed daeunni closed 1 year ago

daeunni commented 1 year ago

Hi, @voldemortX, I still really appreciate your nice work. :)

Btw, I wanna utilize your bezier_labels dataset to compare the shape of each CULane and TUSimple lanes. I especially want to analyze the curvature of each lane.

so I think I tried to get the curvature from the bezier_control_points like below.

import numpy as np

def calculate_curvature(control_points):
    curvatures = []    
    for curve_points in control_points:
        t = np.linspace(0, 1, len(curve_points) // 2)
        x = curve_points[::2]
        y = curve_points[1::2]

        dx_dt = np.gradient(x, t)
        dy_dt = np.gradient(y, t)

        d2x_dt2 = np.gradient(dx_dt, t)
        d2y_dt2 = np.gradient(dy_dt, t)

        curvature = np.abs(dx_dt * d2y_dt2 - dy_dt * d2x_dt2) / (dx_dt**2 + dy_dt**2)**1.5
        curvatures.append(curvature)

    return curvatures

# Input data
bezier_control_points = [
    [20.122, 499.926, 257.659, 429.921, 495.202, 359.939, 732.764, 290.021],
    [499.298, 590.096, 588.081, 487.337, 678.286, 385.712, 774.891, 290.126],
    [1409.662, 589.936, 1211.566, 489.959, 1013.442, 390.059, 815.358, 290.058],
    [1650.416, 439.999, 1388.091, 388.547, 1126.67, 331.949, 862.549, 290.071]
]

curvatures = calculate_curvature(bezier_control_points)
for i, curve_curvatures in enumerate(curvatures):    
    print(f"Curvatures for Curve {i+1}:")
    print(curve_curvatures)
    print()

From the upper code, I got these results.

Curvatures for Curve 1:
[1.93707160e-07 4.65870062e-07 6.41179970e-07 5.44324660e-07]

Curvatures for Curve 2:
[4.92736453e-05 1.68366957e-04 2.63056668e-04 2.38077982e-04]

Curvatures for Curve 3:
[8.26171703e-07 2.76865852e-07 6.85603690e-07 1.09864069e-06]

Curvatures for Curve 4:
[3.65494821e-05 1.57942102e-05 8.64188993e-05 1.04603821e-04]

So the thing is, can I analyze 4 curvatures per lane are the coefficient? And can I use it to compare w/ TUSimple and CULane together?

voldemortX commented 1 year ago

@daeunni I'm not very good at math, but I think you can get meaningful curvature from control points. Because the curve fitting accuracy is rather high on these datasets.