对标记点进行三角化

《Python计算机视觉编程》(《Programming Computer Vision with Python》)一书的第三章第二节分段仿射扭曲一节中,使用狄洛克三角剖分方法时提示错误

ModuleNotFoundError: No module named ‘matplotlib.delaunay’

即,matplotlib库中已经不再支持delaunay模块了。所以我们需要寻找一个别的模块来代替它。我在网上找到了from scipy.spatial import Delaunay 这个方法,scipy库中依然保留有这个模块,所以可以用scipy库来代替matplotlib这个库。
具体实现函数如下:(取自网络)

from scipy.spatial import Delaunay
import numpy as np
import matplotlib.pyplot as plt

# Triangle Settings
width = 100
height = 100
pointNumber = 100
points = np.zeros((pointNumber, 2))
points[:, 0] = np.random.randint(0, width, pointNumber)
points[:, 1] = np.random.randint(0, height, pointNumber)

# Use scipy.spatial.Delaunay for Triangulation
tri = Delaunay(points)

# Plot Delaunay triangle with color filled
center = np.sum(points[tri.simplices], axis=1)/3.0
color = np.array([(x - width/2)**2 + (y - height/<
  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 2
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值