I am trying to read the mat file given in the following website, ufldl.stanford.edu/housenumbers, in the file train.tar.gz, there is a mat file named digitStruct.mat.
when i used scipy.io to read the mat file, it alerts me with the message ' please use hdf reader for matlab v7.3 files '.
the original matlab file is provided as below
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
as shown above, the mat file has the key 'digitStruct', and within 'digitStruct', key 'name' and 'bbox' can be found, I used h5py API to read the file.
import h5py
f = h5py.File('train.mat')
print len( f['digitStruct']['name'] ), len(f['digitStruct']['bbox'] )
I can read the array, however when I loop though the array, how can I read each item?
for i in f['digitStruct']['name']:
print i # only print out the HDF5 ref