matlab文件结构 主文件,python读取的复杂Matlab结构文件

我得到(在这个案例中,使用共享文件是个好主意):

装载:data = io.loadmat('../Downloads/anno_bbox.mat')

我得到:

^{2}$

我可以指定bbox_test=data['bbox_test']。这个变量有9658条记录,有三个字段,每个字段都有object dtype。在

所以有一个文件名(嵌入在1元素数组中的字符串)In [101]: data['bbox_test'][0,0]['filename']

Out[101]: array(['HICO_test2015_00000001.jpg'], dtype='

size有3个字段,在数组中嵌入了3个数字(2d matlab矩阵):In [102]: data['bbox_test'][0,0]['size']

Out[102]:

array([[(array([[640]], dtype=uint16), array([[427]], dtype=uint16), array([[3]], dtype=uint8))]],

dtype=[('width', 'O'), ('height', 'O'), ('depth', 'O')])

In [112]: data['bbox_test'][0,0]['size'][0,0].item()

Out[112]:

(array([[640]], dtype=uint16),

array([[427]], dtype=uint16),

array([[3]], dtype=uint8))

hoi更复杂:In [103]: data['bbox_test'][0,0]['hoi']

Out[103]:

array([[(array([[246]], dtype=uint8), array([[(array([[320]], dtype=uint16), array([[359]], dtype=uint16), array([[306]], dtype=uint16), array([[349]], dtype=uint16)),...

dtype=[('id', 'O'), ('bboxhuman', 'O'), ('bboxobject', 'O'), ('connection', 'O'), ('invis', 'O')])

In [126]: data['bbox_test'][0,1]['hoi']['id']

Out[126]:

array([[array([[132]], dtype=uint8), array([[140]], dtype=uint8),

array([[144]], dtype=uint8)]], dtype=object)

In [130]: data['bbox_test'][0,1]['hoi']['bboxhuman'][0,0]

Out[130]:

array([[(array([[226]], dtype=uint8), array([[340]], dtype=uint16), array([[18]], dtype=uint8), array([[210]], dtype=uint8))]],

dtype=[('x1', 'O'), ('x2', 'O'), ('y1', 'O'), ('y2', 'O')])

因此,在MATLAB结构中显示的数据都在那里,在数组(通常是2d(1,1)形状)、对象数据类型或多个字段的嵌套结构中。在

返回并加载squeeze_me我得到了一个更简单的:In [133]: data['bbox_test'][1]['hoi']['bboxhuman']

Out[133]:

array([array((226, 340, 18, 210),

dtype=[('x1', 'O'), ('x2', 'O'), ('y1', 'O'), ('y2', 'O')]),

array((230, 356, 19, 212),

dtype=[('x1', 'O'), ('x2', 'O'), ('y1', 'O'), ('y2', 'O')]),

array((234, 342, 13, 202),

dtype=[('x1', 'O'), ('x2', 'O'), ('y1', 'O'), ('y2', 'O')])],

dtype=object)

使用struct_as_record='False',我得到In [136]: data['bbox_test'][1]

Out[136]:

查看此rec的属性,我可以通过属性名访问“fields”:In [137]: rec = data['bbox_test'][1]

In [138]: rec.filename

Out[138]: 'HICO_test2015_00000002.jpg'

In [139]: rec.size

Out[139]:

In [141]: rec.size.width

Out[141]: 640

In [142]: rec.hoi

Out[142]:

array([,

,

],

dtype=object)

In [145]: rec.hoi[1].bboxhuman

Out[145]:

In [146]: rec.hoi[1].bboxhuman.x1

Out[146]: 230

In [147]: vars(rec.hoi[1].bboxhuman)

Out[147]:

{'_fieldnames': ['x1', 'x2', 'y1', 'y2'],

'x1': 230,

'x2': 356,

'y1': 19,

'y2': 212}

等等。在

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值