python求函数曲率_【Python】车道线拟合曲线的曲率半径计算公式及代码

这篇博客介绍了如何在Python中计算车道线拟合曲线的曲率半径,涉及了将像素坐标转换为实际距离的单位,并给出了计算曲率半径的公式和代码实现。
摘要由CSDN通过智能技术生成

学习优达学城的Advanced-Lane-Lines课程时,碰到了车道线的曲率半径计算。初见公式略显陌生,直到想起曲率半径的计算公式时才想明白,故记录如下。

def cal_curverature(img_shape, left_fit, right_fit):

ploty=np.linspace(0, img_shape[0]-1, num=img_shape[0])

ym_per_pix = 30/720 # meters per pixel in y dimension

xm_per_pix = 3.7/700 # meters per pixel in x dimension

# Fit new polynomials to x,y in world space

y_eval = np.max(ploty)

leftx=left_fit[0]*ploty**2+left_fit[1]*ploty+left_fit[2]

rightx=right_fit[0]*ploty**2+right_fit[1]*ploty+right_fit[2]

left_fit_cr = np.polyfit(ploty*ym_per_pix, leftx*xm_per_pix, 2)

right_fit_cr = np.polyfit(ploty*ym_per_pix, rightx*xm_per_pix, 2)

# Calculate the new radii of curvature

left_curverad = ((1 + (2*left_fit_cr[0]*y_eval*ym_per_pix + left_fit_cr[1])**2)**1.5) / np.absolute(2*left_fit_cr[0])

right_curverad = ((1 + (2*right_fit_cr[0]*y_eval*ym_per_pix + right_fit_cr[1])**2)**1.5) / np.absolute(2*right_fit_cr[0])

xoffset=(left_fit_cr[2]+right_fit_cr[2])/2-img.shape[1]*xm_per_pix/2

return left_curverad, right_curverad, xoffset

一、曲率半径公式及推导

5101b3c7d248a68d6f395e6c983d3f67.png

详细推导过程如下:

3af801d469c55af287cce89f4f14d725.png

4dda14fd76a12e2f55d4e0adbf69ff3c.png

二、利用公式计算拟合车道线的曲率半径

假设车道线方程为二次拟合曲线:

x = a*y*y + b*y +c

则在y米远处,曲率半径为:

c06ae0baced571f42e3067c112e0cbb0.png

  • 0
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值