Fix issues #546 & #552, enable MSVC HDF build.

pull/547/head
Balint Cristian 9 years ago
parent 7b2c6f83a1
commit 133f9c8385
  1. 22
      modules/hdf/CMakeLists.txt
  2. 67
      modules/hdf/src/hdf5.cpp

@ -1,6 +1,24 @@
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${CMAKE_CURRENT_SOURCE_DIR}) set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${CMAKE_CURRENT_SOURCE_DIR})
if(WIN32)
# windows cmake internal lookups are broken for now
# will lookup for headers and shared libs given HDF_DIR env
find_path(HDF5_INCLUDE_DIRS hdf5.h HINTS "$ENV{HDF5_DIR}\\..\\include")
find_library(HDF5_C_LIBRARY NAMES hdf5 HINTS "$ENV{HDF5_DIR}\\..\\lib")
if(HDF5_INCLUDE_DIRS AND HDF5_C_LIBRARY)
set(HDF5_FOUND "YES")
set(HDF5_LIBRARIES ${HDF5_C_LIBRARY})
mark_as_advanced(HDF5_LIBRARIES)
mark_as_advanced(HDF5_C_LIBRARY)
mark_as_advanced(HDF5_INCLUDE_DIRS)
add_definitions(-DH5_BUILT_AS_DYNAMIC_LIB -D_HDF5USEDLL_)
else()
set(HDF5_FOUND "NO")
endif()
else()
find_package(HDF5) find_package(HDF5)
endif()
if(HDF5_FOUND) if(HDF5_FOUND)
set(HAVE_HDF5 1) set(HAVE_HDF5 1)
message(STATUS "HDF5: YES") message(STATUS "HDF5: YES")
@ -9,13 +27,13 @@ else()
message(STATUS "HDF5: NO") message(STATUS "HDF5: NO")
endif() endif()
if(${HDF5_FOUND}) if(HDF5_FOUND)
include_directories(${HDF5_INCLUDE_DIRS}) include_directories(${HDF5_INCLUDE_DIRS})
endif() endif()
set(the_description "Hierarchical Data Format I/O") set(the_description "Hierarchical Data Format I/O")
ocv_define_module(hdf opencv_core WRAP python) ocv_define_module(hdf opencv_core WRAP python)
if(${HDF5_FOUND}) if(HDF5_FOUND)
target_link_libraries(opencv_hdf ${HDF5_LIBRARIES}) target_link_libraries(opencv_hdf ${HDF5_LIBRARIES})
endif() endif()

@ -329,7 +329,7 @@ vector<int> HDF5Impl::dsgetsize( String dslabel, int dims_flag ) const
int n_dims = H5Sget_simple_extent_ndims( fspace ); int n_dims = H5Sget_simple_extent_ndims( fspace );
// dims storage // dims storage
hsize_t dims[n_dims]; hsize_t *dims = new hsize_t[n_dims];
// output storage // output storage
vector<int> SizeVect(0); vector<int> SizeVect(0);
@ -367,6 +367,8 @@ vector<int> HDF5Impl::dsgetsize( String dslabel, int dims_flag ) const
H5Dclose( dsdata ); H5Dclose( dsdata );
H5Sclose( fspace ); H5Sclose( fspace );
delete dims;
return SizeVect; return SizeVect;
} }
@ -386,7 +388,7 @@ int HDF5Impl::dsgettype( String dslabel ) const
// fetch channs // fetch channs
hsize_t ardims[1]; hsize_t ardims[1];
H5Tget_array_dims( dstype, ardims ); H5Tget_array_dims( dstype, ardims );
channs = ardims[0]; channs = (int)ardims[0];
// fetch depth // fetch depth
hid_t tsuper = H5Tget_super( dstype ); hid_t tsuper = H5Tget_super( dstype );
h5type = H5Tget_native_type( tsuper, H5T_DIR_ASCEND ); h5type = H5Tget_native_type( tsuper, H5T_DIR_ASCEND );
@ -481,9 +483,9 @@ void HDF5Impl::dscreate( const int n_dims, const int* sizes, const int type,
int channs = CV_MAT_CN( type ); int channs = CV_MAT_CN( type );
hsize_t chunks[n_dims]; hsize_t *chunks = new hsize_t[n_dims];
hsize_t dsdims[n_dims]; hsize_t *dsdims = new hsize_t[n_dims];
hsize_t maxdim[n_dims]; hsize_t *maxdim = new hsize_t[n_dims];
// dimension space // dimension space
for ( int d = 0; d < n_dims; d++ ) for ( int d = 0; d < n_dims; d++ )
@ -529,7 +531,7 @@ void HDF5Impl::dscreate( const int n_dims, const int* sizes, const int type,
// expand channs // expand channs
if ( channs > 1 ) if ( channs > 1 )
{ {
hsize_t adims[1] = { channs }; hsize_t adims[1] = { (hsize_t)channs };
dstype = H5Tarray_create( dstype, 1, adims ); dstype = H5Tarray_create( dstype, 1, adims );
} }
@ -540,6 +542,10 @@ void HDF5Impl::dscreate( const int n_dims, const int* sizes, const int type,
if ( channs > 1 ) if ( channs > 1 )
H5Tclose( dstype ); H5Tclose( dstype );
delete chunks;
delete dsdims;
delete maxdim;
H5Pclose( dsdcpl ); H5Pclose( dsdcpl );
H5Sclose( dspace ); H5Sclose( dspace );
} }
@ -554,7 +560,7 @@ void HDF5Impl::dsread( OutputArray Array, String dslabel ) const
void HDF5Impl::dsread( OutputArray Array, String dslabel, void HDF5Impl::dsread( OutputArray Array, String dslabel,
const int* dims_offset ) const const int* dims_offset ) const
{ {
dsread( Array, dslabel, dims_offset ); dsread( Array, dslabel, dims_offset, NULL );
} }
// overload // overload
@ -585,7 +591,7 @@ void HDF5Impl::dsread( OutputArray Array, String dslabel,
// fetch channs // fetch channs
hsize_t ardims[1]; hsize_t ardims[1];
H5Tget_array_dims( dstype, ardims ); H5Tget_array_dims( dstype, ardims );
channs = ardims[0]; channs = (int) ardims[0];
// fetch depth // fetch depth
hid_t tsuper = H5Tget_super( dstype ); hid_t tsuper = H5Tget_super( dstype );
h5type = H5Tget_native_type( tsuper, H5T_DIR_ASCEND ); h5type = H5Tget_native_type( tsuper, H5T_DIR_ASCEND );
@ -602,7 +608,7 @@ void HDF5Impl::dsread( OutputArray Array, String dslabel,
int n_dims = H5Sget_simple_extent_ndims( fspace ); int n_dims = H5Sget_simple_extent_ndims( fspace );
// fetch dims // fetch dims
hsize_t dsdims[n_dims]; hsize_t *dsdims = new hsize_t[n_dims];
H5Sget_simple_extent_dims( fspace, dsdims, NULL ); H5Sget_simple_extent_dims( fspace, dsdims, NULL );
// set amount by custom offset // set amount by custom offset
@ -620,8 +626,8 @@ void HDF5Impl::dsread( OutputArray Array, String dslabel,
} }
// get memory write window // get memory write window
int mxdims[n_dims]; int *mxdims = new int[n_dims];
hsize_t foffset[n_dims]; hsize_t *foffset = new hsize_t[n_dims];
for ( int d = 0; d < n_dims; d++ ) for ( int d = 0; d < n_dims; d++ )
{ {
foffset[d] = 0; foffset[d] = 0;
@ -653,6 +659,10 @@ void HDF5Impl::dsread( OutputArray Array, String dslabel,
Mat matrix = Array.getMat(); Mat matrix = Array.getMat();
H5Dread( dsdata, dstype, dspace, fspace, H5P_DEFAULT, matrix.data ); H5Dread( dsdata, dstype, dspace, fspace, H5P_DEFAULT, matrix.data );
delete dsdims;
delete mxdims;
delete foffset;
H5Tclose( dstype ); H5Tclose( dstype );
H5Sclose( dspace ); H5Sclose( dspace );
H5Sclose( fspace ); H5Sclose( fspace );
@ -692,9 +702,9 @@ void HDF5Impl::dswrite( InputArray Array, String dslabel,
int n_dims = matrix.dims; int n_dims = matrix.dims;
int channs = matrix.channels(); int channs = matrix.channels();
int dsizes[n_dims]; int *dsizes = new int[n_dims];
hsize_t dsdims[n_dims]; hsize_t *dsdims = new hsize_t[n_dims];
hsize_t offset[n_dims]; hsize_t *offset = new hsize_t[n_dims];
// replicate Mat dimensions // replicate Mat dimensions
for ( int d = 0; d < n_dims; d++ ) for ( int d = 0; d < n_dims; d++ )
{ {
@ -738,7 +748,7 @@ void HDF5Impl::dswrite( InputArray Array, String dslabel,
// expand channs // expand channs
if ( matrix.channels() > 1 ) if ( matrix.channels() > 1 )
{ {
hsize_t adims[1] = { channs }; hsize_t adims[1] = { (hsize_t)channs };
dstype = H5Tarray_create( dstype, 1, adims ); dstype = H5Tarray_create( dstype, 1, adims );
} }
@ -749,6 +759,10 @@ void HDF5Impl::dswrite( InputArray Array, String dslabel,
if ( matrix.channels() > 1 ) if ( matrix.channels() > 1 )
H5Tclose( dstype ); H5Tclose( dstype );
delete dsizes;
delete dsdims;
delete offset;
H5Sclose( dspace ); H5Sclose( dspace );
H5Sclose( fspace ); H5Sclose( fspace );
H5Dclose( dsdata ); H5Dclose( dsdata );
@ -793,8 +807,8 @@ void HDF5Impl::dsinsert( InputArray Array, String dslabel,
int n_dims = matrix.dims; int n_dims = matrix.dims;
int channs = matrix.channels(); int channs = matrix.channels();
hsize_t dsdims[n_dims]; hsize_t *dsdims = new hsize_t[n_dims];
hsize_t offset[n_dims]; hsize_t *offset = new hsize_t[n_dims];
// replicate Mat dimensions // replicate Mat dimensions
for ( int d = 0; d < n_dims; d++ ) for ( int d = 0; d < n_dims; d++ )
{ {
@ -828,14 +842,14 @@ void HDF5Impl::dsinsert( InputArray Array, String dslabel,
// get actual file space and dims // get actual file space and dims
hid_t fspace = H5Dget_space( dsdata ); hid_t fspace = H5Dget_space( dsdata );
int f_dims = H5Sget_simple_extent_ndims( fspace ); int f_dims = H5Sget_simple_extent_ndims( fspace );
hsize_t fsdims[f_dims]; hsize_t *fsdims = new hsize_t[f_dims];
H5Sget_simple_extent_dims( fspace, fsdims, NULL ); H5Sget_simple_extent_dims( fspace, fsdims, NULL );
H5Sclose( fspace ); H5Sclose( fspace );
CV_Assert( f_dims == n_dims ); CV_Assert( f_dims == n_dims );
// compute new extents // compute new extents
hsize_t nwdims[n_dims]; hsize_t *nwdims = new hsize_t[n_dims];
for ( int d = 0; d < n_dims; d++ ) for ( int d = 0; d < n_dims; d++ )
{ {
// init // init
@ -869,7 +883,7 @@ void HDF5Impl::dsinsert( InputArray Array, String dslabel,
// expand channs // expand channs
if ( matrix.channels() > 1 ) if ( matrix.channels() > 1 )
{ {
hsize_t adims[1] = { channs }; hsize_t adims[1] = { (hsize_t)channs };
dstype = H5Tarray_create( dstype, 1, adims ); dstype = H5Tarray_create( dstype, 1, adims );
} }
@ -880,6 +894,11 @@ void HDF5Impl::dsinsert( InputArray Array, String dslabel,
if ( matrix.channels() > 1 ) if ( matrix.channels() > 1 )
H5Tclose( dstype ); H5Tclose( dstype );
delete dsdims;
delete offset;
delete fsdims;
delete nwdims;
H5Sclose( dspace ); H5Sclose( dspace );
H5Sclose( fspace ); H5Sclose( fspace );
H5Dclose( dsdata ); H5Dclose( dsdata );
@ -976,16 +995,18 @@ void HDF5Impl::kpwrite( const vector<KeyPoint> keypoints, String kplabel,
{ {
CV_Assert( keypoints.size() > 0 ); CV_Assert( keypoints.size() > 0 );
int dskdims[1];
hsize_t dsddims[1]; hsize_t dsddims[1];
hsize_t doffset[1]; hsize_t doffset[1];
// replicate vector dimension // replicate vector dimension
doffset[0] = 0; doffset[0] = 0;
dsddims[0] = keypoints.size(); dsddims[0] = keypoints.size();
dskdims[0] = (int)keypoints.size();
// pre-create dataset if needed // pre-create dataset if needed
if ( hlexists( kplabel ) == false ) if ( hlexists( kplabel ) == false )
kpcreate( dsddims[0], kplabel ); kpcreate( dskdims[0], kplabel );
// set custom amount of data // set custom amount of data
if ( counts != H5_NONE ) if ( counts != H5_NONE )
@ -1058,7 +1079,7 @@ void HDF5Impl::kpinsert( const vector<KeyPoint> keypoints, String kplabel,
// get actual file space and dims // get actual file space and dims
hid_t fspace = H5Dget_space( dsdata ); hid_t fspace = H5Dget_space( dsdata );
int f_dims = H5Sget_simple_extent_ndims( fspace ); int f_dims = H5Sget_simple_extent_ndims( fspace );
hsize_t fsdims[f_dims]; hsize_t *fsdims = new hsize_t[f_dims];
H5Sget_simple_extent_dims( fspace, fsdims, NULL ); H5Sget_simple_extent_dims( fspace, fsdims, NULL );
H5Sclose( fspace ); H5Sclose( fspace );
@ -1101,6 +1122,8 @@ void HDF5Impl::kpinsert( const vector<KeyPoint> keypoints, String kplabel,
// write into dataset // write into dataset
H5Dwrite( dsdata, mmtype, dspace, fspace, H5P_DEFAULT, &keypoints[0] ); H5Dwrite( dsdata, mmtype, dspace, fspace, H5P_DEFAULT, &keypoints[0] );
delete fsdims;
H5Tclose( mmtype ); H5Tclose( mmtype );
H5Sclose( dspace ); H5Sclose( dspace );
H5Sclose( fspace ); H5Sclose( fspace );

Loading…
Cancel
Save