You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

使用Chitra获取resize后Bounding Box值报AttributeError如何解决

问题描述

使用Chitra库对单张示例图像及其对应的Bounding Box执行resize操作时,以下代码可正常运行:

box = test_bboxes
label = ['dog']
image = Chitra(test, box, label)
image.resize_image_with_bbox((200, 200))
image.image = image.image.convert('RGB')
plt.imshow(image.draw_boxes())

尝试打印resize后的Bounding Box值,执行如下代码时:

print(image.bounding_boxes)

程序抛出错误:

AttributeError: 'Chitra' object has no attribute 'bounding_boxes'

查阅Chitra官方文档未找到对应解决方案,需要找到正确获取resize后Bounding Box值的方法。

解决方案

报错核心原因是属性名使用错误——你代码里draw_boxes()能正常绘制出框,说明resize后的边界框数据已经正确存在Chitra实例中,只是调用的属性名不对。Chitra类中存储边界框的属性不是bounding_boxes,而是缩写的bboxes,按以下方式即可正确取值:

  • 直接访问image.bboxes可获取所有边界框的对象列表,resize_image_with_bbox方法执行时会自动同步更新列表内所有边界框的坐标,无需手动做缩放换算
  • 单个边界框对象的坐标值存储在coords属性中,遍历列表读取该属性即可拿到数值化的坐标结果

可直接运行的取值示例代码:

# 遍历打印所有resize后的边界框坐标
for bbox in image.bboxes:
    print(bbox.coords)

如果需要一次性拿到所有边界框的坐标集合,也可以用列表推导式快速提取:

all_resized_bboxes = [bbox.coords for bbox in image.bboxes]

内容的提问来源于stack exchange,提问作者Krisna Gita

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.28 19:18:21