File: create_groups.cpp

package info (click to toggle)
opencv 4.10.0%2Bdfsg-5
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 282,092 kB
  • sloc: cpp: 1,178,079; xml: 682,621; python: 49,092; lisp: 31,150; java: 25,469; ansic: 11,039; javascript: 6,085; sh: 1,214; cs: 601; perl: 494; objc: 210; makefile: 173
file content (56 lines) | stat: -rw-r--r-- 1,436 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
/**
 * @file create_groups.cpp
 * @author Fangjun Kuang <csukuangfj dot at gmail dot com>
 * @date December 2017
 *
 * @brief It demonstrates how to create HDF5 groups and subgroups.
 *
 * Basic steps:
 *  1. Use hdf::open to create a HDF5 file
 *  2. Use HDF5::hlexists to check if a group exists or not
 *  3. Use HDF5::grcreate to create a group by specifying its name
 *  4. Use hdf::close to close a HDF5 file after modifying it
 *
 */

//! [tutorial]
#include <iostream>

#include <opencv2/core.hpp>
#include <opencv2/hdf.hpp>

using namespace cv;

int main()
{
    //! [create_group]

    //! [tutorial_create_file]
    Ptr<hdf::HDF5> h5io = hdf::open("mytest.h5");
    //! [tutorial_create_file]

    //! [tutorial_create_group]
    // "/" 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";
    //! [tutorial_create_group]

    //! [tutorial_create_subgroup]
    // 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";
    //! [tutorial_create_subgroup]

    //! [tutorial_close_file]
    h5io->close();
    //! [tutorial_close_file]

    //! [create_group]

    return 0;
}
//! [tutorial]