【问题标题】:Python error numpy.int32 object is not iterable [duplicate]Python错误numpy.int32对象不可迭代[重复]
【发布时间】:2020-03-08 04:50:01
【问题描述】:

我有一个下面的 python 代码来检测框架中的人。一旦检测到,它就会得到人的边界框person_box。从person_box我可以得到边界框的startX, startYwidth height。但在下面的代码中,在 for 循环中,我收到错误为 numpy.int32 object is not iterable

person_box = person_detections[0, 0, i, 3:7] * np.array([W, H, W, H])
person_box = person_box.astype(int)
print(person_box)
(startX, startY, endX, endY) = person_box.astype("int")
width = endX - startX
height = endY - startY

for (startX, startY, width, height) in person_box:
    person_box = np.array([startX, startY, startX + width, startY + height])

输出

[159 156 451 431]

我无法理解这个错误,因为我对 numpy 数组没有太多经验。请帮忙。谢谢。

【问题讨论】:

  • 显示回溯

标签: python numpy-ndarray


【解决方案1】:

for 循环将迭代person_box 并逐个传递参数。您正在尝试拆分参数并分配给for (startX, startY, width, height) in person_box: 中的startX, startY, width, height,您可以尝试:

person_box = np.array([person_box [0], person_box[1] , person_box[0] + person_box[2] , person_box[1] + person_box[3] ])

startX = person_box[0]
startY = person_box[1]
width = person_box[2]
height = person_box[3]
person_box = np.array([startX, startY, startX + width, startY + height])

【讨论】:

    猜你喜欢
    • 2018-07-20
    • 1970-01-01
    • 1970-01-01
    • 2013-07-02
    • 2017-06-22
    • 2014-10-09
    • 2017-06-29
    • 2017-03-05
    • 1970-01-01
    相关资源
    最近更新 更多