python错误numpy.int32对象不可迭代

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

person_box = person_detections[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,width,height) in person_box:
    person_box = np.array([startX,startX + width,startY + height])

输出

[159 156 451 431]

由于我对numpy数组经验不足,所以我不太了解该错误。请帮忙。谢谢。

suixinyu2009 回答:python错误numpy.int32对象不可迭代

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

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,startX + width,startY + height])
本文链接:https://www.f2er.com/3117228.html

大家都在问