我想讀取以下網站ufldl.stanford.edu/housenumbers中給出的mat文件,文件train.tar.gz中有一個mat文件名爲digitStruct.mat。如何在python中讀取Mat v7.3文件?
當我使用scipy.io來讀取mat文件時,它告訴我'請使用hdf reader for matlab v7.3文件'。
原始MATLAB文件被提供作爲下面
load digitStruct.mat
for i = 1:length(digitStruct)
im = imread([digitStruct(i).name]);
for j = 1:length(digitStruct(i).bbox)
[height, width] = size(im);
aa = max(digitStruct(i).bbox(j).top+1,1);
bb = min(digitStruct(i).bbox(j).top+digitStruct(i).bbox(j).height, height);
cc = max(digitStruct(i).bbox(j).left+1,1);
dd = min(digitStruct(i).bbox(j).left+digitStruct(i).bbox(j).width, width);
imshow(im(aa:bb, cc:dd, :));
fprintf('%d\n',digitStruct(i).bbox(j).label);
pause;
end
end
如上所示,墊子文件具有鍵「digitStruct」和「digitStruct」內,鍵「名稱」和「BBOX」,可以發現,我用h5py API來讀取文件。
import h5py
f = h5py.File('train.mat')
print len(f['digitStruct']['name']), len(f['digitStruct']['bbox'] )
我可以讀取數組,但是當我循環訪問數組時,如何讀取每個項目?
for i in f['digitStruct']['name']:
print i # only print out the HDF5 ref
嘿,你有解決方案嗎?我也有同樣的問題。謝謝 –