TypeError:' float'对象不能解释为整数(python 3.4版本)

时间:2017-11-01 10:42:25

标签: python python-3.x

我正在尝试运行视频文件并收到如下错误。

$ /usr/bin/python3.4 /home/ramakrishna/PycharmProjects/Lanedect/driving-lane-departure-warning-master/main.py
Traceback (most recent call last):

  File "/home/ramakrishna/PycharmProjects/Lanedect/driving-lane-departure-warning-master/main.py", line 19, in <module>
    img_aug = process_frame(img)

  File "/home/ramakrishna/PycharmProjects/Lanedect/driving-lane-departure-warning-master/lane.py", line 615, in process_frame
    output = create_output_frame(offcenter, pts, img_undist_, fps, curvature, curve_direction, binary_sub)

  File "/home/ramakrishna/PycharmProjects/Lanedect/driving-lane-departure-warning-master/lane.py", line 467, in create_output_frame
    whole_frame = np.zeros((h*2.5,w*2.34, 3), dtype=np.uint8)

TypeError: 'float' object cannot be interpreted as an integer

2 个答案:

答案 0 :(得分:2)

以下是出错的原因。

np.zeros((h*2.5,w*2.34, 3), dtype=np.uint8)

np.zeros期望维度为整数,而h*2.5w*2.34的评估结果为float。如果您希望可以使用int()将参数转换为整数。

答案 1 :(得分:0)

我终于得到了它的解决方案..我最初尝试将浮动值分别替换为3和2分别为3.5和3.24。但是因为这些值减少了总帧尺寸而出现错误。然后将其更改为 np.zeros((h * 3,w * 3,3),dtype = np.uint8)并且它有效.. !!