Curve Fitting

Reference:
https://cloud.tencent.com/developer/article/1165821

基于Numpy包的polyfit函数实现,其支持的三个参数分别是x点集合、y点集合,以及多项式的幂次。得到多项式方程以后,就可以完整拟合曲线:

代码:

def circle_fitness_demo():
    # 创建图像, 绘制初始点
    image = np.zeros((400, 400, 3), dtype=np.uint8)
    x = np.array([30, 50, 100, 120])
    y = np.array([100, 150, 240, 200])
    for i in range(len(x)):
        cv.circle(image, (x[i], y[i]), 3, (255, 0, 0), -1, 8, 0)

    # 多项式曲线生成
    poly = np.poly1d(np.polyfit(x, y, 3))
    print(poly)

    # 绘制拟合曲线
    for t in range(30, 250, 1):
        y_ = np.int(poly(t))
        cv.circle(image, (t, y_), 1, (0, 0, 255), 1, 8, 0)
    cv.imshow("fit curve", image)
posted @   shendawei  阅读(38)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· TypeScript + Deepseek 打造卜卦网站:技术与玄学的结合
· 阿里巴巴 QwQ-32B真的超越了 DeepSeek R-1吗?
· 【译】Visual Studio 中新的强大生产力特性
· 【设计模式】告别冗长if-else语句:使用策略模式优化代码结构
· 10年+ .NET Coder 心语 ── 封装的思维:从隐藏、稳定开始理解其本质意义
点击右上角即可分享
微信分享提示