line 117, in linspace num = operator.index(num)TypeError: 'numpy.float64' object cannot be interp

记录一下错误和解决方案

C:\Users\wei\.virtualenvs\pyqt51-EL5sW8oD\Scripts\python.exe E:/work/facode/0finger/app/enhance/image_enhance.py
Traceback (most recent call last):
  File "C:\Users\wei\.virtualenvs\pyqt51-EL5sW8oD\lib\site-packages\numpy\core\function_base.py", line 117, in linspace
    num = operator.index(num)
TypeError: 'numpy.float64' object cannot be interpreted as an integer

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "E:/work/facode/0finger/app/enhance/image_enhance.py", line 68, in <module>
    img = image_enhance(img)
  File "E:/work/facode/0finger/app/enhance/image_enhance.py", line 32, in image_enhance
    newim = ridge_filter(normim, orientim, freq, kx, ky)  # create gabor filter and do the actual filtering
  File "E:\work\facode\0finger\app\enhance\ridge_filter.py", line 59, in ridge_filter
    x, y = np.meshgrid(np.linspace(-sze, sze, (2 * sze + 1)), np.linspace(-sze, sze, (2 * sze + 1)))
  File "<__array_function__ internals>", line 6, in linspace
  File "C:\Users\wei\.virtualenvs\pyqt51-EL5sW8oD\lib\site-packages\numpy\core\function_base.py", line 121, in linspace
    .format(type(num)))
TypeError: object of type <class 'numpy.float64'> cannot be safely interpreted as an integer.

Process finished with exit code 1
找了很多网上的改正方法,没有找到导致错误的代码 看到网上说更换

原因是numpy1.18.2版本与其他软件的兼容性的问题导致。
解决办法:将numpy1.18.2的版本降为1.17,测试可以正常运行。其他可行办法尚未测试。
结果如下:

  • 6
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
抱歉,我之前的回答有误。出现错误的原因是 `bezier_curve_derivative` 被误用成一个函数,而它是一个numpy数组。我将修正代码如下: ```python import numpy as np import matplotlib.pyplot as plt from matplotlib.animation import FuncAnimation def bezier_curve(points, t): n = len(points) - 1 result = np.zeros_like(points[0]) for i in range(n + 1): result += binomial_coefficient(n, i) * ((1 - t) ** (n - i)) * (t ** i) * points[i] return result def binomial_coefficient(n, k): return np.math.factorial(n) / (np.math.factorial(k) * np.math.factorial(n - k)) def update(frame): t = frame / frames tangent = bezier_curve_derivative[frame] angle = np.arctan2(tangent[1], tangent[0]) car.set_transform(plt.transforms.Affine2D().rotate(angle).translated(positions[frame][0], positions[frame][1])) return car, # 贝塞尔曲线控制点 points = np.array([[0, 0], [1, 1], [2, -1], [3, 0]]) # 计算贝塞尔曲线上的点 frames = 100 positions = [bezier_curve(points, t) for t in np.linspace(0, 1, frames)] # 计算贝塞尔曲线切线方向 bezier_curve_derivative = np.gradient(positions, axis=0) # 创建画布和轴 fig, ax = plt.subplots() ax.set_xlim(-2, 4) ax.set_ylim(-2, 2) # 创建小车 car = plt.Rectangle((0, 0), 0.2, 0.1, fc='blue') ax.add_patch(car) # 动画更新函数 animation = FuncAnimation(fig, update, frames=frames, interval=50, blit=True) plt.show() ``` 在修正后的代码中,我将 `bezier_curve_derivative` 改为了一个numpy数组,以便在 `update` 函数中使用正确的切线值。 希望这次能够解决问题。如果还有其他问题,请随时提问。

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值