cv::hdf::HDF5 Class ReferenceabstractHierarchical Data Format I/O routines » Hierarchical Data Format version 5
Hierarchical Data Format version 5 interface. More...
#include <opencv2/hdf/hdf5.hpp>
Public Types | |
Hierarchical Data Format version 5 interface. More...
#include <opencv2/hdf/hdf5.hpp>
Public Types | |
| enum |
| { H5_UNLIMITED = -1 , H5_NONE = -1 , H5_GETDIMS = 100 , H5_GETMAXDIMS = 101 , H5_GETCHUNKDIMS = 102 } |
Public Member Functions | |
| virtual | ~HDF5 () |
| virtual void | atdelete (const String &atlabel)=0 |
| virtual bool | atexists (const String &atlabel) const =0 |
| virtual void | atread (double *value, const String &atlabel)=0 |
| virtual void | atread (int *value, const String &atlabel)=0 |
| virtual void | atread (OutputArray value, const String &atlabel)=0 |
| virtual void | atread (String *value, const String &atlabel)=0 |
| virtual void | atwrite (const double value, const String &atlabel)=0 |
| virtual void | atwrite (const int value, const String &atlabel)=0 |
| virtual void | atwrite (const String &value, const String &atlabel)=0 |
| virtual void | atwrite (InputArray value, const String &atlabel)=0 |
| virtual void | close ()=0 |
| Close and release hdf5 object. | |
| virtual void | dscreate (const int n_dims, const int *sizes, const int type, const String &dslabel) const =0 |
| virtual void | dscreate (const int n_dims, const int *sizes, const int type, const String &dslabel, const int compresslevel) const =0 |
| virtual void | dscreate (const int n_dims, const int *sizes, const int type, const String &dslabel, const int compresslevel, const int *dims_chunks) const =0 |
| Create and allocate storage for n-dimensional dataset, single or multichannel type. | |
| virtual void | dscreate (const int rows, const int cols, const int type, const String &dslabel) const =0 |
| virtual void | dscreate (const int rows, const int cols, const int type, const String &dslabel, const int compresslevel) const =0 |
| virtual void | dscreate (const int rows, const int cols, const int type, const String &dslabel, const int compresslevel, const int *dims_chunks) const =0 |
| Create and allocate storage for two dimensional single or multi channel dataset. | |
| virtual void | dscreate (const int rows, const int cols, const int type, const String &dslabel, const int compresslevel, const vector< int > &dims_chunks) const =0 |
| virtual void | dscreate (const vector< int > &sizes, const int type, const String &dslabel, const int compresslevel=HDF5::H5_NONE, const vector< int > &dims_chunks=vector< int >()) const =0 |
| virtual vector< int > | dsgetsize (const String &dslabel, int dims_flag=HDF5::H5_GETDIMS) const =0 |
| Fetch dataset sizes. | |
| virtual int | dsgettype (const String &dslabel) const =0 |
| Fetch dataset type. | |
| virtual void | dsinsert (InputArray Array, const String &dslabel) const =0 |
| virtual void | dsinsert (InputArray Array, const String &dslabel, const int *dims_offset) const =0 |
| virtual void | dsinsert (InputArray Array, const String &dslabel, const int *dims_offset, const int *dims_counts) const =0 |
| Insert or overwrite a Mat object into specified dataset and auto expand dataset size if unlimited property allows. | |
| virtual void | dsinsert (InputArray Array, const String &dslabel, const vector< int > &dims_offset, const vector< int > &dims_counts=vector< int >()) const =0 |
| virtual void | dsread (OutputArray Array, const String &dslabel) const =0 |
| virtual void | dsread (OutputArray Array, const String &dslabel, const int *dims_offset) const =0 |
| virtual void | dsread (OutputArray Array, const String &dslabel, const int *dims_offset, const int *dims_counts) const =0 |
| Read specific dataset from hdf5 file into Mat object. | |
| virtual void | dsread (OutputArray Array, const String &dslabel, const vector< int > &dims_offset, const vector< int > &dims_counts=vector< int >()) const =0 |
| virtual void | dswrite (InputArray Array, const String &dslabel) const =0 |
| virtual void | dswrite (InputArray Array, const String &dslabel, const int *dims_offset) const =0 |
| virtual void | dswrite (InputArray Array, const String &dslabel, const int *dims_offset, const int *dims_counts) const =0 |
| Write or overwrite a Mat object into specified dataset of hdf5 file. | |
| virtual void | dswrite (InputArray Array, const String &dslabel, const vector< int > &dims_offset, const vector< int > &dims_counts=vector< int >()) const =0 |
| virtual void | grcreate (const String &grlabel)=0 |
| Create a group. | |
| virtual bool | hlexists (const String &label) const =0 |
| Check if label exists or not. | |
| virtual void | kpcreate (const int size, const String &kplabel, const int compresslevel=H5_NONE, const int chunks=H5_NONE) const =0 |
| Create and allocate special storage for cv::KeyPoint dataset. | |
| virtual int | kpgetsize (const String &kplabel, int dims_flag=HDF5::H5_GETDIMS) const =0 |
| Fetch keypoint dataset size. | |
| virtual void | kpinsert (const vector< KeyPoint > keypoints, const String &kplabel, const int offset=H5_NONE, const int counts=H5_NONE) const =0 |
| Insert or overwrite list of KeyPoint into specified dataset and autoexpand dataset size if unlimited property allows. | |
| virtual void | kpread (vector< KeyPoint > &keypoints, const String &kplabel, const int offset=H5_NONE, const int counts=H5_NONE) const =0 |
| Read specific keypoint dataset from hdf5 file into vector<KeyPoint> object. | |
| virtual void | kpwrite (const vector< KeyPoint > keypoints, const String &kplabel, const int offset=H5_NONE, const int counts=H5_NONE) const =0 |
| Write or overwrite list of KeyPoint into specified dataset of hdf5 file. | |
Hierarchical Data Format version 5 interface.
Notice that this module is compiled only when hdf5 is correctly installed.
| anonymous enum |
| Enumerator | |
|---|---|
| H5_UNLIMITED | The dimension size is unlimited,. |
| H5_NONE | No compression,. |
| H5_GETDIMS | Get the dimension information of a dataset. |
| H5_GETMAXDIMS | Get the maximum dimension information of a dataset. |
| H5_GETCHUNKDIMS | Get the chunk sizes of a dataset. |
| inlinevirtual |
| pure virtual |
Delete an attribute from the root group.
| atlabel | the attribute to be deleted. |
| pure virtual |
Check whether a given attribute exits or not in the root group.
| atlabel | the attribute name to be checked. |
| pure virtual |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
| pure virtual |
Read an attribute from the root group.
| value | address where the attribute is read into |
| atlabel | attribute name |
The following example demonstrates how to read an attribute of type cv::String:
String expected_attr_str;
h5io->atread(&expected_attr_str, attr_str_name);
| pure virtual |
Read an attribute from the root group.
| value | attribute value. Currently, only n-d continuous multi-channel arrays are supported. |
| atlabel | attribute name. |
| pure virtual |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
| pure virtual |
Write an attribute inside the root group.
| value | attribute value. |
| atlabel | attribute name. |
The following example demonstrates how to write an attribute of type cv::String:
String attr_str_name = "string attribute";
String attr_str = "Hello HDF5 from OpenCV!";
if (!h5io->atexists(attr_str_name))
h5io->atwrite(attr_str, attr_str_name);
| pure virtual |
Write an attribute into the root group.
| value | attribute value. Currently, only n-d continuous multi-channel arrays are supported. |
| atlabel | attribute name. |
| pure virtual |
Close and release hdf5 object.
| pure virtual |
| pure virtual |
| pure virtual |
Create and allocate storage for n-dimensional dataset, single or multichannel type.
| n_dims | declare number of dimensions |
| sizes | array containing sizes for each dimensions |
| type | type to be used, e.g., CV_8UC3, CV_32FC1, etc. |
| dslabel | specify the hdf5 dataset label. Existing dataset label will cause an error. |
| compresslevel | specify the compression level 0-9 to be used, H5_NONE is the default value and means no compression. The value 0 also means no compression. A value 9 indicating the best compression ration. Note that a higher compression level indicates a higher computational cost. It relies on GNU gzip for compression. |
| dims_chunks |
| pure virtual |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
| pure virtual |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
| pure virtual |
Create and allocate storage for two dimensional single or multi channel dataset.
| rows | declare amount of rows |
| cols | declare amount of columns |
| type | type to be used, e.g, CV_8UC3, CV_32FC1 and etc. |
| dslabel | specify the hdf5 dataset label. Existing dataset label will cause an error. |
| compresslevel | specify the compression level 0-9 to be used, H5_NONE is the default value and means no compression. The value 0 also means no compression. A value 9 indicating the best compression ration. Note that a higher compression level indicates a higher computational cost. It relies on GNU gzip for compression. |
| dims_chunks |
| pure virtual |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
| pure virtual |
| pure virtual |
Fetch dataset sizes.
| dslabel | specify the hdf5 dataset label to be measured. |
| dims_flag | will fetch dataset dimensions on H5_GETDIMS, dataset maximum dimensions on H5_GETMAXDIMS, and chunk sizes on H5_GETCHUNKDIMS. |
Returns vector object containing sizes of dataset on each dimensions.
| pure virtual |
Fetch dataset type.
| dslabel | specify the hdf5 dataset label to be checked. |
Returns the stored matrix type. This is an identifier compatible with the CvMat type system, like e.g. CV_16SC5 (16-bit signed 5-channel array), and so on.
| pure virtual |
| pure virtual |
| pure virtual |
Insert or overwrite a Mat object into specified dataset and auto expand dataset size if unlimited property allows.
| Array | specify Mat data array to be written. |
| dslabel | specify the target hdf5 dataset label. |
| dims_offset | each array member specify the offset location over dataset's each dimensions from where InputArray will be (over)written into dataset. |
| dims_counts | each array member specify the amount of data over dataset's each dimensions from InputArray that will be written into dataset. |
Writes Mat object into targeted dataset and dataset dimension if allowed.
| pure virtual |
| pure virtual |
| pure virtual |
| pure virtual |
Read specific dataset from hdf5 file into Mat object.
| Array | Mat container where data reads will be returned. |
| dslabel | specify the source hdf5 dataset label. |
| dims_offset | each array member specify the offset location over each dimensions from where dataset starts to read into OutputArray. |
| dims_counts | each array member specify the amount over dataset's each dimensions of dataset to read into OutputArray. |
Reads out Mat object reflecting the stored dataset.
| pure virtual |
| pure virtual |
| pure virtual |
| pure virtual |
Write or overwrite a Mat object into specified dataset of hdf5 file.
| Array | specify Mat data array to be written. |
| dslabel | specify the target hdf5 dataset label. |
| dims_offset | each array member specify the offset location over dataset's each dimensions from where InputArray will be (over)written into dataset. |
| dims_counts | each array member specifies the amount of data over dataset's each dimensions from InputArray that will be written into dataset. |
Writes Mat object into targeted dataset.
| pure virtual |
| pure virtual |
Create a group.
| grlabel | specify the hdf5 group label. |
Create a hdf5 group with default properties. The group is closed automatically after creation.
In this example, Group1 will have one subgroup called SubGroup1:
Ptr<hdf::HDF5> h5io = hdf::open("mytest.h5");
// "/" means the root group, which is always present
if (!h5io->hlexists("/Group1"))
h5io->grcreate("/Group1");
else
std::cout << "/Group1 has already been created, skip it.\n";
// Note that Group1 has been created above, otherwise exception will occur
if (!h5io->hlexists("/Group1/SubGroup1"))
h5io->grcreate("/Group1/SubGroup1");
else
std::cout << "/Group1/SubGroup1 has already been created, skip it.\n";
h5io->close();
| pure virtual |
Check if label exists or not.
| label | specify the hdf5 dataset label. |
Returns true if dataset exists, and false otherwise.
Create and allocate special storage for cv::KeyPoint dataset.
| size | declare fixed number of KeyPoints |
| kplabel | specify the hdf5 dataset label, any existing dataset with the same label will be overwritten. |
| compresslevel | specify the compression level 0-9 to be used, H5_NONE is default and means no compression. |
| chunks | each array member specifies chunking sizes to be used for block I/O, H5_NONE is default and means no compression. |
| pure virtual |
Fetch keypoint dataset size.
| kplabel | specify the hdf5 dataset label to be measured. |
| dims_flag | will fetch dataset dimensions on H5_GETDIMS, and dataset maximum dimensions on H5_GETMAXDIMS. |
Returns size of keypoints dataset.
Insert or overwrite list of KeyPoint into specified dataset and autoexpand dataset size if unlimited property allows.
| keypoints | specify keypoints data list to be written. |
| kplabel | specify the target hdf5 dataset label. |
| offset | specify the offset location on dataset from where keypoints will be (over)written into dataset. |
| counts | specify the amount of keypoints that will be written into dataset. |
Writes vector<KeyPoint> object into targeted dataset and autoexpand dataset dimension if allowed.
Read specific keypoint dataset from hdf5 file into vector<KeyPoint> object.
| keypoints | vector<KeyPoint> container where data reads will be returned. |
| kplabel | specify the source hdf5 dataset label. |
| offset | specify the offset location over dataset from where read starts. |
| counts | specify the amount of keypoints from dataset to read. |
Reads out vector<KeyPoint> object reflecting the stored dataset.
Write or overwrite list of KeyPoint into specified dataset of hdf5 file.
| keypoints | specify keypoints data list to be written. |
| kplabel | specify the target hdf5 dataset label. |
| offset | specify the offset location on dataset from where keypoints will be (over)written into dataset. |
| counts | specify the amount of keypoints that will be written into dataset. |
Writes vector<KeyPoint> object into targeted dataset.
| each array member specifies chunking sizes to be used for block I/O, by default NULL means none at all. |
// open / autocreate hdf5 file
cv::Ptr<cv::hdf::HDF5> h5io = cv::hdf::open( "mytest.h5" );
// create space for 6 dimensional CV_64FC2 matrix
if ( ! h5io->hlexists( "nddata" ) )
int n_dims = 5;
int dsdims[n_dims] = { 100, 100, 20, 10, 5, 5 };
h5io->dscreate( n_dims, sizes, CV_64FC2, "nddata" );
else
printf("DS already created, skipping\n" );
// release
h5io->close();// open / autocreate hdf5 file
cv::Ptr<cv::hdf::HDF5> h5io = cv::hdf::open( "mytest.h5" );
// create space for 6 dimensional CV_64FC2 matrix
if ( ! h5io->hlexists( "nddata" ) )
int n_dims = 5;
int dsdims[n_dims] = { 100, 100, 20, 10, 5, 5 };
int chunks[n_dims] = { 1, 100, 20, 10, 5, 5 };
h5io->dscreate( n_dims, dsdims, CV_64FC2, "nddata", 0, chunks );
else
printf("DS already created, skipping\n" );
// release
h5io->close();// open / autocreate hdf5 file
cv::Ptr<cv::hdf::HDF5> h5io = cv::hdf::open( "mytest.h5" );
int n_dims = 3;
int chunks[n_dims] = { 1, 1, 1 };
int dsdims[n_dims] = { cv::hdf::HDF5::H5_UNLIMITED, cv::hdf::HDF5::H5_UNLIMITED, cv::hdf::HDF5::H5_UNLIMITED };
h5io->dscreate( n_dims, dsdims, CV_64FC2, "nddata", cv::hdf::HDF5::H5_NONE, chunks );
// release
h5io->close();| each array member specifies the chunking size to be used for block I/O, by default NULL means none at all. |
// open / autocreate hdf5 file
cv::Ptr<cv::hdf::HDF5> h5io = cv::hdf::open( "mytest.h5" );
// create space for 100x50 CV_64FC2 matrix
if ( ! h5io->hlexists( "hilbert" ) )
h5io->dscreate( 100, 50, CV_64FC2, "hilbert" );
else
printf("DS already created, skipping\n" );
// release
h5io->close();// open / autocreate hdf5 file
cv::Ptr<cv::hdf::HDF5> h5io = cv::hdf::open( "mytest.h5" );
// create level 9 compressed space for CV_64FC2 matrix
if ( ! h5io->hlexists( "hilbert", 9 ) )
h5io->dscreate( 100, 50, CV_64FC2, "hilbert", 9 );
else
printf("DS already created, skipping\n" );
// release
h5io->close();// open / autocreate hdf5 file
cv::Ptr<cv::hdf::HDF5> h5io = cv::hdf::open( "mytest.h5" );
// create level 9 compressed space for CV_64FC2 matrix
int chunks[2] = { 100, 100 };
h5io->dscreate( 100, cv::hdf::HDF5::H5_UNLIMITED, CV_64FC2, "hilbert", cv::hdf::HDF5::H5_NONE, chunks );
// release
h5io->close();// dual channel hilbert matrix
cv::Mat H(50, 100, CV_64FC2);
for(int i = 0; i < H.rows; i++)
for(int j = 0; j < H.cols; j++)
{
H.at<cv::Vec2d>(i,j)[0] = 1./(i+j+1);
H.at<cv::Vec2d>(i,j)[1] = -1./(i+j+1);
count++;
}
// open / autocreate hdf5 file
cv::Ptr<cv::hdf::HDF5> h5io = cv::hdf::open( "mytest.h5" );
// optimise dataset by chunks
int chunks[2] = { 100, 100 };
// create Unlimited x 100 CV_64FC2 space
h5io->dscreate( cv::hdf::HDF5::H5_UNLIMITED, 100, CV_64FC2, "hilbert", cv::hdf::HDF5::H5_NONE, chunks );
// write into first half
int offset[2] = { 0, 0 };
for ( int t = 0; t < 5; t++ )
{
offset[0] += 100 * t;
h5io->dsinsert( H, "hilbert", offset );
}
// release
h5io->close();// open hdf5 file
cv::Ptr<cv::hdf::HDF5> h5io = cv::hdf::open( "mytest.h5" );
// blank Mat container
cv::Mat H;
// read hibert dataset
h5io->read( H, "hilbert" );
// release
h5io->close();// open hdf5 file
cv::Ptr<cv::hdf::HDF5> h5io = cv::hdf::open( "mytest.h5" );
// blank Mat container
cv::Mat H;
int offset[2] = { 1, 2 };
int counts[2] = { 3, 5 };
// read hibert dataset
h5io->read( H, "hilbert", offset, counts );
// release
h5io->close();// dual channel hilbert matrix
cv::Mat H(100, 100, CV_64FC2);
for(int i = 0; i < H.rows; i++)
for(int j = 0; j < H.cols; j++)
{
H.at<cv::Vec2d>(i,j)[0] = 1./(i+j+1);
H.at<cv::Vec2d>(i,j)[1] = -1./(i+j+1);
count++;
}
// open / autocreate hdf5 file
cv::Ptr<cv::hdf::HDF5> h5io = cv::hdf::open( "mytest.h5" );
// write / overwrite dataset
h5io->dswrite( H, "hilbert" );
// release
h5io->close();// dual channel hilbert matrix
cv::Mat H(50, 100, CV_64FC2);
for(int i = 0; i < H.rows; i++)
for(int j = 0; j < H.cols; j++)
{
H.at<cv::Vec2d>(i,j)[0] = 1./(i+j+1);
H.at<cv::Vec2d>(i,j)[1] = -1./(i+j+1);
count++;
}
::<::::> = ::::( );
[] = { , };
->( , , , , , );
[] = { , };
->( , , );
[] = { , };
->( , , );
->();The corresponding result visualized using the HDFView tool is
// open hdf5 file
cv::Ptr<cv::hdf::HDF5> h5io = cv::hdf::open( "mytest.h5" );
if ( ! h5io->hlexists( "keypoints" ) )
h5io->kpcreate( 100, "keypoints" );
else
printf("DS already created, skipping\n" );// open hdf5 file
cv::Ptr<cv::hdf::HDF5> h5io = cv::hdf::open( "mytest.h5" );
if ( ! h5io->hlexists( "keypoints" ) )
h5io->kpcreate( cv::hdf::HDF5::H5_UNLIMITED, "keypoints", cv::hdf::HDF5::H5_NONE, 100 );
else
printf("DS already created, skipping\n" );// generate 10 dummy keypoints
std::vector<cv::KeyPoint> keypoints;
for(int i = 0; i < 10; i++)
keypoints.push_back( cv::KeyPoint(i, -i, 1, -1, 0, 0, -1) );
// open / autocreate hdf5 file
cv::Ptr<cv::hdf::HDF5> h5io = cv::hdf::open( "mytest.h5" );
// create unlimited size space with chunk size of 10
h5io->kpcreate( cv::hdf::HDF5::H5_UNLIMITED, "keypoints", -1, 10 );
// insert 10 times same 10 keypoints
for(int i = 0; i < 10; i++)
h5io->kpinsert( keypoints, "keypoints", i * 10 );
// release
h5io->close();// open hdf5 file
cv::Ptr<cv::hdf::HDF5> h5io = cv::hdf::open( "mytest.h5" );
// blank KeyPoint container
std::vector<cv::KeyPoint> keypoints;
// read keypoints starting second one
h5io->kpread( keypoints, "keypoints", 1 );
// release
h5io->close();// open hdf5 file
cv::Ptr<cv::hdf::HDF5> h5io = cv::hdf::open( "mytest.h5" );
// blank KeyPoint container
std::vector<cv::KeyPoint> keypoints;
// read three keypoints starting second one
h5io->kpread( keypoints, "keypoints", 1, 3 );
// release
h5io->close();// generate 100 dummy keypoints
std::vector<cv::KeyPoint> keypoints;
for(int i = 0; i < 100; i++)
keypoints.push_back( cv::KeyPoint(i, -i, 1, -1, 0, 0, -1) );
// open / autocreate hdf5 file
cv::Ptr<cv::hdf::HDF5> h5io = cv::hdf::open( "mytest.h5" );
// write / overwrite dataset
h5io->kpwrite( keypoints, "keypoints" );
// release
h5io->close();// generate 50 dummy keypoints
std::vector<cv::KeyPoint> keypoints;
for(int i = 0; i < 50; i++)
keypoints.push_back( cv::KeyPoint(i, -i, 1, -1, 0, 0, -1) );
// open / autocreate hdf5 file
cv::Ptr<cv::hdf::HDF5> h5io = cv::hdf::open( "mytest.h5" );
// create maximum compressed space of size 100 with chunk size 10
h5io->kpcreate( 100, , , );
->( , , );
->( , , , );
->( , , , );
->();