OpenCV 4.12.0
開源計算機視覺
載入中...
搜尋中...
無匹配項

分層資料格式版本 5 介面。 更多...

#include <opencv2/hdf/hdf5.hpp>

cv::hdf::HDF5 的協作圖

公共型別

列舉  {
  H5_UNLIMITED = -1 ,
  H5_NONE = -1 ,
  H5_GETDIMS = 100 ,
  H5_GETMAXDIMS = 101 ,
  H5_GETCHUNKDIMS = 102
}
 

公共成員函式

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
 關閉並釋放 hdf5 物件。
 
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
 為 n 維資料集建立並分配儲存空間,單通道或多通道型別。
 
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
 為二維單通道或多通道資料集建立並分配儲存空間。
 
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
 獲取資料集大小。
 
virtual int dsgettype (const String &dslabel) const =0
 獲取資料集型別。
 
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
 Mat 物件插入或覆蓋到指定資料集,如果無限制屬性允許則自動擴充套件資料集大小。
 
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
 從 hdf5 檔案讀取指定資料集到 Mat 物件。
 
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
 Mat 物件寫入或覆蓋到 hdf5 檔案的指定資料集。
 
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
 建立一個組。
 
virtual bool hlexists (const String &label) const =0
 檢查標籤是否存在。
 
virtual void kpcreate (const int size, const String &kplabel, const int compresslevel=H5_NONE, const int chunks=H5_NONE) const =0
 cv::KeyPoint 資料集建立並分配特殊儲存空間。
 
virtual int kpgetsize (const String &kplabel, int dims_flag=HDF5::H5_GETDIMS) const =0
 獲取關鍵點資料集大小。
 
virtual void kpinsert (const vector< KeyPoint > keypoints, const String &kplabel, const int offset=H5_NONE, const int counts=H5_NONE) const =0
 KeyPoint 列表插入或覆蓋到指定資料集,如果無限制屬性允許則自動擴充套件資料集大小。
 
virtual void kpread (vector< KeyPoint > &keypoints, const String &kplabel, const int offset=H5_NONE, const int counts=H5_NONE) const =0
 從 hdf5 檔案讀取指定關鍵點資料集到 vector<KeyPoint> 物件。
 
virtual void kpwrite (const vector< KeyPoint > keypoints, const String &kplabel, const int offset=H5_NONE, const int counts=H5_NONE) const =0
 KeyPoint 列表寫入或覆蓋到 hdf5 檔案的指定資料集。
 

詳細描述

分層資料格式版本 5 介面。

請注意,此模組僅在 hdf5 正確安裝時才編譯。

成員列舉文件

◆ 匿名列舉

匿名列舉
列舉器
H5_UNLIMITED 

維度大小是無限制的。

另請參見
dscreate()
H5_NONE 

無壓縮。

另請參見
dscreate()
H5_GETDIMS 

獲取資料集的維度資訊。

另請參見
dsgetsize()
H5_GETMAXDIMS 

獲取資料集的最大維度資訊。

另請參見
dsgetsize()
H5_GETCHUNKDIMS 

獲取資料集的塊大小。

另請參見
dsgetsize()

建構函式 & 解構函式文件

◆ ~HDF5()

virtual cv::hdf::HDF5::~HDF5 ( )
內聯虛擬函式

成員函式文件

◆ atdelete()

virtual void cv::hdf::HDF5::atdelete ( const String & atlabel)
純虛擬函式

從根組中刪除一個屬性。

引數
atlabel要刪除的屬性。
注意
如果給定的屬性不存在,則會呼叫 CV_Error()。請事先使用 atexists() 檢查它是否存在。
另請參見
atexists, atwrite, atread

◆ atexists()

virtual bool cv::hdf::HDF5::atexists ( const String & atlabel) const
純虛擬函式

檢查根組中給定的屬性是否存在。

引數
atlabel要檢查的屬性名稱。
返回
如果屬性存在則為 true,否則為 false。
另請參見
atdelete, atwrite, atread

◆ atread() [1/4]

virtual void cv::hdf::HDF5::atread ( 如果傳入NULL,則假定尺度引數c為1.0。否則,指向的變數將被設定為最優尺度。 ,
const String & atlabel )
純虛擬函式

這是一個過載的成員函式,為方便起見提供。它與上面的函式僅在接受的引數上不同。

◆ atread() [2/4]

virtual void cv::hdf::HDF5::atread ( int * ,
const String & atlabel )
純虛擬函式

從根組讀取一個屬性。

引數
讀取屬性的地址。
atlabel屬性名稱。

以下示例演示如何讀取 cv::String 型別的屬性

String expected_attr_str;
h5io->atread(&expected_attr_str, attr_str_name);
注意
屬性必須存在,否則將呼叫 CV_Error()。請事先使用 atexists() 檢查它是否存在。
另請參見
atexists, atdelete, atwrite

◆ atread() [3/4]

virtual void cv::hdf::HDF5::atread ( OutputArray ,
const String & atlabel )
純虛擬函式

從根組讀取一個屬性。

引數
屬性值。目前,僅支援 N 維連續多通道陣列。
atlabel屬性名稱。
注意
屬性必須存在,否則將呼叫 CV_Error()。請事先使用 atexists() 檢查它是否存在。
另請參見
atexists, atdelete, atwrite

◆ atread() [4/4]

virtual void cv::hdf::HDF5::atread ( String * ,
const String & atlabel )
純虛擬函式

這是一個過載的成員函式,為方便起見提供。它與上面的函式僅在接受的引數上不同。

◆ atwrite() [1/4]

virtual void cv::hdf::HDF5::atwrite ( const double ,
const String & atlabel )
純虛擬函式

這是一個過載的成員函式,為方便起見提供。它與上面的函式僅在接受的引數上不同。

◆ atwrite() [2/4]

virtual void cv::hdf::HDF5::atwrite ( const int ,
const String & atlabel )
純虛擬函式

在根組中寫入一個屬性。

引數
屬性值。
atlabel屬性名稱。

以下示例演示如何寫入 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);
注意
如果給定的屬性已存在,則會呼叫 CV_Error()。請事先使用 atexists() 檢查它是否存在。如果它已經存在,則使用 atdelete() 將其刪除。
另請參見
atexists, atdelete, atread

◆ atwrite() [3/4]

virtual void cv::hdf::HDF5::atwrite ( const String & ,
const String & atlabel )
純虛擬函式

這是一個過載的成員函式,為方便起見提供。它與上面的函式僅在接受的引數上不同。

◆ atwrite() [4/4]

virtual void cv::hdf::HDF5::atwrite ( InputArray ,
const String & atlabel )
純虛擬函式

將屬性寫入根組。

引數
屬性值。目前,僅支援 N 維連續多通道陣列。
atlabel屬性名稱。
注意
如果給定的屬性已存在,則會呼叫 CV_Error()。請事先使用 atexists() 檢查它是否存在。如果它已經存在,則使用 atdelete() 將其刪除。
另請參見
atexists, atdelete, atread

◆ close()

virtual void cv::hdf::HDF5::close ( )
純虛擬函式

關閉並釋放 hdf5 物件。

◆ dscreate() [1/8]

virtual void cv::hdf::HDF5::dscreate ( const int n_dims,
const int * sizes,
const int type,
const String & dslabel ) const
純虛擬函式

◆ dscreate() [2/8]

virtual void cv::hdf::HDF5::dscreate ( const int n_dims,
const int * sizes,
const int type,
const String & dslabel,
const int compresslevel ) const
純虛擬函式

◆ dscreate() [3/8]

virtual void cv::hdf::HDF5::dscreate ( const int n_dims,
const int * sizes,
const int type,
const String & dslabel,
const int compresslevel,
const int * dims_chunks ) const
純虛擬函式

為 n 維資料集建立並分配儲存空間,單通道或多通道型別。

引數
n_dims宣告維度數量
sizes包含每個維度大小的陣列
type要使用的型別,例如 CV_8UC3, CV_32FC1 等。
dslabel指定 hdf5 資料集標籤。如果資料集標籤已存在將導致錯誤。
compresslevel指定要使用的壓縮級別 0-9,H5_NONE 是預設值,表示不壓縮。值 0 也表示不壓縮。值 9 表示最佳壓縮比。請注意,更高的壓縮級別意味著更高的計算成本。它依賴 GNU gzip 進行壓縮。
dims_chunks每個陣列成員指定用於塊 I/O 的分塊大小,預設 NULL 表示完全沒有。
注意
如果資料集已存在,將丟擲異常。可以使用 hlexists() 檢查資料集是否存在。
  • 請看下面的示例,它建立了一個 6 維儲存空間
    // 開啟/自動建立 hdf5 檔案
    cv::Ptr<cv::hdf::HDF5> h5io = cv::hdf::open( "mytest.h5" );
    // 為 6 維 CV_64FC2 矩陣建立空間
    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 已經建立,跳過\n" );
    // 釋放
    h5io->close();
    std::shared_ptr< _Tp > Ptr
    Definition cvstd_wrapper.hpp:23
    CV_64FC2
    #define CV_64FC2
    Ptr< HDF5 > open(const String &HDF5Filename)
    開啟或建立 hdf5 檔案。
注意
啟用壓縮需要內部分塊。分塊可以顯著提高讀寫訪問速度,特別是對於在資料集內部偏移的視窗訪問邏輯。如果沒有指定自定義分塊,則預設的分塊將資料集整體作為一個大的資料塊來呼叫。
  • 請看級別 0 壓縮(淺層)使用第一維度分塊的示例,這樣儲存將由 100 個數據塊組成
    // 開啟/自動建立 hdf5 檔案
    cv::Ptr<cv::hdf::HDF5> h5io = cv::hdf::open( "mytest.h5" );
    // 為 6 維 CV_64FC2 矩陣建立空間
    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 已經建立,跳過\n" );
    // 釋放
    h5io->close();
注意
sizes 陣列中使用 H5_UNLIMITED 值表示該維度的資料是無限制的,因此可以在這些無限制方向上隨時擴充套件此類資料集。任何維度上存在 H5_UNLIMITED 都要求定義自定義分塊。在無限制場景中不會定義預設分塊,因為該維度上的預設大小將為零,並且在寫入資料集後會增長。寫入具有 H5_UNLIMITED 的資料集需要 dsinsert() 而不是 dswrite(),因為它允許在無限制維度上增長,而 dswrite() 僅允許在預定義的資料空間中寫入。

◆ dscreate() [4/8]

virtual void cv::hdf::HDF5::dscreate ( const int rows,
const int cols,
const int type,
const String & dslabel ) const
純虛擬函式

這是一個過載的成員函式,為方便起見提供。它與上面的函式僅在接受的引數上不同。

◆ dscreate() [5/8]

virtual void cv::hdf::HDF5::dscreate ( const int rows,
const int cols,
const int type,
const String & dslabel,
const int compresslevel ) const
純虛擬函式

這是一個過載的成員函式,為方便起見提供。它與上面的函式僅在接受的引數上不同。

◆ dscreate() [6/8]

virtual void cv::hdf::HDF5::dscreate ( const int rows,
const int cols,
const int type,
const String & dslabel,
const int compresslevel,
const int * dims_chunks ) const
純虛擬函式

為二維單通道或多通道資料集建立並分配儲存空間。

引數
rows宣告行數
cols宣告列數
type要使用的型別,例如 CV_8UC3、CV_32FC1 等。
dslabel指定 hdf5 資料集標籤。如果資料集標籤已存在將導致錯誤。
compresslevel指定要使用的壓縮級別 0-9,H5_NONE 是預設值,表示不壓縮。值 0 也表示不壓縮。值 9 表示最佳壓縮比。請注意,更高的壓縮級別意味著更高的計算成本。它依賴 GNU gzip 進行壓縮。
dims_chunks每個陣列成員指定用於塊 I/O 的分塊大小,預設 NULL 表示完全沒有。
注意
如果資料集已存在,將丟擲異常(呼叫 CV_Error())。
  • 可以使用 hlexists() 檢查資料集是否存在,示例如下
    // 開啟/自動建立 hdf5 檔案
    cv::Ptr<cv::hdf::HDF5> h5io = cv::hdf::open( "mytest.h5" );
    // 為 100x50 CV_64FC2 矩陣建立空間
    if ( ! h5io->hlexists( "hilbert" ) )
    h5io->dscreate( 100, 50, CV_64FC2, "hilbert" );
    else
    printf("DS 已經建立,跳過\n" );
    // 釋放
    h5io->close();
注意
啟用壓縮需要內部分塊。分塊可以顯著提高讀寫訪問速度,特別是對於在資料集內部偏移的視窗訪問邏輯。如果沒有指定自定義分塊,則預設的分塊將資料集整體作為一個大的資料塊來呼叫。
  • 請看級別 9 壓縮使用內部預設分塊的示例
    // 開啟/自動建立 hdf5 檔案
    cv::Ptr<cv::hdf::HDF5> h5io = cv::hdf::open( "mytest.h5" );
    // 為 CV_64FC2 矩陣建立級別 9 壓縮空間
    if ( ! h5io->hlexists( "hilbert", 9 ) )
    h5io->dscreate( 100, 50, CV_64FC2, "hilbert", 9 );
    else
    printf("DS 已經建立,跳過\n" );
    // 釋放
    h5io->close();
注意
rowscols 或兩者都使用 H5_UNLIMITED 值表示指定維度上的資料是無限制的,因此可以隨時在行、列或兩個方向上擴充套件此類資料集。任何維度上存在 H5_UNLIMITED 都要求定義自定義分塊。在無限制場景中不會定義預設分塊,因為該維度上的預設大小將為零,並且在寫入資料集後會增長。寫入具有 H5_UNLIMITED 的資料集需要 dsinsert(),它允許在無限制維度上增長,而不是 dswrite(),它僅允許在預定義的資料空間中寫入。
注意
不是執行緒安全的,必須在資料集建立時只調用一次,否則會發生異常。單個 hdf5 檔案中允許多個數據集。

◆ dscreate() [7/8]

virtual void cv::hdf::HDF5::dscreate ( const int rows,
const int cols,
const int type,
const String & dslabel,
const int compresslevel,
const vector< int > & dims_chunks ) const
純虛擬函式

這是一個過載的成員函式,為方便起見提供。它與上面的函式僅在接受的引數上不同。

◆ dscreate() [8/8]

virtual void cv::hdf::HDF5::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
純虛擬函式

◆ dsgetsize()

virtual vector< int > cv::hdf::HDF5::dsgetsize ( const String & dslabel,
int dims_flag = HDF5::H5_GETDIMS ) const
純虛擬函式

獲取資料集大小。

引數
dslabel指定要測量尺寸的 hdf5 資料集標籤。
dims_flag將獲取資料集在 H5_GETDIMS 上的維度,在 H5_GETMAXDIMS 上的資料集最大維度,以及在 H5_GETCHUNKDIMS 上的分塊大小。

返回包含資料集在每個維度上的大小的向量物件。

注意
結果向量大小將與資料集的維度數量匹配。預設情況下,H5_GETDIMS 將返回實際資料集維度。使用 H5_GETMAXDIM 標誌將獲取最大允許維度,該維度通常與實際資料集維度匹配,但如果資料集在某些維度上以無限制模式準備,則可以包含 H5_UNLIMITED 值。在完全或部分覆蓋現有資料集之前檢查其維度可能很有用。嘗試用過大的源資料寫入資料集目標將丟擲異常。H5_GETCHUNKDIMS 將返回分塊的維度(如果資料集是使用分塊選項建立的),否則返回的向量大小將為零。

◆ dsgettype()

virtual int cv::hdf::HDF5::dsgettype ( const String & dslabel) const
純虛擬函式

獲取資料集型別。

引數
dslabel指定要檢查的 hdf5 資料集標籤。

返回儲存的矩陣型別。這是一個與 CvMat 型別系統相容的識別符號,例如 CV_16SC5(16 位有符號 5 通道陣列)等。

注意
結果可以透過 CV_MAT_CN() 解析以獲取通道數量,並透過 CV_MAT_DEPTH() 解析以獲取原生 cvdata 型別。它是執行緒安全的。

◆ dsinsert() [1/4]

virtual void cv::hdf::HDF5::dsinsert ( InputArray Array,
const String & dslabel ) const
純虛擬函式

◆ dsinsert() [2/4]

virtual void cv::hdf::HDF5::dsinsert ( InputArray Array,
const String & dslabel,
const int * dims_offset ) const
純虛擬函式

◆ dsinsert() [3/4]

virtual void cv::hdf::HDF5::dsinsert ( InputArray Array,
const String & dslabel,
const int * dims_offset,
const int * dims_counts ) const
純虛擬函式

Mat 物件插入或覆蓋到指定資料集,如果無限制屬性允許則自動擴充套件資料集大小。

引數
Array指定要寫入的 Mat 資料陣列。
dslabel指定目標 hdf5 資料集標籤。
dims_offset每個陣列成員指定資料集的每個維度上的偏移位置,InputArray 將從該位置寫入(覆蓋)到資料集中。
dims_counts每個陣列成員指定 InputArray 在資料集的每個維度上將寫入資料集的資料量。

Mat 物件寫入目標資料集並自動擴充套件資料集維度(如果允許)。

注意
dswrite() 不同,資料集不會自動建立。只支援 Mat 並且它必須是連續的。如果 dsinsert() 發生在資料集維度的外部區域並且資料集在該維度上處於無限制模式,則資料集會擴充套件,否則會丟擲異常。要建立在特定或更多維度上具有無限制屬性的資料集,請參閱 dscreate() 和建立時的可選 H5_UNLIMITED 標誌。它在同一個資料集上不是執行緒安全的,但多個數據集可以合併到單個 hdf5 檔案中。
  • 下面的示例建立了無限制行 x 100 列,並使用單個 100x100 CV_64FC2 在資料集上透過 dsinsert() 擴充套件行 5 次。最終大小將有 5x100 行和 100 列,反映 H 矩陣在行跨度上的五倍。分塊大小為 100x100,僅針對停用壓縮的 H 矩陣大小進行了最佳化。如果例程被多次呼叫,資料集將被覆蓋。
    // 雙通道希爾伯特矩陣
    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++;
    }
    // 開啟/自動建立 hdf5 檔案
    cv::Ptr<cv::hdf::HDF5> h5io = cv::hdf::open( "mytest.h5" );
    // 按塊最佳化資料集
    int chunks[2] = { 100, 100 };
    // 建立無限制 x 100 CV_64FC2 空間
    h5io->dscreate( cv::hdf::HDF5::H5_UNLIMITED, 100, CV_64FC2, "hilbert", cv::hdf::HDF5::H5_NONE, chunks );
    // 寫入前半部分
    int offset[2] = { 0, 0 };
    for ( int t = 0; t < 5; t++ )
    {
    offset[0] += 100 * t;
    h5io->dsinsert( H, "hilbert", offset );
    }
    // 釋放
    h5io->close();
    n 維密集陣列類
    定義 mat.hpp:830

◆ dsinsert() [4/4]

virtual void cv::hdf::HDF5::dsinsert ( InputArray Array,
const String & dslabel,
const vector< int > & dims_offset,
const vector< int > & dims_counts = vector< int >() ) const
純虛擬函式

◆ dsread() [1/4]

virtual void cv::hdf::HDF5::dsread ( OutputArray Array,
const String & dslabel ) const
純虛擬函式

◆ dsread() [2/4]

virtual void cv::hdf::HDF5::dsread ( OutputArray Array,
const String & dslabel,
const int * dims_offset ) const
純虛擬函式

◆ dsread() [3/4]

virtual void cv::hdf::HDF5::dsread ( OutputArray Array,
const String & dslabel,
const int * dims_offset,
const int * dims_counts ) const
純虛擬函式

從 hdf5 檔案讀取指定資料集到 Mat 物件。

引數
ArrayMat 容器,資料讀取結果將返回到其中。
dslabel指定源 hdf5 資料集標籤。
dims_offset每個陣列成員指定資料集的每個維度上的偏移位置,從該位置開始讀取到 OutputArray 中。
dims_counts每個陣列成員指定資料集的每個維度上要讀取到 OutputArray 中的資料量。

讀出反映儲存資料集的 Mat 物件。

注意
如果 hdf5 檔案不存在,將丟擲異常。使用 hlexists() 檢查資料集是否存在。它是執行緒安全的。
  • 下面的示例讀取一個數據集
    // 開啟 hdf5 檔案
    cv::Ptr<cv::hdf::HDF5> h5io = cv::hdf::open( "mytest.h5" );
    // 空的 Mat 容器
    // 讀取 hibert 資料集
    h5io->read( H, "hilbert" );
    // 釋放
    h5io->close();
  • 下面的示例從第二行和第三個元素開始讀取 3x5 子矩陣。
    // 開啟 hdf5 檔案
    cv::Ptr<cv::hdf::HDF5> h5io = cv::hdf::open( "mytest.h5" );
    // 空的 Mat 容器
    int offset[2] = { 1, 2 };
    int counts[2] = { 3, 5 };
    // 讀取 hibert 資料集
    h5io->read( H, "hilbert", offset, counts );
    // 釋放
    h5io->close();

◆ dsread() [4/4]

virtual void cv::hdf::HDF5::dsread ( OutputArray Array,
const String & dslabel,
const vector< int > & dims_offset,
const vector< int > & dims_counts = vector< int >() ) const
純虛擬函式

◆ dswrite() [1/4]

virtual void cv::hdf::HDF5::dswrite ( InputArray Array,
const String & dslabel ) const
純虛擬函式

◆ dswrite() [2/4]

virtual void cv::hdf::HDF5::dswrite ( InputArray Array,
const String & dslabel,
const int * dims_offset ) const
純虛擬函式

◆ dswrite() [3/4]

virtual void cv::hdf::HDF5::dswrite ( InputArray Array,
const String & dslabel,
const int * dims_offset,
const int * dims_counts ) const
純虛擬函式

Mat 物件寫入或覆蓋到 hdf5 檔案的指定資料集。

引數
Array指定要寫入的 Mat 資料陣列。
dslabel指定目標 hdf5 資料集標籤。
dims_offset每個陣列成員指定資料集的每個維度上的偏移位置,InputArray 將從該位置寫入(覆蓋)到資料集中。
dims_counts每個陣列成員指定 InputArray 在資料集的每個維度上將寫入資料集的資料量。

Mat 物件寫入目標資料集。

注意
如果資料集未建立且不存在,則將自動建立。只支援 Mat 並且它必須是連續的。它是執行緒安全的,但建議寫入操作發生在不重疊的獨立區域。多個數據集可以寫入單個 hdf5 檔案中。
  • 下面的示例將一個 100x100 CV_64FC2 矩陣寫入資料集。不需要預先建立資料集。如果例程被多次呼叫,資料集將被覆蓋。
    // 雙通道希爾伯特矩陣
    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++;
    }
    // 開啟/自動建立 hdf5 檔案
    cv::Ptr<cv::hdf::HDF5> h5io = cv::hdf::open( "mytest.h5" );
    // 寫入/覆蓋資料集
    h5io->dswrite( H, "hilbert" );
    // 釋放
    h5io->close();
  • 下面的示例將一個較小的 50x100 矩陣寫入 100x100 壓縮空間,該空間由兩個 50x100 的塊最佳化。矩陣使用偏移量寫入資料空間的前半部分 (0->50) 和後半部分 (50->100) 兩次。如果例程被多次呼叫,資料集將被覆蓋。
    // 雙通道希爾伯特矩陣
    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++;
    }
    // 開啟/自動建立 hdf5 檔案
    cv::Ptr<cv::hdf::HDF5> h5io = cv::hdf::open( "mytest.h5" );
    // 透過兩個塊最佳化資料集
    int chunks[2] = { 50, 100 };
    // 建立 100x100 CV_64FC2 壓縮空間
    h5io->dscreate( 100, 100, CV_64FC2, "hilbert", 9, chunks );
    // 寫入前半部分
    int offset1[2] = { 0, 0 };
    h5io->dswrite( H, "hilbert", offset1 );
    // 寫入後半部分
    int offset2[2] = { 50, 0 };
    h5io->dswrite( H, "hilbert", offset2 );
    // 釋放
    h5io->close();

◆ dswrite() [4/4]

virtual void cv::hdf::HDF5::dswrite ( InputArray Array,
const String & dslabel,
const vector< int > & dims_offset,
const vector< int > & dims_counts = vector< int >() ) const
純虛擬函式

◆ grcreate()

virtual void cv::hdf::HDF5::grcreate ( const String & grlabel)
純虛擬函式

建立一個組。

引數
grlabel指定 hdf5 組標籤。

建立具有預設屬性的 hdf5 組。組在建立後自動關閉。

注意
組對於更好地組織多個數據集很有用。可以在任何組中建立子組。可以使用 hlexists() 檢查特定組是否存在。對於子組,標籤將是例如:“Group1/SubGroup1”,其中 SubGroup1 在根組 Group1 內部。在建立子組之前,必須建立其父組。
  • 在此示例中,Group1 將有一個名為 SubGroup1 的子組

    Ptr<hdf::HDF5> h5io = hdf::open("mytest.h5");
    // "/" 表示根組,它始終存在
    if (!h5io->hlexists("/Group1"))
    h5io->grcreate("/Group1");
    else
    std::cout << "/Group1 已經建立,跳過。\n";
    // 請注意,Group1 已在上面建立,否則會發生異常
    if (!h5io->hlexists("/Group1/SubGroup1"))
    h5io->grcreate("/Group1/SubGroup1");
    else
    std::cout << "/Group1/SubGroup1 已經建立,跳過。\n";
    h5io->close();

    使用 HDFView 工具視覺化的相應結果是

使用 HDFView 工具視覺化組
注意
當使用 dscreate()kpcreate() 建立資料集時,可以透過在標籤中指定完整路徑在組內建立它。在我們的示例中,它將是:“Group1/SubGroup1/MyDataSet”。它不是執行緒安全的。

◆ hlexists()

virtual bool cv::hdf::HDF5::hlexists ( const String & label) const
純虛擬函式

檢查標籤是否存在。

引數
label指定 hdf5 資料集標籤。

如果資料集存在,返回true,否則返回false

注意
檢查資料集、組或其他物件型別(hdf5 連結)是否存在於標籤名稱下。它是執行緒安全的。

◆ kpcreate()

virtual void cv::hdf::HDF5::kpcreate ( const int size,
const String & kplabel,
const int compresslevel = H5_NONE,
const int chunks = H5_NONE ) const
純虛擬函式

cv::KeyPoint 資料集建立並分配特殊儲存空間。

引數
size宣告固定數量的關鍵點
kplabel指定 hdf5 資料集標籤,任何具有相同標籤的現有資料集都將被覆蓋。
compresslevel指定要使用的壓縮級別 0-9,H5_NONE 是預設值,表示不壓縮。
chunks每個陣列成員指定用於塊 I/O 的分塊大小,H5_NONE 是預設值,表示不壓縮。
注意
如果資料集已存在,將丟擲異常。可以使用 hlexists() 檢查資料集是否存在。
  • 請看下面的示例,它在資料集中為 100 個關鍵點建立空間
    // 開啟 hdf5 檔案
    cv::Ptr<cv::hdf::HDF5> h5io = cv::hdf::open( "mytest.h5" );
    if ( ! h5io->hlexists( "keypoints" ) )
    h5io->kpcreate( 100, "keypoints" );
    else
    printf("DS 已經建立,跳過\n" );
注意
size 引數的 H5_UNLIMITED 值表示無限制的關鍵點數量,因此可以透過新增或插入隨時擴充套件此類資料集。H5_UNLIMITED 的存在要求定義自定義分塊。在無限制場景中不會定義預設分塊,因為該維度上的預設大小將為零,並且在寫入資料集後會增長。寫入具有 H5_UNLIMITED 的資料集需要 kpinsert(),它允許在無限制維度上增長,而不是 kpwrite(),它僅允許在預定義資料空間中寫入。

◆ kpgetsize()

virtual int cv::hdf::HDF5::kpgetsize ( const String & kplabel,
int dims_flag = HDF5::H5_GETDIMS ) const
純虛擬函式

獲取關鍵點資料集大小。

引數
kplabel指定要測量尺寸的 hdf5 資料集標籤。
dims_flag將獲取資料集在 H5_GETDIMS 上的維度,以及在 H5_GETMAXDIMS 上的資料集最大維度。

返回關鍵點資料集的大小。

注意
結果大小將與關鍵點數量匹配。預設情況下,H5_GETDIMS 將返回實際資料集維度。使用 H5_GETMAXDIM 標誌將獲取最大允許維度,該維度通常與實際資料集維度匹配,但如果資料集以無限制模式準備,則可以包含 H5_UNLIMITED 值。在完全或部分覆蓋現有資料集之前檢查其維度可能很有用。嘗試用過大的源資料寫入資料集目標將丟擲異常。H5_GETCHUNKDIMS 將返回分塊的維度(如果資料集是使用分塊選項建立的),否則返回的向量大小將為零。

◆ kpinsert()

virtual void cv::hdf::HDF5::kpinsert ( const vector< KeyPoint > keypoints,
const String & kplabel,
const int offset = H5_NONE,
const int counts = H5_NONE ) const
純虛擬函式

KeyPoint 列表插入或覆蓋到指定資料集,如果無限制屬性允許則自動擴充套件資料集大小。

引數
keypoints指定要寫入的關鍵點資料列表。
kplabel指定目標 hdf5 資料集標籤。
offset指定資料集上偏移位置,關鍵點將從該位置寫入(覆蓋)到資料集中。
counts指定將寫入資料集的關鍵點數量。

將 vector<KeyPoint> 物件寫入目標資料集並自動擴充套件資料集維度(如果允許)。

注意
kpwrite() 不同,資料集不會自動建立。如果 dsinsert() 發生在資料集的外部區域,並且資料集已以無限制模式建立,則資料集會擴充套件,否則將丟擲異常。要建立具有無限制屬性的資料集,請參閱 kpcreate() 和建立時可選的 H5_UNLIMITED 標誌。它在同一資料集上不是執行緒安全的,但多個數據集可以合併到單個 hdf5 檔案中。
  • 下面的示例建立了用於關鍵點儲存的無限制空間,並將 10 個關鍵點列表插入該空間十次。最終資料集將包含 100 個關鍵點。分塊大小為 10,僅針對關鍵點列表進行了最佳化。如果例程被多次呼叫,資料集將被覆蓋。
    // 生成 10 個虛擬關鍵點
    std::vector<cv::KeyPoint> keypoints;
    for(int i = 0; i < 10; i++)
    keypoints.push_back( cv::KeyPoint(i, -i, 1, -1, 0, 0, -1) );
    // 開啟/自動建立 hdf5 檔案
    cv::Ptr<cv::hdf::HDF5> h5io = cv::hdf::open( "mytest.h5" );
    // 建立無限制大小空間,分塊大小為 10
    h5io->kpcreate( cv::hdf::HDF5::H5_UNLIMITED, "keypoints", -1, 10 );
    // 插入 10 次相同的 10 個關鍵點
    for(int i = 0; i < 10; i++)
    h5io->kpinsert( keypoints, "keypoints", i * 10 );
    // 釋放
    h5io->close();
    用於顯著點檢測器的資料結構。
    定義於 types.hpp:752

◆ kpread()

virtual void cv::hdf::HDF5::kpread ( vector< KeyPoint > & keypoints,
const String & kplabel,
const int offset = H5_NONE,
const int counts = H5_NONE ) const
純虛擬函式

從 hdf5 檔案讀取指定關鍵點資料集到 vector<KeyPoint> 物件。

引數
keypointsvector<KeyPoint> 容器,資料讀取結果將返回到其中。
kplabel指定源 hdf5 資料集標籤。
offset指定資料集上讀取開始的偏移位置。
counts指定從資料集中讀取的關鍵點數量。

讀出反映儲存資料集的 vector<KeyPoint> 物件。

注意
如果 hdf5 檔案不存在,將丟擲異常。使用 hlexists() 檢查資料集是否存在。它是執行緒安全的。
  • 下面的示例讀取一個包含關鍵點的資料集,從第二個條目開始
    // 開啟 hdf5 檔案
    cv::Ptr<cv::hdf::HDF5> h5io = cv::hdf::open( "mytest.h5" );
    // 空的關鍵點容器
    std::vector<cv::KeyPoint> keypoints;
    // 從第二個關鍵點開始讀取
    h5io->kpread( keypoints, "keypoints", 1 );
    // 釋放
    h5io->close();
  • 下面的示例從第二個條目開始讀取 3 個關鍵點。
    // 開啟 hdf5 檔案
    cv::Ptr<cv::hdf::HDF5> h5io = cv::hdf::open( "mytest.h5" );
    // 空的關鍵點容器
    std::vector<cv::KeyPoint> keypoints;
    // 從第二個關鍵點開始讀取三個關鍵點
    h5io->kpread( keypoints, "keypoints", 1, 3 );
    // 釋放
    h5io->close();

◆ kpwrite()

virtual void cv::hdf::HDF5::kpwrite ( const vector< KeyPoint > keypoints,
const String & kplabel,
const int offset = H5_NONE,
const int counts = H5_NONE ) const
純虛擬函式

KeyPoint 列表寫入或覆蓋到 hdf5 檔案的指定資料集。

引數
keypoints指定要寫入的關鍵點資料列表。
kplabel指定目標 hdf5 資料集標籤。
offset指定資料集上偏移位置,關鍵點將從該位置寫入(覆蓋)到資料集中。
counts指定將寫入資料集的關鍵點數量。

將 vector<KeyPoint> 物件寫入目標資料集。

注意
如果資料集未建立且不存在,則將自動建立。它是執行緒安全的,但建議寫入操作發生在不重疊的獨立區域。多個數據集可以寫入單個 hdf5 檔案中。
  • 下面的示例將 100 個關鍵點寫入資料集。不需要預先建立資料集。如果例程被多次呼叫,資料集將被覆蓋。
    // 生成 100 個虛擬關鍵點
    std::vector<cv::KeyPoint> keypoints;
    for(int i = 0; i < 100; i++)
    keypoints.push_back( cv::KeyPoint(i, -i, 1, -1, 0, 0, -1) );
    // 開啟/自動建立 hdf5 檔案
    cv::Ptr<cv::hdf::HDF5> h5io = cv::hdf::open( "mytest.h5" );
    // 寫入/覆蓋資料集
    h5io->kpwrite( keypoints, "keypoints" );
    // 釋放
    h5io->close();
  • 下面的示例使用較小的 50 個關鍵點集,並寫入到 100 個關鍵點的壓縮空間中,該空間由 10 個塊最佳化。同一關鍵點集被寫入三次,首先寫入前半部分 (0->50),然後寫入後半部分 (50->75),最後寫入剩餘槽位 (75->99),使用偏移量和計數引數設定寫入訪問的視窗。如果例程被多次呼叫,資料集將被覆蓋。
    // 生成 50 個虛擬關鍵點
    std::vector<cv::KeyPoint> keypoints;
    for(int i = 0; i < 50; i++)
    keypoints.push_back( cv::KeyPoint(i, -i, 1, -1, 0, 0, -1) );
    // 開啟/自動建立 hdf5 檔案
    cv::Ptr<cv::hdf::HDF5> h5io = cv::hdf::open( "mytest.h5" );
    // 建立大小為 100 的最大壓縮空間,分塊大小為 10
    h5io->kpcreate( 100, "keypoints", 9, 10 );
    // 寫入前半部分
    h5io->kpwrite( keypoints, "keypoints", 0 );
    // 將前 25 個關鍵點寫入後半部分
    h5io->kpwrite( keypoints, "keypoints", 50, 25 );
    // 將前 25 個關鍵點寫入後半部分的剩餘空間
    h5io->kpwrite( keypoints, "keypoints", 75, 25 );
    // 釋放
    h5io->close();

此類的文件是從以下檔案生成的