File: create_groups.cpp

package info (click to toggle)
opencv 4.6.0%2Bdfsg-12
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 276,172 kB
  • sloc: cpp: 1,079,020; xml: 682,526; python: 43,885; lisp: 30,943; java: 25,642; ansic: 7,968; javascript: 5,956; objc: 2,039; sh: 1,017; cs: 601; perl: 494; makefile: 179
file content (56 lines) | stat: -rw-r--r-- 1,436 bytes parent folder | download | duplicates (4)
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]