首页 > 解决方案 > 将每个对象的索引存储到二维列表中

问题描述

print(humans)
for human in humans:
    pose_2d_mpii, visibility = common.MPIIPart.from_coco(human)
    pose_2d_mpiis.append([(int(x * standard_w + 0.5), int(y * standard_h + 0.5)) for x, y in pose_2d_mpii])
    visibilities.append(visibility)
    # This is to account for events where a body part is not detected - affects indexing order #
    # Create list indexing to find the actual index of body parts #
    print(human.body_parts.items())
    for item in human.body_parts.items():
        indexing.append(item[0])

print(indexing)

    

这是人类的输出:

[<estimator.Human object at 0x0000024AEBBC4508>, <estimator.Human object at 0x0000024AEBBC4548>, <estimator.Human object at 0x0000024AEBBC45C8>]

这是 human.body_parts.item() 输出:

dict_items([(1, <estimator.BodyPart object at 0x0000024AE59949F8>), (2, <estimator.BodyPart object at 0x0000024AEAAEFB38>), (5, <estimator.BodyPart object at 0x0000024AE5994A48>), (3, <estimator.BodyPart object at 0x0000024AEAAEF598>), (4, <estimator.BodyPart object at 0x0000024AE5198048>), (6, <estimator.BodyPart object at 0x0000024AEAAEFF98>), (7, <estimator.BodyPart object at 0x0000024AEBBBED68>), (8, <estimator.BodyPart object at 0x0000024AEAAEFAE8>), (11, <estimator.BodyPart object at 0x0000024AEAAEFD68>), (0, <estimator.BodyPart object at 0x0000024AE59944F8>), (14, <estimator.BodyPart object at 0x0000024AE59947C8>), (16, <estimator.BodyPart object at 0x0000024AEAAEF638>), (15, <estimator.BodyPart object at 0x0000024AE5994598>), (17, <estimator.BodyPart object at 0x0000024AEAAEF188>)])
dict_items([(1, <estimator.BodyPart object at 0x0000024AE59948B8>), (2, <estimator.BodyPart object at 0x0000024AEAAEFBD8>), (5, <estimator.BodyPart object at 0x0000024AE5994908>), (3, <estimator.BodyPart object at 0x0000024AEAAEF6D8>), (6, <estimator.BodyPart object at 0x0000024AEAAEF1D8>), (7, <estimator.BodyPart object at 0x0000024AEAAEF688>), (8, <estimator.BodyPart object at 0x0000024AE5994728>), (11, <estimator.BodyPart object at 0x0000024AE5994B88>), (12, <estimator.BodyPart object at 0x0000024AE5994B38>), (0, <estimator.BodyPart object at 0x0000024AE59945E8>), (14, <estimator.BodyPart object at 0x0000024AE5994868>), (16, <estimator.BodyPart object at 0x0000024AEAAEFA48>), (15, <estimator.BodyPart object at 0x0000024AE5994638>), (17, <estimator.BodyPart object at 0x0000024AEAAEF728>)])
dict_items([(1, <estimator.BodyPart object at 0x0000024AE5994A98>), (2, <estimator.BodyPart object at 0x0000024AEAAEFC78>), (5, <estimator.BodyPart object at 0x0000024AE5994BD8>), (3, <estimator.BodyPart object at 0x0000024AEAAEF4F8>), (4, <estimator.BodyPart object at 0x0000024AEAAEF548>), (6, <estimator.BodyPart object at 0x0000024AEAAEFEA8>), (7, <estimator.BodyPart object at 0x0000024AEAAEF818>), (8, <estimator.BodyPart object at 0x0000024AE5994778>), (11, <estimator.BodyPart object at 0x0000024AEAAEFC28>), (0, <estimator.BodyPart object at 0x0000024AEAAEF9A8>), (14, <estimator.BodyPart object at 0x0000024AE59946D8>), (16, <estimator.BodyPart object at 0x0000024AEAAEFE08>), (15, <estimator.BodyPart object at 0x0000024AEAAEF9F8>), (17, <estimator.BodyPart object at 0x0000024AEAAEF228>)])

这是索引输出:

[1, 2, 5, 3, 4, 6, 7, 8, 11, 0, 14, 16, 15, 17, 1, 2, 5, 3, 6, 7, 8, 11, 12, 0, 14, 16, 15, 17, 1, 2, 5, 3, 4, 6, 7, 8, 11, 0, 14, 16, 15, 17]

由于 tf-pose-estimate 的检测精度,每个 Human 对象的项目数不同。我希望能够为每个人创建一个二维列表作为行,并将相应的索引作为列。上面的代码是我为单一人类场景编写的。但是,如果我要使用相同的代码,该列表将是多个人类场景的所有人类索引的组合。我将不胜感激所有的帮助。谢谢!

indexing[0].append(item[0])

据我了解,这将是执行此操作的适当方法吗?但是我将如何为每个人循环这个?

标签: pythonpython-3.xlistappendpose-estimation

解决方案


推荐阅读