Merge pull request #502 from cbalint13:hdf

pull/505/head
Alexander Alekhin 9 years ago
commit 57337b5ac4
  1. 9
      modules/hdf/include/opencv2/hdf/hdf5.hpp
  2. 48
      modules/hdf/src/hdf5.cpp

@ -63,7 +63,7 @@ public:
CV_WRAP enum CV_WRAP enum
{ {
H5_UNLIMITED = -1, H5_NONE = -1, H5_GETDIMS = 100, H5_GETMAXDIMS = 101, H5_UNLIMITED = -1, H5_NONE = -1, H5_GETDIMS = 100, H5_GETMAXDIMS = 101, H5_GETCHUNKDIMS = 102,
}; };
virtual ~HDF5() {} virtual ~HDF5() {}
@ -278,7 +278,9 @@ public:
actual dataset dimensions. Using H5_GETMAXDIM flag will get maximum allowed dimension which normally match actual dataset dimensions. Using H5_GETMAXDIM flag will get maximum allowed dimension which normally match
actual dataset dimension but can hold H5_UNLIMITED value if dataset was prepared in **unlimited** mode on actual dataset dimension but can hold H5_UNLIMITED value if dataset was prepared in **unlimited** mode on
some of its dimension. It can be useful to check existing dataset dimensions before overwrite it as whole or subset. some of its dimension. It can be useful to check existing dataset dimensions before overwrite it as whole or subset.
Trying to write with oversized source data into dataset target will thrown exception. Trying to write with oversized source data into dataset target will thrown exception. The H5_GETCHUNKDIMS will
return the dimension of chunk if dataset was created with chunking options otherwise returned vector size
will be zero.
*/ */
CV_WRAP virtual vector<int> dsgetsize( String dslabel, int dims_flag = HDF5::H5_GETDIMS ) const = 0; CV_WRAP virtual vector<int> dsgetsize( String dslabel, int dims_flag = HDF5::H5_GETDIMS ) const = 0;
@ -488,7 +490,8 @@ public:
Using H5_GETMAXDIM flag will get maximum allowed dimension which normally match actual dataset dimension but can hold Using H5_GETMAXDIM flag will get maximum allowed dimension which normally match actual dataset dimension but can hold
H5_UNLIMITED value if dataset was prepared in **unlimited** mode. It can be useful to check existing dataset dimension H5_UNLIMITED value if dataset was prepared in **unlimited** mode. It can be useful to check existing dataset dimension
before overwrite it as whole or subset. Trying to write with oversized source data into dataset target will thrown before overwrite it as whole or subset. Trying to write with oversized source data into dataset target will thrown
exception. exception. The H5_GETCHUNKDIMS will return the dimension of chunk if dataset was created with chunking options otherwise
returned vector size will be zero.
*/ */
CV_WRAP virtual int kpgetsize( String kplabel, int dims_flag = HDF5::H5_GETDIMS ) const = 0; CV_WRAP virtual int kpgetsize( String kplabel, int dims_flag = HDF5::H5_GETDIMS ) const = 0;

@ -266,14 +266,16 @@ HDF5Impl::HDF5Impl( String _hdf5_filename )
// restore previous error handler // restore previous error handler
H5Eset_auto( stackid, errfunc, errdata ); H5Eset_auto( stackid, errfunc, errdata );
if ( check == 1 ) if ( check == 1 || check == 0 )
// open the HDF5 file // open the HDF5 file
m_h5_file_id = H5Fopen( m_hdf5_filename.c_str(), m_h5_file_id = H5Fopen( m_hdf5_filename.c_str(),
H5F_ACC_RDWR, H5P_DEFAULT ); H5F_ACC_RDWR, H5P_DEFAULT );
else else if ( check == -1 )
// create the HDF5 file // file does not exist
m_h5_file_id = H5Fcreate( m_hdf5_filename.c_str(), m_h5_file_id = H5Fcreate( m_hdf5_filename.c_str(),
H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT ); H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT );
else
CV_Error( Error::StsInternal, "Unknown file state." );
} }
void HDF5Impl::close() void HDF5Impl::close()
@ -282,8 +284,6 @@ void HDF5Impl::close()
H5Fclose( m_h5_file_id ); H5Fclose( m_h5_file_id );
// mark closed // mark closed
m_h5_file_id = -1; m_h5_file_id = -1;
H5close( );
} }
/* /*
@ -328,17 +328,41 @@ vector<int> HDF5Impl::dsgetsize( String dslabel, int dims_flag ) const
// fetch rank // fetch rank
int n_dims = H5Sget_simple_extent_ndims( fspace ); int n_dims = H5Sget_simple_extent_ndims( fspace );
// dims storage
hsize_t dims[n_dims];
// output storage
vector<int> SizeVect(0);
// fetch dims // fetch dims
hsize_t dsdims[n_dims]; if ( dims_flag == H5_GETDIMS ||
if ( dims_flag == H5_GETDIMS ) dims_flag == H5_GETMAXDIMS )
H5Sget_simple_extent_dims( fspace, dsdims, NULL ); {
if ( dims_flag == H5_GETDIMS )
H5Sget_simple_extent_dims( fspace, dims, NULL );
else
H5Sget_simple_extent_dims( fspace, NULL, dims );
SizeVect.resize( n_dims );
}
else if ( dims_flag == H5_GETCHUNKDIMS )
{
// rank size
int rank_chunk = -1;
// fetch chunk size
hid_t cparms = H5Dget_create_plist( dsdata );
if ( H5D_CHUNKED == H5Pget_layout ( cparms ) )
{
rank_chunk = H5Pget_chunk ( cparms, n_dims, dims );
}
if ( rank_chunk > 0 )
SizeVect.resize( n_dims );
}
else else
H5Sget_simple_extent_dims( fspace, NULL, dsdims ); CV_Error( Error::StsInternal, "Unknown dimension flag." );
// fill with size data // fill with size data
vector<int> SizeVect( n_dims ); for ( size_t d = 0; d < SizeVect.size(); d++ )
for ( int d = 0; d < n_dims; d++ ) SizeVect[d] = (int) dims[d];
SizeVect[d] = (int) dsdims[d];
H5Dclose( dsdata ); H5Dclose( dsdata );
H5Sclose( fspace ); H5Sclose( fspace );

Loading…
Cancel
Save