openCV library for Renesas RZ/A
Dependents: RZ_A2M_Mbed_samples
include/opencv2/core/persistence.hpp@0:0e0631af0305, 2021-01-29 (annotated)
- Committer:
- RyoheiHagimoto
- Date:
- Fri Jan 29 04:53:38 2021 +0000
- Revision:
- 0:0e0631af0305
copied from https://github.com/d-kato/opencv-lib.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
RyoheiHagimoto | 0:0e0631af0305 | 1 | /*M/////////////////////////////////////////////////////////////////////////////////////// |
RyoheiHagimoto | 0:0e0631af0305 | 2 | // |
RyoheiHagimoto | 0:0e0631af0305 | 3 | // IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING. |
RyoheiHagimoto | 0:0e0631af0305 | 4 | // |
RyoheiHagimoto | 0:0e0631af0305 | 5 | // By downloading, copying, installing or using the software you agree to this license. |
RyoheiHagimoto | 0:0e0631af0305 | 6 | // If you do not agree to this license, do not download, install, |
RyoheiHagimoto | 0:0e0631af0305 | 7 | // copy or use the software. |
RyoheiHagimoto | 0:0e0631af0305 | 8 | // |
RyoheiHagimoto | 0:0e0631af0305 | 9 | // |
RyoheiHagimoto | 0:0e0631af0305 | 10 | // License Agreement |
RyoheiHagimoto | 0:0e0631af0305 | 11 | // For Open Source Computer Vision Library |
RyoheiHagimoto | 0:0e0631af0305 | 12 | // |
RyoheiHagimoto | 0:0e0631af0305 | 13 | // Copyright (C) 2000-2008, Intel Corporation, all rights reserved. |
RyoheiHagimoto | 0:0e0631af0305 | 14 | // Copyright (C) 2009, Willow Garage Inc., all rights reserved. |
RyoheiHagimoto | 0:0e0631af0305 | 15 | // Copyright (C) 2013, OpenCV Foundation, all rights reserved. |
RyoheiHagimoto | 0:0e0631af0305 | 16 | // Third party copyrights are property of their respective owners. |
RyoheiHagimoto | 0:0e0631af0305 | 17 | // |
RyoheiHagimoto | 0:0e0631af0305 | 18 | // Redistribution and use in source and binary forms, with or without modification, |
RyoheiHagimoto | 0:0e0631af0305 | 19 | // are permitted provided that the following conditions are met: |
RyoheiHagimoto | 0:0e0631af0305 | 20 | // |
RyoheiHagimoto | 0:0e0631af0305 | 21 | // * Redistribution's of source code must retain the above copyright notice, |
RyoheiHagimoto | 0:0e0631af0305 | 22 | // this list of conditions and the following disclaimer. |
RyoheiHagimoto | 0:0e0631af0305 | 23 | // |
RyoheiHagimoto | 0:0e0631af0305 | 24 | // * Redistribution's in binary form must reproduce the above copyright notice, |
RyoheiHagimoto | 0:0e0631af0305 | 25 | // this list of conditions and the following disclaimer in the documentation |
RyoheiHagimoto | 0:0e0631af0305 | 26 | // and/or other materials provided with the distribution. |
RyoheiHagimoto | 0:0e0631af0305 | 27 | // |
RyoheiHagimoto | 0:0e0631af0305 | 28 | // * The name of the copyright holders may not be used to endorse or promote products |
RyoheiHagimoto | 0:0e0631af0305 | 29 | // derived from this software without specific prior written permission. |
RyoheiHagimoto | 0:0e0631af0305 | 30 | // |
RyoheiHagimoto | 0:0e0631af0305 | 31 | // This software is provided by the copyright holders and contributors "as is" and |
RyoheiHagimoto | 0:0e0631af0305 | 32 | // any express or implied warranties, including, but not limited to, the implied |
RyoheiHagimoto | 0:0e0631af0305 | 33 | // warranties of merchantability and fitness for a particular purpose are disclaimed. |
RyoheiHagimoto | 0:0e0631af0305 | 34 | // In no event shall the Intel Corporation or contributors be liable for any direct, |
RyoheiHagimoto | 0:0e0631af0305 | 35 | // indirect, incidental, special, exemplary, or consequential damages |
RyoheiHagimoto | 0:0e0631af0305 | 36 | // (including, but not limited to, procurement of substitute goods or services; |
RyoheiHagimoto | 0:0e0631af0305 | 37 | // loss of use, data, or profits; or business interruption) however caused |
RyoheiHagimoto | 0:0e0631af0305 | 38 | // and on any theory of liability, whether in contract, strict liability, |
RyoheiHagimoto | 0:0e0631af0305 | 39 | // or tort (including negligence or otherwise) arising in any way out of |
RyoheiHagimoto | 0:0e0631af0305 | 40 | // the use of this software, even if advised of the possibility of such damage. |
RyoheiHagimoto | 0:0e0631af0305 | 41 | // |
RyoheiHagimoto | 0:0e0631af0305 | 42 | //M*/ |
RyoheiHagimoto | 0:0e0631af0305 | 43 | |
RyoheiHagimoto | 0:0e0631af0305 | 44 | #ifndef OPENCV_CORE_PERSISTENCE_HPP |
RyoheiHagimoto | 0:0e0631af0305 | 45 | #define OPENCV_CORE_PERSISTENCE_HPP |
RyoheiHagimoto | 0:0e0631af0305 | 46 | |
RyoheiHagimoto | 0:0e0631af0305 | 47 | #ifndef __cplusplus |
RyoheiHagimoto | 0:0e0631af0305 | 48 | # error persistence.hpp header must be compiled as C++ |
RyoheiHagimoto | 0:0e0631af0305 | 49 | #endif |
RyoheiHagimoto | 0:0e0631af0305 | 50 | |
RyoheiHagimoto | 0:0e0631af0305 | 51 | //! @addtogroup core_c |
RyoheiHagimoto | 0:0e0631af0305 | 52 | //! @{ |
RyoheiHagimoto | 0:0e0631af0305 | 53 | |
RyoheiHagimoto | 0:0e0631af0305 | 54 | /** @brief "black box" representation of the file storage associated with a file on disk. |
RyoheiHagimoto | 0:0e0631af0305 | 55 | |
RyoheiHagimoto | 0:0e0631af0305 | 56 | Several functions that are described below take CvFileStorage\* as inputs and allow the user to |
RyoheiHagimoto | 0:0e0631af0305 | 57 | save or to load hierarchical collections that consist of scalar values, standard CXCore objects |
RyoheiHagimoto | 0:0e0631af0305 | 58 | (such as matrices, sequences, graphs), and user-defined objects. |
RyoheiHagimoto | 0:0e0631af0305 | 59 | |
RyoheiHagimoto | 0:0e0631af0305 | 60 | OpenCV can read and write data in XML (<http://www.w3c.org/XML>), YAML (<http://www.yaml.org>) or |
RyoheiHagimoto | 0:0e0631af0305 | 61 | JSON (<http://www.json.org/>) formats. Below is an example of 3x3 floating-point identity matrix A, |
RyoheiHagimoto | 0:0e0631af0305 | 62 | stored in XML and YAML files |
RyoheiHagimoto | 0:0e0631af0305 | 63 | using CXCore functions: |
RyoheiHagimoto | 0:0e0631af0305 | 64 | XML: |
RyoheiHagimoto | 0:0e0631af0305 | 65 | @code{.xml} |
RyoheiHagimoto | 0:0e0631af0305 | 66 | <?xml version="1.0"> |
RyoheiHagimoto | 0:0e0631af0305 | 67 | <opencv_storage> |
RyoheiHagimoto | 0:0e0631af0305 | 68 | <A type_id="opencv-matrix"> |
RyoheiHagimoto | 0:0e0631af0305 | 69 | <rows>3</rows> |
RyoheiHagimoto | 0:0e0631af0305 | 70 | <cols>3</cols> |
RyoheiHagimoto | 0:0e0631af0305 | 71 | <dt>f</dt> |
RyoheiHagimoto | 0:0e0631af0305 | 72 | <data>1. 0. 0. 0. 1. 0. 0. 0. 1.</data> |
RyoheiHagimoto | 0:0e0631af0305 | 73 | </A> |
RyoheiHagimoto | 0:0e0631af0305 | 74 | </opencv_storage> |
RyoheiHagimoto | 0:0e0631af0305 | 75 | @endcode |
RyoheiHagimoto | 0:0e0631af0305 | 76 | YAML: |
RyoheiHagimoto | 0:0e0631af0305 | 77 | @code{.yaml} |
RyoheiHagimoto | 0:0e0631af0305 | 78 | %YAML:1.0 |
RyoheiHagimoto | 0:0e0631af0305 | 79 | A: !!opencv-matrix |
RyoheiHagimoto | 0:0e0631af0305 | 80 | rows: 3 |
RyoheiHagimoto | 0:0e0631af0305 | 81 | cols: 3 |
RyoheiHagimoto | 0:0e0631af0305 | 82 | dt: f |
RyoheiHagimoto | 0:0e0631af0305 | 83 | data: [ 1., 0., 0., 0., 1., 0., 0., 0., 1.] |
RyoheiHagimoto | 0:0e0631af0305 | 84 | @endcode |
RyoheiHagimoto | 0:0e0631af0305 | 85 | As it can be seen from the examples, XML uses nested tags to represent hierarchy, while YAML uses |
RyoheiHagimoto | 0:0e0631af0305 | 86 | indentation for that purpose (similar to the Python programming language). |
RyoheiHagimoto | 0:0e0631af0305 | 87 | |
RyoheiHagimoto | 0:0e0631af0305 | 88 | The same functions can read and write data in both formats; the particular format is determined by |
RyoheiHagimoto | 0:0e0631af0305 | 89 | the extension of the opened file, ".xml" for XML files, ".yml" or ".yaml" for YAML and ".json" for |
RyoheiHagimoto | 0:0e0631af0305 | 90 | JSON. |
RyoheiHagimoto | 0:0e0631af0305 | 91 | */ |
RyoheiHagimoto | 0:0e0631af0305 | 92 | typedef struct CvFileStorage CvFileStorage; |
RyoheiHagimoto | 0:0e0631af0305 | 93 | typedef struct CvFileNode CvFileNode; |
RyoheiHagimoto | 0:0e0631af0305 | 94 | typedef struct CvMat CvMat; |
RyoheiHagimoto | 0:0e0631af0305 | 95 | typedef struct CvMatND CvMatND; |
RyoheiHagimoto | 0:0e0631af0305 | 96 | |
RyoheiHagimoto | 0:0e0631af0305 | 97 | //! @} core_c |
RyoheiHagimoto | 0:0e0631af0305 | 98 | |
RyoheiHagimoto | 0:0e0631af0305 | 99 | #include "opencv2/core/types.hpp" |
RyoheiHagimoto | 0:0e0631af0305 | 100 | #include "opencv2/core/mat.hpp" |
RyoheiHagimoto | 0:0e0631af0305 | 101 | |
RyoheiHagimoto | 0:0e0631af0305 | 102 | namespace cv { |
RyoheiHagimoto | 0:0e0631af0305 | 103 | |
RyoheiHagimoto | 0:0e0631af0305 | 104 | /** @addtogroup core_xml |
RyoheiHagimoto | 0:0e0631af0305 | 105 | |
RyoheiHagimoto | 0:0e0631af0305 | 106 | XML/YAML/JSON file storages. {#xml_storage} |
RyoheiHagimoto | 0:0e0631af0305 | 107 | ======================= |
RyoheiHagimoto | 0:0e0631af0305 | 108 | Writing to a file storage. |
RyoheiHagimoto | 0:0e0631af0305 | 109 | -------------------------- |
RyoheiHagimoto | 0:0e0631af0305 | 110 | You can store and then restore various OpenCV data structures to/from XML (<http://www.w3c.org/XML>), |
RyoheiHagimoto | 0:0e0631af0305 | 111 | YAML (<http://www.yaml.org>) or JSON (<http://www.json.org/>) formats. Also, it is possible store |
RyoheiHagimoto | 0:0e0631af0305 | 112 | and load arbitrarily complex data structures, which include OpenCV data structures, as well as |
RyoheiHagimoto | 0:0e0631af0305 | 113 | primitive data types (integer and floating-point numbers and text strings) as their elements. |
RyoheiHagimoto | 0:0e0631af0305 | 114 | |
RyoheiHagimoto | 0:0e0631af0305 | 115 | Use the following procedure to write something to XML, YAML or JSON: |
RyoheiHagimoto | 0:0e0631af0305 | 116 | -# Create new FileStorage and open it for writing. It can be done with a single call to |
RyoheiHagimoto | 0:0e0631af0305 | 117 | FileStorage::FileStorage constructor that takes a filename, or you can use the default constructor |
RyoheiHagimoto | 0:0e0631af0305 | 118 | and then call FileStorage::open. Format of the file (XML, YAML or JSON) is determined from the filename |
RyoheiHagimoto | 0:0e0631af0305 | 119 | extension (".xml", ".yml"/".yaml" and ".json", respectively) |
RyoheiHagimoto | 0:0e0631af0305 | 120 | -# Write all the data you want using the streaming operator `<<`, just like in the case of STL |
RyoheiHagimoto | 0:0e0631af0305 | 121 | streams. |
RyoheiHagimoto | 0:0e0631af0305 | 122 | -# Close the file using FileStorage::release. FileStorage destructor also closes the file. |
RyoheiHagimoto | 0:0e0631af0305 | 123 | |
RyoheiHagimoto | 0:0e0631af0305 | 124 | Here is an example: |
RyoheiHagimoto | 0:0e0631af0305 | 125 | @code |
RyoheiHagimoto | 0:0e0631af0305 | 126 | #include "opencv2/opencv.hpp" |
RyoheiHagimoto | 0:0e0631af0305 | 127 | #include <time.h> |
RyoheiHagimoto | 0:0e0631af0305 | 128 | |
RyoheiHagimoto | 0:0e0631af0305 | 129 | using namespace cv; |
RyoheiHagimoto | 0:0e0631af0305 | 130 | |
RyoheiHagimoto | 0:0e0631af0305 | 131 | int main(int, char** argv) |
RyoheiHagimoto | 0:0e0631af0305 | 132 | { |
RyoheiHagimoto | 0:0e0631af0305 | 133 | FileStorage fs("test.yml", FileStorage::WRITE); |
RyoheiHagimoto | 0:0e0631af0305 | 134 | |
RyoheiHagimoto | 0:0e0631af0305 | 135 | fs << "frameCount" << 5; |
RyoheiHagimoto | 0:0e0631af0305 | 136 | time_t rawtime; time(&rawtime); |
RyoheiHagimoto | 0:0e0631af0305 | 137 | fs << "calibrationDate" << asctime(localtime(&rawtime)); |
RyoheiHagimoto | 0:0e0631af0305 | 138 | Mat cameraMatrix = (Mat_<double>(3,3) << 1000, 0, 320, 0, 1000, 240, 0, 0, 1); |
RyoheiHagimoto | 0:0e0631af0305 | 139 | Mat distCoeffs = (Mat_<double>(5,1) << 0.1, 0.01, -0.001, 0, 0); |
RyoheiHagimoto | 0:0e0631af0305 | 140 | fs << "cameraMatrix" << cameraMatrix << "distCoeffs" << distCoeffs; |
RyoheiHagimoto | 0:0e0631af0305 | 141 | fs << "features" << "["; |
RyoheiHagimoto | 0:0e0631af0305 | 142 | for( int i = 0; i < 3; i++ ) |
RyoheiHagimoto | 0:0e0631af0305 | 143 | { |
RyoheiHagimoto | 0:0e0631af0305 | 144 | int x = rand() % 640; |
RyoheiHagimoto | 0:0e0631af0305 | 145 | int y = rand() % 480; |
RyoheiHagimoto | 0:0e0631af0305 | 146 | uchar lbp = rand() % 256; |
RyoheiHagimoto | 0:0e0631af0305 | 147 | |
RyoheiHagimoto | 0:0e0631af0305 | 148 | fs << "{:" << "x" << x << "y" << y << "lbp" << "[:"; |
RyoheiHagimoto | 0:0e0631af0305 | 149 | for( int j = 0; j < 8; j++ ) |
RyoheiHagimoto | 0:0e0631af0305 | 150 | fs << ((lbp >> j) & 1); |
RyoheiHagimoto | 0:0e0631af0305 | 151 | fs << "]" << "}"; |
RyoheiHagimoto | 0:0e0631af0305 | 152 | } |
RyoheiHagimoto | 0:0e0631af0305 | 153 | fs << "]"; |
RyoheiHagimoto | 0:0e0631af0305 | 154 | fs.release(); |
RyoheiHagimoto | 0:0e0631af0305 | 155 | return 0; |
RyoheiHagimoto | 0:0e0631af0305 | 156 | } |
RyoheiHagimoto | 0:0e0631af0305 | 157 | @endcode |
RyoheiHagimoto | 0:0e0631af0305 | 158 | The sample above stores to XML and integer, text string (calibration date), 2 matrices, and a custom |
RyoheiHagimoto | 0:0e0631af0305 | 159 | structure "feature", which includes feature coordinates and LBP (local binary pattern) value. Here |
RyoheiHagimoto | 0:0e0631af0305 | 160 | is output of the sample: |
RyoheiHagimoto | 0:0e0631af0305 | 161 | @code{.yaml} |
RyoheiHagimoto | 0:0e0631af0305 | 162 | %YAML:1.0 |
RyoheiHagimoto | 0:0e0631af0305 | 163 | frameCount: 5 |
RyoheiHagimoto | 0:0e0631af0305 | 164 | calibrationDate: "Fri Jun 17 14:09:29 2011\n" |
RyoheiHagimoto | 0:0e0631af0305 | 165 | cameraMatrix: !!opencv-matrix |
RyoheiHagimoto | 0:0e0631af0305 | 166 | rows: 3 |
RyoheiHagimoto | 0:0e0631af0305 | 167 | cols: 3 |
RyoheiHagimoto | 0:0e0631af0305 | 168 | dt: d |
RyoheiHagimoto | 0:0e0631af0305 | 169 | data: [ 1000., 0., 320., 0., 1000., 240., 0., 0., 1. ] |
RyoheiHagimoto | 0:0e0631af0305 | 170 | distCoeffs: !!opencv-matrix |
RyoheiHagimoto | 0:0e0631af0305 | 171 | rows: 5 |
RyoheiHagimoto | 0:0e0631af0305 | 172 | cols: 1 |
RyoheiHagimoto | 0:0e0631af0305 | 173 | dt: d |
RyoheiHagimoto | 0:0e0631af0305 | 174 | data: [ 1.0000000000000001e-01, 1.0000000000000000e-02, |
RyoheiHagimoto | 0:0e0631af0305 | 175 | -1.0000000000000000e-03, 0., 0. ] |
RyoheiHagimoto | 0:0e0631af0305 | 176 | features: |
RyoheiHagimoto | 0:0e0631af0305 | 177 | - { x:167, y:49, lbp:[ 1, 0, 0, 1, 1, 0, 1, 1 ] } |
RyoheiHagimoto | 0:0e0631af0305 | 178 | - { x:298, y:130, lbp:[ 0, 0, 0, 1, 0, 0, 1, 1 ] } |
RyoheiHagimoto | 0:0e0631af0305 | 179 | - { x:344, y:158, lbp:[ 1, 1, 0, 0, 0, 0, 1, 0 ] } |
RyoheiHagimoto | 0:0e0631af0305 | 180 | @endcode |
RyoheiHagimoto | 0:0e0631af0305 | 181 | |
RyoheiHagimoto | 0:0e0631af0305 | 182 | As an exercise, you can replace ".yml" with ".xml" or ".json" in the sample above and see, how the |
RyoheiHagimoto | 0:0e0631af0305 | 183 | corresponding XML file will look like. |
RyoheiHagimoto | 0:0e0631af0305 | 184 | |
RyoheiHagimoto | 0:0e0631af0305 | 185 | Several things can be noted by looking at the sample code and the output: |
RyoheiHagimoto | 0:0e0631af0305 | 186 | |
RyoheiHagimoto | 0:0e0631af0305 | 187 | - The produced YAML (and XML/JSON) consists of heterogeneous collections that can be nested. There are |
RyoheiHagimoto | 0:0e0631af0305 | 188 | 2 types of collections: named collections (mappings) and unnamed collections (sequences). In mappings |
RyoheiHagimoto | 0:0e0631af0305 | 189 | each element has a name and is accessed by name. This is similar to structures and std::map in |
RyoheiHagimoto | 0:0e0631af0305 | 190 | C/C++ and dictionaries in Python. In sequences elements do not have names, they are accessed by |
RyoheiHagimoto | 0:0e0631af0305 | 191 | indices. This is similar to arrays and std::vector in C/C++ and lists, tuples in Python. |
RyoheiHagimoto | 0:0e0631af0305 | 192 | "Heterogeneous" means that elements of each single collection can have different types. |
RyoheiHagimoto | 0:0e0631af0305 | 193 | |
RyoheiHagimoto | 0:0e0631af0305 | 194 | Top-level collection in YAML/XML/JSON is a mapping. Each matrix is stored as a mapping, and the matrix |
RyoheiHagimoto | 0:0e0631af0305 | 195 | elements are stored as a sequence. Then, there is a sequence of features, where each feature is |
RyoheiHagimoto | 0:0e0631af0305 | 196 | represented a mapping, and lbp value in a nested sequence. |
RyoheiHagimoto | 0:0e0631af0305 | 197 | |
RyoheiHagimoto | 0:0e0631af0305 | 198 | - When you write to a mapping (a structure), you write element name followed by its value. When you |
RyoheiHagimoto | 0:0e0631af0305 | 199 | write to a sequence, you simply write the elements one by one. OpenCV data structures (such as |
RyoheiHagimoto | 0:0e0631af0305 | 200 | cv::Mat) are written in absolutely the same way as simple C data structures - using `<<` |
RyoheiHagimoto | 0:0e0631af0305 | 201 | operator. |
RyoheiHagimoto | 0:0e0631af0305 | 202 | |
RyoheiHagimoto | 0:0e0631af0305 | 203 | - To write a mapping, you first write the special string `{` to the storage, then write the |
RyoheiHagimoto | 0:0e0631af0305 | 204 | elements as pairs (`fs << <element_name> << <element_value>`) and then write the closing |
RyoheiHagimoto | 0:0e0631af0305 | 205 | `}`. |
RyoheiHagimoto | 0:0e0631af0305 | 206 | |
RyoheiHagimoto | 0:0e0631af0305 | 207 | - To write a sequence, you first write the special string `[`, then write the elements, then |
RyoheiHagimoto | 0:0e0631af0305 | 208 | write the closing `]`. |
RyoheiHagimoto | 0:0e0631af0305 | 209 | |
RyoheiHagimoto | 0:0e0631af0305 | 210 | - In YAML/JSON (but not XML), mappings and sequences can be written in a compact Python-like inline |
RyoheiHagimoto | 0:0e0631af0305 | 211 | form. In the sample above matrix elements, as well as each feature, including its lbp value, is |
RyoheiHagimoto | 0:0e0631af0305 | 212 | stored in such inline form. To store a mapping/sequence in a compact form, put `:` after the |
RyoheiHagimoto | 0:0e0631af0305 | 213 | opening character, e.g. use `{:` instead of `{` and `[:` instead of `[`. When the |
RyoheiHagimoto | 0:0e0631af0305 | 214 | data is written to XML, those extra `:` are ignored. |
RyoheiHagimoto | 0:0e0631af0305 | 215 | |
RyoheiHagimoto | 0:0e0631af0305 | 216 | Reading data from a file storage. |
RyoheiHagimoto | 0:0e0631af0305 | 217 | --------------------------------- |
RyoheiHagimoto | 0:0e0631af0305 | 218 | To read the previously written XML, YAML or JSON file, do the following: |
RyoheiHagimoto | 0:0e0631af0305 | 219 | -# Open the file storage using FileStorage::FileStorage constructor or FileStorage::open method. |
RyoheiHagimoto | 0:0e0631af0305 | 220 | In the current implementation the whole file is parsed and the whole representation of file |
RyoheiHagimoto | 0:0e0631af0305 | 221 | storage is built in memory as a hierarchy of file nodes (see FileNode) |
RyoheiHagimoto | 0:0e0631af0305 | 222 | |
RyoheiHagimoto | 0:0e0631af0305 | 223 | -# Read the data you are interested in. Use FileStorage::operator [], FileNode::operator [] |
RyoheiHagimoto | 0:0e0631af0305 | 224 | and/or FileNodeIterator. |
RyoheiHagimoto | 0:0e0631af0305 | 225 | |
RyoheiHagimoto | 0:0e0631af0305 | 226 | -# Close the storage using FileStorage::release. |
RyoheiHagimoto | 0:0e0631af0305 | 227 | |
RyoheiHagimoto | 0:0e0631af0305 | 228 | Here is how to read the file created by the code sample above: |
RyoheiHagimoto | 0:0e0631af0305 | 229 | @code |
RyoheiHagimoto | 0:0e0631af0305 | 230 | FileStorage fs2("test.yml", FileStorage::READ); |
RyoheiHagimoto | 0:0e0631af0305 | 231 | |
RyoheiHagimoto | 0:0e0631af0305 | 232 | // first method: use (type) operator on FileNode. |
RyoheiHagimoto | 0:0e0631af0305 | 233 | int frameCount = (int)fs2["frameCount"]; |
RyoheiHagimoto | 0:0e0631af0305 | 234 | |
RyoheiHagimoto | 0:0e0631af0305 | 235 | String date; |
RyoheiHagimoto | 0:0e0631af0305 | 236 | // second method: use FileNode::operator >> |
RyoheiHagimoto | 0:0e0631af0305 | 237 | fs2["calibrationDate"] >> date; |
RyoheiHagimoto | 0:0e0631af0305 | 238 | |
RyoheiHagimoto | 0:0e0631af0305 | 239 | Mat cameraMatrix2, distCoeffs2; |
RyoheiHagimoto | 0:0e0631af0305 | 240 | fs2["cameraMatrix"] >> cameraMatrix2; |
RyoheiHagimoto | 0:0e0631af0305 | 241 | fs2["distCoeffs"] >> distCoeffs2; |
RyoheiHagimoto | 0:0e0631af0305 | 242 | |
RyoheiHagimoto | 0:0e0631af0305 | 243 | cout << "frameCount: " << frameCount << endl |
RyoheiHagimoto | 0:0e0631af0305 | 244 | << "calibration date: " << date << endl |
RyoheiHagimoto | 0:0e0631af0305 | 245 | << "camera matrix: " << cameraMatrix2 << endl |
RyoheiHagimoto | 0:0e0631af0305 | 246 | << "distortion coeffs: " << distCoeffs2 << endl; |
RyoheiHagimoto | 0:0e0631af0305 | 247 | |
RyoheiHagimoto | 0:0e0631af0305 | 248 | FileNode features = fs2["features"]; |
RyoheiHagimoto | 0:0e0631af0305 | 249 | FileNodeIterator it = features.begin(), it_end = features.end(); |
RyoheiHagimoto | 0:0e0631af0305 | 250 | int idx = 0; |
RyoheiHagimoto | 0:0e0631af0305 | 251 | std::vector<uchar> lbpval; |
RyoheiHagimoto | 0:0e0631af0305 | 252 | |
RyoheiHagimoto | 0:0e0631af0305 | 253 | // iterate through a sequence using FileNodeIterator |
RyoheiHagimoto | 0:0e0631af0305 | 254 | for( ; it != it_end; ++it, idx++ ) |
RyoheiHagimoto | 0:0e0631af0305 | 255 | { |
RyoheiHagimoto | 0:0e0631af0305 | 256 | cout << "feature #" << idx << ": "; |
RyoheiHagimoto | 0:0e0631af0305 | 257 | cout << "x=" << (int)(*it)["x"] << ", y=" << (int)(*it)["y"] << ", lbp: ("; |
RyoheiHagimoto | 0:0e0631af0305 | 258 | // you can also easily read numerical arrays using FileNode >> std::vector operator. |
RyoheiHagimoto | 0:0e0631af0305 | 259 | (*it)["lbp"] >> lbpval; |
RyoheiHagimoto | 0:0e0631af0305 | 260 | for( int i = 0; i < (int)lbpval.size(); i++ ) |
RyoheiHagimoto | 0:0e0631af0305 | 261 | cout << " " << (int)lbpval[i]; |
RyoheiHagimoto | 0:0e0631af0305 | 262 | cout << ")" << endl; |
RyoheiHagimoto | 0:0e0631af0305 | 263 | } |
RyoheiHagimoto | 0:0e0631af0305 | 264 | fs2.release(); |
RyoheiHagimoto | 0:0e0631af0305 | 265 | @endcode |
RyoheiHagimoto | 0:0e0631af0305 | 266 | |
RyoheiHagimoto | 0:0e0631af0305 | 267 | Format specification {#format_spec} |
RyoheiHagimoto | 0:0e0631af0305 | 268 | -------------------- |
RyoheiHagimoto | 0:0e0631af0305 | 269 | `([count]{u|c|w|s|i|f|d})`... where the characters correspond to fundamental C++ types: |
RyoheiHagimoto | 0:0e0631af0305 | 270 | - `u` 8-bit unsigned number |
RyoheiHagimoto | 0:0e0631af0305 | 271 | - `c` 8-bit signed number |
RyoheiHagimoto | 0:0e0631af0305 | 272 | - `w` 16-bit unsigned number |
RyoheiHagimoto | 0:0e0631af0305 | 273 | - `s` 16-bit signed number |
RyoheiHagimoto | 0:0e0631af0305 | 274 | - `i` 32-bit signed number |
RyoheiHagimoto | 0:0e0631af0305 | 275 | - `f` single precision floating-point number |
RyoheiHagimoto | 0:0e0631af0305 | 276 | - `d` double precision floating-point number |
RyoheiHagimoto | 0:0e0631af0305 | 277 | - `r` pointer, 32 lower bits of which are written as a signed integer. The type can be used to |
RyoheiHagimoto | 0:0e0631af0305 | 278 | store structures with links between the elements. |
RyoheiHagimoto | 0:0e0631af0305 | 279 | |
RyoheiHagimoto | 0:0e0631af0305 | 280 | `count` is the optional counter of values of a given type. For example, `2if` means that each array |
RyoheiHagimoto | 0:0e0631af0305 | 281 | element is a structure of 2 integers, followed by a single-precision floating-point number. The |
RyoheiHagimoto | 0:0e0631af0305 | 282 | equivalent notations of the above specification are `iif`, `2i1f` and so forth. Other examples: `u` |
RyoheiHagimoto | 0:0e0631af0305 | 283 | means that the array consists of bytes, and `2d` means the array consists of pairs of doubles. |
RyoheiHagimoto | 0:0e0631af0305 | 284 | |
RyoheiHagimoto | 0:0e0631af0305 | 285 | @see @ref filestorage.cpp |
RyoheiHagimoto | 0:0e0631af0305 | 286 | */ |
RyoheiHagimoto | 0:0e0631af0305 | 287 | |
RyoheiHagimoto | 0:0e0631af0305 | 288 | //! @{ |
RyoheiHagimoto | 0:0e0631af0305 | 289 | |
RyoheiHagimoto | 0:0e0631af0305 | 290 | /** @example filestorage.cpp |
RyoheiHagimoto | 0:0e0631af0305 | 291 | A complete example using the FileStorage interface |
RyoheiHagimoto | 0:0e0631af0305 | 292 | */ |
RyoheiHagimoto | 0:0e0631af0305 | 293 | |
RyoheiHagimoto | 0:0e0631af0305 | 294 | ////////////////////////// XML & YAML I/O ////////////////////////// |
RyoheiHagimoto | 0:0e0631af0305 | 295 | |
RyoheiHagimoto | 0:0e0631af0305 | 296 | class CV_EXPORTS FileNode; |
RyoheiHagimoto | 0:0e0631af0305 | 297 | class CV_EXPORTS FileNodeIterator; |
RyoheiHagimoto | 0:0e0631af0305 | 298 | |
RyoheiHagimoto | 0:0e0631af0305 | 299 | /** @brief XML/YAML/JSON file storage class that encapsulates all the information necessary for writing or |
RyoheiHagimoto | 0:0e0631af0305 | 300 | reading data to/from a file. |
RyoheiHagimoto | 0:0e0631af0305 | 301 | */ |
RyoheiHagimoto | 0:0e0631af0305 | 302 | class CV_EXPORTS_W FileStorage |
RyoheiHagimoto | 0:0e0631af0305 | 303 | { |
RyoheiHagimoto | 0:0e0631af0305 | 304 | public: |
RyoheiHagimoto | 0:0e0631af0305 | 305 | //! file storage mode |
RyoheiHagimoto | 0:0e0631af0305 | 306 | enum Mode |
RyoheiHagimoto | 0:0e0631af0305 | 307 | { |
RyoheiHagimoto | 0:0e0631af0305 | 308 | READ = 0, //!< value, open the file for reading |
RyoheiHagimoto | 0:0e0631af0305 | 309 | WRITE = 1, //!< value, open the file for writing |
RyoheiHagimoto | 0:0e0631af0305 | 310 | APPEND = 2, //!< value, open the file for appending |
RyoheiHagimoto | 0:0e0631af0305 | 311 | MEMORY = 4, //!< flag, read data from source or write data to the internal buffer (which is |
RyoheiHagimoto | 0:0e0631af0305 | 312 | //!< returned by FileStorage::release) |
RyoheiHagimoto | 0:0e0631af0305 | 313 | FORMAT_MASK = (7<<3), //!< mask for format flags |
RyoheiHagimoto | 0:0e0631af0305 | 314 | FORMAT_AUTO = 0, //!< flag, auto format |
RyoheiHagimoto | 0:0e0631af0305 | 315 | FORMAT_XML = (1<<3), //!< flag, XML format |
RyoheiHagimoto | 0:0e0631af0305 | 316 | FORMAT_YAML = (2<<3), //!< flag, YAML format |
RyoheiHagimoto | 0:0e0631af0305 | 317 | FORMAT_JSON = (3<<3), //!< flag, JSON format |
RyoheiHagimoto | 0:0e0631af0305 | 318 | |
RyoheiHagimoto | 0:0e0631af0305 | 319 | BASE64 = 64, //!< flag, write rawdata in Base64 by default. (consider using WRITE_BASE64) |
RyoheiHagimoto | 0:0e0631af0305 | 320 | WRITE_BASE64 = BASE64 | WRITE, //!< flag, enable both WRITE and BASE64 |
RyoheiHagimoto | 0:0e0631af0305 | 321 | }; |
RyoheiHagimoto | 0:0e0631af0305 | 322 | enum |
RyoheiHagimoto | 0:0e0631af0305 | 323 | { |
RyoheiHagimoto | 0:0e0631af0305 | 324 | UNDEFINED = 0, |
RyoheiHagimoto | 0:0e0631af0305 | 325 | VALUE_EXPECTED = 1, |
RyoheiHagimoto | 0:0e0631af0305 | 326 | NAME_EXPECTED = 2, |
RyoheiHagimoto | 0:0e0631af0305 | 327 | INSIDE_MAP = 4 |
RyoheiHagimoto | 0:0e0631af0305 | 328 | }; |
RyoheiHagimoto | 0:0e0631af0305 | 329 | |
RyoheiHagimoto | 0:0e0631af0305 | 330 | /** @brief The constructors. |
RyoheiHagimoto | 0:0e0631af0305 | 331 | |
RyoheiHagimoto | 0:0e0631af0305 | 332 | The full constructor opens the file. Alternatively you can use the default constructor and then |
RyoheiHagimoto | 0:0e0631af0305 | 333 | call FileStorage::open. |
RyoheiHagimoto | 0:0e0631af0305 | 334 | */ |
RyoheiHagimoto | 0:0e0631af0305 | 335 | CV_WRAP FileStorage(); |
RyoheiHagimoto | 0:0e0631af0305 | 336 | |
RyoheiHagimoto | 0:0e0631af0305 | 337 | /** @overload |
RyoheiHagimoto | 0:0e0631af0305 | 338 | @param source Name of the file to open or the text string to read the data from. Extension of the |
RyoheiHagimoto | 0:0e0631af0305 | 339 | file (.xml, .yml/.yaml, or .json) determines its format (XML, YAML or JSON respectively). Also you can |
RyoheiHagimoto | 0:0e0631af0305 | 340 | append .gz to work with compressed files, for example myHugeMatrix.xml.gz. If both FileStorage::WRITE |
RyoheiHagimoto | 0:0e0631af0305 | 341 | and FileStorage::MEMORY flags are specified, source is used just to specify the output file format (e.g. |
RyoheiHagimoto | 0:0e0631af0305 | 342 | mydata.xml, .yml etc.). |
RyoheiHagimoto | 0:0e0631af0305 | 343 | @param flags Mode of operation. See FileStorage::Mode |
RyoheiHagimoto | 0:0e0631af0305 | 344 | @param encoding Encoding of the file. Note that UTF-16 XML encoding is not supported currently and |
RyoheiHagimoto | 0:0e0631af0305 | 345 | you should use 8-bit encoding instead of it. |
RyoheiHagimoto | 0:0e0631af0305 | 346 | */ |
RyoheiHagimoto | 0:0e0631af0305 | 347 | CV_WRAP FileStorage(const String& source, int flags, const String& encoding=String()); |
RyoheiHagimoto | 0:0e0631af0305 | 348 | |
RyoheiHagimoto | 0:0e0631af0305 | 349 | /** @overload */ |
RyoheiHagimoto | 0:0e0631af0305 | 350 | FileStorage(CvFileStorage* fs, bool owning=true); |
RyoheiHagimoto | 0:0e0631af0305 | 351 | |
RyoheiHagimoto | 0:0e0631af0305 | 352 | //! the destructor. calls release() |
RyoheiHagimoto | 0:0e0631af0305 | 353 | virtual ~FileStorage(); |
RyoheiHagimoto | 0:0e0631af0305 | 354 | |
RyoheiHagimoto | 0:0e0631af0305 | 355 | /** @brief Opens a file. |
RyoheiHagimoto | 0:0e0631af0305 | 356 | |
RyoheiHagimoto | 0:0e0631af0305 | 357 | See description of parameters in FileStorage::FileStorage. The method calls FileStorage::release |
RyoheiHagimoto | 0:0e0631af0305 | 358 | before opening the file. |
RyoheiHagimoto | 0:0e0631af0305 | 359 | @param filename Name of the file to open or the text string to read the data from. |
RyoheiHagimoto | 0:0e0631af0305 | 360 | Extension of the file (.xml, .yml/.yaml or .json) determines its format (XML, YAML or JSON |
RyoheiHagimoto | 0:0e0631af0305 | 361 | respectively). Also you can append .gz to work with compressed files, for example myHugeMatrix.xml.gz. If both |
RyoheiHagimoto | 0:0e0631af0305 | 362 | FileStorage::WRITE and FileStorage::MEMORY flags are specified, source is used just to specify |
RyoheiHagimoto | 0:0e0631af0305 | 363 | the output file format (e.g. mydata.xml, .yml etc.). A file name can also contain parameters. |
RyoheiHagimoto | 0:0e0631af0305 | 364 | You can use this format, "*?base64" (e.g. "file.json?base64" (case sensitive)), as an alternative to |
RyoheiHagimoto | 0:0e0631af0305 | 365 | FileStorage::BASE64 flag. |
RyoheiHagimoto | 0:0e0631af0305 | 366 | @param flags Mode of operation. One of FileStorage::Mode |
RyoheiHagimoto | 0:0e0631af0305 | 367 | @param encoding Encoding of the file. Note that UTF-16 XML encoding is not supported currently and |
RyoheiHagimoto | 0:0e0631af0305 | 368 | you should use 8-bit encoding instead of it. |
RyoheiHagimoto | 0:0e0631af0305 | 369 | */ |
RyoheiHagimoto | 0:0e0631af0305 | 370 | CV_WRAP virtual bool open(const String& filename, int flags, const String& encoding=String()); |
RyoheiHagimoto | 0:0e0631af0305 | 371 | |
RyoheiHagimoto | 0:0e0631af0305 | 372 | /** @brief Checks whether the file is opened. |
RyoheiHagimoto | 0:0e0631af0305 | 373 | |
RyoheiHagimoto | 0:0e0631af0305 | 374 | @returns true if the object is associated with the current file and false otherwise. It is a |
RyoheiHagimoto | 0:0e0631af0305 | 375 | good practice to call this method after you tried to open a file. |
RyoheiHagimoto | 0:0e0631af0305 | 376 | */ |
RyoheiHagimoto | 0:0e0631af0305 | 377 | CV_WRAP virtual bool isOpened() const; |
RyoheiHagimoto | 0:0e0631af0305 | 378 | |
RyoheiHagimoto | 0:0e0631af0305 | 379 | /** @brief Closes the file and releases all the memory buffers. |
RyoheiHagimoto | 0:0e0631af0305 | 380 | |
RyoheiHagimoto | 0:0e0631af0305 | 381 | Call this method after all I/O operations with the storage are finished. |
RyoheiHagimoto | 0:0e0631af0305 | 382 | */ |
RyoheiHagimoto | 0:0e0631af0305 | 383 | CV_WRAP virtual void release(); |
RyoheiHagimoto | 0:0e0631af0305 | 384 | |
RyoheiHagimoto | 0:0e0631af0305 | 385 | /** @brief Closes the file and releases all the memory buffers. |
RyoheiHagimoto | 0:0e0631af0305 | 386 | |
RyoheiHagimoto | 0:0e0631af0305 | 387 | Call this method after all I/O operations with the storage are finished. If the storage was |
RyoheiHagimoto | 0:0e0631af0305 | 388 | opened for writing data and FileStorage::WRITE was specified |
RyoheiHagimoto | 0:0e0631af0305 | 389 | */ |
RyoheiHagimoto | 0:0e0631af0305 | 390 | CV_WRAP virtual String releaseAndGetString(); |
RyoheiHagimoto | 0:0e0631af0305 | 391 | |
RyoheiHagimoto | 0:0e0631af0305 | 392 | /** @brief Returns the first element of the top-level mapping. |
RyoheiHagimoto | 0:0e0631af0305 | 393 | @returns The first element of the top-level mapping. |
RyoheiHagimoto | 0:0e0631af0305 | 394 | */ |
RyoheiHagimoto | 0:0e0631af0305 | 395 | CV_WRAP FileNode getFirstTopLevelNode() const; |
RyoheiHagimoto | 0:0e0631af0305 | 396 | |
RyoheiHagimoto | 0:0e0631af0305 | 397 | /** @brief Returns the top-level mapping |
RyoheiHagimoto | 0:0e0631af0305 | 398 | @param streamidx Zero-based index of the stream. In most cases there is only one stream in the file. |
RyoheiHagimoto | 0:0e0631af0305 | 399 | However, YAML supports multiple streams and so there can be several. |
RyoheiHagimoto | 0:0e0631af0305 | 400 | @returns The top-level mapping. |
RyoheiHagimoto | 0:0e0631af0305 | 401 | */ |
RyoheiHagimoto | 0:0e0631af0305 | 402 | CV_WRAP FileNode root(int streamidx=0) const; |
RyoheiHagimoto | 0:0e0631af0305 | 403 | |
RyoheiHagimoto | 0:0e0631af0305 | 404 | /** @brief Returns the specified element of the top-level mapping. |
RyoheiHagimoto | 0:0e0631af0305 | 405 | @param nodename Name of the file node. |
RyoheiHagimoto | 0:0e0631af0305 | 406 | @returns Node with the given name. |
RyoheiHagimoto | 0:0e0631af0305 | 407 | */ |
RyoheiHagimoto | 0:0e0631af0305 | 408 | FileNode operator[](const String& nodename) const; |
RyoheiHagimoto | 0:0e0631af0305 | 409 | |
RyoheiHagimoto | 0:0e0631af0305 | 410 | /** @overload */ |
RyoheiHagimoto | 0:0e0631af0305 | 411 | CV_WRAP_AS(getNode) FileNode operator[](const char* nodename) const; |
RyoheiHagimoto | 0:0e0631af0305 | 412 | |
RyoheiHagimoto | 0:0e0631af0305 | 413 | /** @brief Returns the obsolete C FileStorage structure. |
RyoheiHagimoto | 0:0e0631af0305 | 414 | @returns Pointer to the underlying C FileStorage structure |
RyoheiHagimoto | 0:0e0631af0305 | 415 | */ |
RyoheiHagimoto | 0:0e0631af0305 | 416 | CvFileStorage* operator *() { return fs.get(); } |
RyoheiHagimoto | 0:0e0631af0305 | 417 | |
RyoheiHagimoto | 0:0e0631af0305 | 418 | /** @overload */ |
RyoheiHagimoto | 0:0e0631af0305 | 419 | const CvFileStorage* operator *() const { return fs.get(); } |
RyoheiHagimoto | 0:0e0631af0305 | 420 | |
RyoheiHagimoto | 0:0e0631af0305 | 421 | /** @brief Writes multiple numbers. |
RyoheiHagimoto | 0:0e0631af0305 | 422 | |
RyoheiHagimoto | 0:0e0631af0305 | 423 | Writes one or more numbers of the specified format to the currently written structure. Usually it is |
RyoheiHagimoto | 0:0e0631af0305 | 424 | more convenient to use operator `<<` instead of this method. |
RyoheiHagimoto | 0:0e0631af0305 | 425 | @param fmt Specification of each array element, see @ref format_spec "format specification" |
RyoheiHagimoto | 0:0e0631af0305 | 426 | @param vec Pointer to the written array. |
RyoheiHagimoto | 0:0e0631af0305 | 427 | @param len Number of the uchar elements to write. |
RyoheiHagimoto | 0:0e0631af0305 | 428 | */ |
RyoheiHagimoto | 0:0e0631af0305 | 429 | void writeRaw( const String& fmt, const uchar* vec, size_t len ); |
RyoheiHagimoto | 0:0e0631af0305 | 430 | |
RyoheiHagimoto | 0:0e0631af0305 | 431 | /** @brief Writes the registered C structure (CvMat, CvMatND, CvSeq). |
RyoheiHagimoto | 0:0e0631af0305 | 432 | @param name Name of the written object. |
RyoheiHagimoto | 0:0e0631af0305 | 433 | @param obj Pointer to the object. |
RyoheiHagimoto | 0:0e0631af0305 | 434 | @see ocvWrite for details. |
RyoheiHagimoto | 0:0e0631af0305 | 435 | */ |
RyoheiHagimoto | 0:0e0631af0305 | 436 | void writeObj( const String& name, const void* obj ); |
RyoheiHagimoto | 0:0e0631af0305 | 437 | |
RyoheiHagimoto | 0:0e0631af0305 | 438 | /** |
RyoheiHagimoto | 0:0e0631af0305 | 439 | * @brief Simplified writing API to use with bindings. |
RyoheiHagimoto | 0:0e0631af0305 | 440 | * @param name Name of the written object |
RyoheiHagimoto | 0:0e0631af0305 | 441 | * @param val Value of the written object |
RyoheiHagimoto | 0:0e0631af0305 | 442 | */ |
RyoheiHagimoto | 0:0e0631af0305 | 443 | CV_WRAP void write(const String& name, double val); |
RyoheiHagimoto | 0:0e0631af0305 | 444 | /// @overload |
RyoheiHagimoto | 0:0e0631af0305 | 445 | CV_WRAP void write(const String& name, const String& val); |
RyoheiHagimoto | 0:0e0631af0305 | 446 | /// @overload |
RyoheiHagimoto | 0:0e0631af0305 | 447 | CV_WRAP void write(const String& name, InputArray val); |
RyoheiHagimoto | 0:0e0631af0305 | 448 | |
RyoheiHagimoto | 0:0e0631af0305 | 449 | /** @brief Writes a comment. |
RyoheiHagimoto | 0:0e0631af0305 | 450 | |
RyoheiHagimoto | 0:0e0631af0305 | 451 | The function writes a comment into file storage. The comments are skipped when the storage is read. |
RyoheiHagimoto | 0:0e0631af0305 | 452 | @param comment The written comment, single-line or multi-line |
RyoheiHagimoto | 0:0e0631af0305 | 453 | @param append If true, the function tries to put the comment at the end of current line. |
RyoheiHagimoto | 0:0e0631af0305 | 454 | Else if the comment is multi-line, or if it does not fit at the end of the current |
RyoheiHagimoto | 0:0e0631af0305 | 455 | line, the comment starts a new line. |
RyoheiHagimoto | 0:0e0631af0305 | 456 | */ |
RyoheiHagimoto | 0:0e0631af0305 | 457 | CV_WRAP void writeComment(const String& comment, bool append = false); |
RyoheiHagimoto | 0:0e0631af0305 | 458 | |
RyoheiHagimoto | 0:0e0631af0305 | 459 | /** @brief Returns the normalized object name for the specified name of a file. |
RyoheiHagimoto | 0:0e0631af0305 | 460 | @param filename Name of a file |
RyoheiHagimoto | 0:0e0631af0305 | 461 | @returns The normalized object name. |
RyoheiHagimoto | 0:0e0631af0305 | 462 | */ |
RyoheiHagimoto | 0:0e0631af0305 | 463 | static String getDefaultObjectName(const String& filename); |
RyoheiHagimoto | 0:0e0631af0305 | 464 | |
RyoheiHagimoto | 0:0e0631af0305 | 465 | Ptr<CvFileStorage> fs; //!< the underlying C FileStorage structure |
RyoheiHagimoto | 0:0e0631af0305 | 466 | String elname; //!< the currently written element |
RyoheiHagimoto | 0:0e0631af0305 | 467 | std::vector<char> structs; //!< the stack of written structures |
RyoheiHagimoto | 0:0e0631af0305 | 468 | int state; //!< the writer state |
RyoheiHagimoto | 0:0e0631af0305 | 469 | }; |
RyoheiHagimoto | 0:0e0631af0305 | 470 | |
RyoheiHagimoto | 0:0e0631af0305 | 471 | template<> CV_EXPORTS void DefaultDeleter<CvFileStorage>::operator ()(CvFileStorage* obj) const; |
RyoheiHagimoto | 0:0e0631af0305 | 472 | |
RyoheiHagimoto | 0:0e0631af0305 | 473 | /** @brief File Storage Node class. |
RyoheiHagimoto | 0:0e0631af0305 | 474 | |
RyoheiHagimoto | 0:0e0631af0305 | 475 | The node is used to store each and every element of the file storage opened for reading. When |
RyoheiHagimoto | 0:0e0631af0305 | 476 | XML/YAML file is read, it is first parsed and stored in the memory as a hierarchical collection of |
RyoheiHagimoto | 0:0e0631af0305 | 477 | nodes. Each node can be a “leaf” that is contain a single number or a string, or be a collection of |
RyoheiHagimoto | 0:0e0631af0305 | 478 | other nodes. There can be named collections (mappings) where each element has a name and it is |
RyoheiHagimoto | 0:0e0631af0305 | 479 | accessed by a name, and ordered collections (sequences) where elements do not have names but rather |
RyoheiHagimoto | 0:0e0631af0305 | 480 | accessed by index. Type of the file node can be determined using FileNode::type method. |
RyoheiHagimoto | 0:0e0631af0305 | 481 | |
RyoheiHagimoto | 0:0e0631af0305 | 482 | Note that file nodes are only used for navigating file storages opened for reading. When a file |
RyoheiHagimoto | 0:0e0631af0305 | 483 | storage is opened for writing, no data is stored in memory after it is written. |
RyoheiHagimoto | 0:0e0631af0305 | 484 | */ |
RyoheiHagimoto | 0:0e0631af0305 | 485 | class CV_EXPORTS_W_SIMPLE FileNode |
RyoheiHagimoto | 0:0e0631af0305 | 486 | { |
RyoheiHagimoto | 0:0e0631af0305 | 487 | public: |
RyoheiHagimoto | 0:0e0631af0305 | 488 | //! type of the file storage node |
RyoheiHagimoto | 0:0e0631af0305 | 489 | enum Type |
RyoheiHagimoto | 0:0e0631af0305 | 490 | { |
RyoheiHagimoto | 0:0e0631af0305 | 491 | NONE = 0, //!< empty node |
RyoheiHagimoto | 0:0e0631af0305 | 492 | INT = 1, //!< an integer |
RyoheiHagimoto | 0:0e0631af0305 | 493 | REAL = 2, //!< floating-point number |
RyoheiHagimoto | 0:0e0631af0305 | 494 | FLOAT = REAL, //!< synonym or REAL |
RyoheiHagimoto | 0:0e0631af0305 | 495 | STR = 3, //!< text string in UTF-8 encoding |
RyoheiHagimoto | 0:0e0631af0305 | 496 | STRING = STR, //!< synonym for STR |
RyoheiHagimoto | 0:0e0631af0305 | 497 | REF = 4, //!< integer of size size_t. Typically used for storing complex dynamic structures where some elements reference the others |
RyoheiHagimoto | 0:0e0631af0305 | 498 | SEQ = 5, //!< sequence |
RyoheiHagimoto | 0:0e0631af0305 | 499 | MAP = 6, //!< mapping |
RyoheiHagimoto | 0:0e0631af0305 | 500 | TYPE_MASK = 7, |
RyoheiHagimoto | 0:0e0631af0305 | 501 | FLOW = 8, //!< compact representation of a sequence or mapping. Used only by YAML writer |
RyoheiHagimoto | 0:0e0631af0305 | 502 | USER = 16, //!< a registered object (e.g. a matrix) |
RyoheiHagimoto | 0:0e0631af0305 | 503 | EMPTY = 32, //!< empty structure (sequence or mapping) |
RyoheiHagimoto | 0:0e0631af0305 | 504 | NAMED = 64 //!< the node has a name (i.e. it is element of a mapping) |
RyoheiHagimoto | 0:0e0631af0305 | 505 | }; |
RyoheiHagimoto | 0:0e0631af0305 | 506 | /** @brief The constructors. |
RyoheiHagimoto | 0:0e0631af0305 | 507 | |
RyoheiHagimoto | 0:0e0631af0305 | 508 | These constructors are used to create a default file node, construct it from obsolete structures or |
RyoheiHagimoto | 0:0e0631af0305 | 509 | from the another file node. |
RyoheiHagimoto | 0:0e0631af0305 | 510 | */ |
RyoheiHagimoto | 0:0e0631af0305 | 511 | CV_WRAP FileNode(); |
RyoheiHagimoto | 0:0e0631af0305 | 512 | |
RyoheiHagimoto | 0:0e0631af0305 | 513 | /** @overload |
RyoheiHagimoto | 0:0e0631af0305 | 514 | @param fs Pointer to the obsolete file storage structure. |
RyoheiHagimoto | 0:0e0631af0305 | 515 | @param node File node to be used as initialization for the created file node. |
RyoheiHagimoto | 0:0e0631af0305 | 516 | */ |
RyoheiHagimoto | 0:0e0631af0305 | 517 | FileNode(const CvFileStorage* fs, const CvFileNode* node); |
RyoheiHagimoto | 0:0e0631af0305 | 518 | |
RyoheiHagimoto | 0:0e0631af0305 | 519 | /** @overload |
RyoheiHagimoto | 0:0e0631af0305 | 520 | @param node File node to be used as initialization for the created file node. |
RyoheiHagimoto | 0:0e0631af0305 | 521 | */ |
RyoheiHagimoto | 0:0e0631af0305 | 522 | FileNode(const FileNode& node); |
RyoheiHagimoto | 0:0e0631af0305 | 523 | |
RyoheiHagimoto | 0:0e0631af0305 | 524 | /** @brief Returns element of a mapping node or a sequence node. |
RyoheiHagimoto | 0:0e0631af0305 | 525 | @param nodename Name of an element in the mapping node. |
RyoheiHagimoto | 0:0e0631af0305 | 526 | @returns Returns the element with the given identifier. |
RyoheiHagimoto | 0:0e0631af0305 | 527 | */ |
RyoheiHagimoto | 0:0e0631af0305 | 528 | FileNode operator[](const String& nodename) const; |
RyoheiHagimoto | 0:0e0631af0305 | 529 | |
RyoheiHagimoto | 0:0e0631af0305 | 530 | /** @overload |
RyoheiHagimoto | 0:0e0631af0305 | 531 | @param nodename Name of an element in the mapping node. |
RyoheiHagimoto | 0:0e0631af0305 | 532 | */ |
RyoheiHagimoto | 0:0e0631af0305 | 533 | CV_WRAP_AS(getNode) FileNode operator[](const char* nodename) const; |
RyoheiHagimoto | 0:0e0631af0305 | 534 | |
RyoheiHagimoto | 0:0e0631af0305 | 535 | /** @overload |
RyoheiHagimoto | 0:0e0631af0305 | 536 | @param i Index of an element in the sequence node. |
RyoheiHagimoto | 0:0e0631af0305 | 537 | */ |
RyoheiHagimoto | 0:0e0631af0305 | 538 | CV_WRAP_AS(at) FileNode operator[](int i) const; |
RyoheiHagimoto | 0:0e0631af0305 | 539 | |
RyoheiHagimoto | 0:0e0631af0305 | 540 | /** @brief Returns type of the node. |
RyoheiHagimoto | 0:0e0631af0305 | 541 | @returns Type of the node. See FileNode::Type |
RyoheiHagimoto | 0:0e0631af0305 | 542 | */ |
RyoheiHagimoto | 0:0e0631af0305 | 543 | CV_WRAP int type() const; |
RyoheiHagimoto | 0:0e0631af0305 | 544 | |
RyoheiHagimoto | 0:0e0631af0305 | 545 | //! returns true if the node is empty |
RyoheiHagimoto | 0:0e0631af0305 | 546 | CV_WRAP bool empty() const; |
RyoheiHagimoto | 0:0e0631af0305 | 547 | //! returns true if the node is a "none" object |
RyoheiHagimoto | 0:0e0631af0305 | 548 | CV_WRAP bool isNone() const; |
RyoheiHagimoto | 0:0e0631af0305 | 549 | //! returns true if the node is a sequence |
RyoheiHagimoto | 0:0e0631af0305 | 550 | CV_WRAP bool isSeq() const; |
RyoheiHagimoto | 0:0e0631af0305 | 551 | //! returns true if the node is a mapping |
RyoheiHagimoto | 0:0e0631af0305 | 552 | CV_WRAP bool isMap() const; |
RyoheiHagimoto | 0:0e0631af0305 | 553 | //! returns true if the node is an integer |
RyoheiHagimoto | 0:0e0631af0305 | 554 | CV_WRAP bool isInt() const; |
RyoheiHagimoto | 0:0e0631af0305 | 555 | //! returns true if the node is a floating-point number |
RyoheiHagimoto | 0:0e0631af0305 | 556 | CV_WRAP bool isReal() const; |
RyoheiHagimoto | 0:0e0631af0305 | 557 | //! returns true if the node is a text string |
RyoheiHagimoto | 0:0e0631af0305 | 558 | CV_WRAP bool isString() const; |
RyoheiHagimoto | 0:0e0631af0305 | 559 | //! returns true if the node has a name |
RyoheiHagimoto | 0:0e0631af0305 | 560 | CV_WRAP bool isNamed() const; |
RyoheiHagimoto | 0:0e0631af0305 | 561 | //! returns the node name or an empty string if the node is nameless |
RyoheiHagimoto | 0:0e0631af0305 | 562 | CV_WRAP String name() const; |
RyoheiHagimoto | 0:0e0631af0305 | 563 | //! returns the number of elements in the node, if it is a sequence or mapping, or 1 otherwise. |
RyoheiHagimoto | 0:0e0631af0305 | 564 | CV_WRAP size_t size() const; |
RyoheiHagimoto | 0:0e0631af0305 | 565 | //! returns the node content as an integer. If the node stores floating-point number, it is rounded. |
RyoheiHagimoto | 0:0e0631af0305 | 566 | operator int() const; |
RyoheiHagimoto | 0:0e0631af0305 | 567 | //! returns the node content as float |
RyoheiHagimoto | 0:0e0631af0305 | 568 | operator float() const; |
RyoheiHagimoto | 0:0e0631af0305 | 569 | //! returns the node content as double |
RyoheiHagimoto | 0:0e0631af0305 | 570 | operator double() const; |
RyoheiHagimoto | 0:0e0631af0305 | 571 | //! returns the node content as text string |
RyoheiHagimoto | 0:0e0631af0305 | 572 | operator String() const; |
RyoheiHagimoto | 0:0e0631af0305 | 573 | #ifndef OPENCV_NOSTL |
RyoheiHagimoto | 0:0e0631af0305 | 574 | operator std::string() const; |
RyoheiHagimoto | 0:0e0631af0305 | 575 | #endif |
RyoheiHagimoto | 0:0e0631af0305 | 576 | |
RyoheiHagimoto | 0:0e0631af0305 | 577 | //! returns pointer to the underlying file node |
RyoheiHagimoto | 0:0e0631af0305 | 578 | CvFileNode* operator *(); |
RyoheiHagimoto | 0:0e0631af0305 | 579 | //! returns pointer to the underlying file node |
RyoheiHagimoto | 0:0e0631af0305 | 580 | const CvFileNode* operator* () const; |
RyoheiHagimoto | 0:0e0631af0305 | 581 | |
RyoheiHagimoto | 0:0e0631af0305 | 582 | //! returns iterator pointing to the first node element |
RyoheiHagimoto | 0:0e0631af0305 | 583 | FileNodeIterator begin() const; |
RyoheiHagimoto | 0:0e0631af0305 | 584 | //! returns iterator pointing to the element following the last node element |
RyoheiHagimoto | 0:0e0631af0305 | 585 | FileNodeIterator end() const; |
RyoheiHagimoto | 0:0e0631af0305 | 586 | |
RyoheiHagimoto | 0:0e0631af0305 | 587 | /** @brief Reads node elements to the buffer with the specified format. |
RyoheiHagimoto | 0:0e0631af0305 | 588 | |
RyoheiHagimoto | 0:0e0631af0305 | 589 | Usually it is more convenient to use operator `>>` instead of this method. |
RyoheiHagimoto | 0:0e0631af0305 | 590 | @param fmt Specification of each array element. See @ref format_spec "format specification" |
RyoheiHagimoto | 0:0e0631af0305 | 591 | @param vec Pointer to the destination array. |
RyoheiHagimoto | 0:0e0631af0305 | 592 | @param len Number of elements to read. If it is greater than number of remaining elements then all |
RyoheiHagimoto | 0:0e0631af0305 | 593 | of them will be read. |
RyoheiHagimoto | 0:0e0631af0305 | 594 | */ |
RyoheiHagimoto | 0:0e0631af0305 | 595 | void readRaw( const String& fmt, uchar* vec, size_t len ) const; |
RyoheiHagimoto | 0:0e0631af0305 | 596 | |
RyoheiHagimoto | 0:0e0631af0305 | 597 | //! reads the registered object and returns pointer to it |
RyoheiHagimoto | 0:0e0631af0305 | 598 | void* readObj() const; |
RyoheiHagimoto | 0:0e0631af0305 | 599 | |
RyoheiHagimoto | 0:0e0631af0305 | 600 | //! Simplified reading API to use with bindings. |
RyoheiHagimoto | 0:0e0631af0305 | 601 | CV_WRAP double real() const; |
RyoheiHagimoto | 0:0e0631af0305 | 602 | //! Simplified reading API to use with bindings. |
RyoheiHagimoto | 0:0e0631af0305 | 603 | CV_WRAP String string() const; |
RyoheiHagimoto | 0:0e0631af0305 | 604 | //! Simplified reading API to use with bindings. |
RyoheiHagimoto | 0:0e0631af0305 | 605 | CV_WRAP Mat mat() const; |
RyoheiHagimoto | 0:0e0631af0305 | 606 | |
RyoheiHagimoto | 0:0e0631af0305 | 607 | // do not use wrapper pointer classes for better efficiency |
RyoheiHagimoto | 0:0e0631af0305 | 608 | const CvFileStorage* fs; |
RyoheiHagimoto | 0:0e0631af0305 | 609 | const CvFileNode* node; |
RyoheiHagimoto | 0:0e0631af0305 | 610 | }; |
RyoheiHagimoto | 0:0e0631af0305 | 611 | |
RyoheiHagimoto | 0:0e0631af0305 | 612 | |
RyoheiHagimoto | 0:0e0631af0305 | 613 | /** @brief used to iterate through sequences and mappings. |
RyoheiHagimoto | 0:0e0631af0305 | 614 | |
RyoheiHagimoto | 0:0e0631af0305 | 615 | A standard STL notation, with node.begin(), node.end() denoting the beginning and the end of a |
RyoheiHagimoto | 0:0e0631af0305 | 616 | sequence, stored in node. See the data reading sample in the beginning of the section. |
RyoheiHagimoto | 0:0e0631af0305 | 617 | */ |
RyoheiHagimoto | 0:0e0631af0305 | 618 | class CV_EXPORTS FileNodeIterator |
RyoheiHagimoto | 0:0e0631af0305 | 619 | { |
RyoheiHagimoto | 0:0e0631af0305 | 620 | public: |
RyoheiHagimoto | 0:0e0631af0305 | 621 | /** @brief The constructors. |
RyoheiHagimoto | 0:0e0631af0305 | 622 | |
RyoheiHagimoto | 0:0e0631af0305 | 623 | These constructors are used to create a default iterator, set it to specific element in a file node |
RyoheiHagimoto | 0:0e0631af0305 | 624 | or construct it from another iterator. |
RyoheiHagimoto | 0:0e0631af0305 | 625 | */ |
RyoheiHagimoto | 0:0e0631af0305 | 626 | FileNodeIterator(); |
RyoheiHagimoto | 0:0e0631af0305 | 627 | |
RyoheiHagimoto | 0:0e0631af0305 | 628 | /** @overload |
RyoheiHagimoto | 0:0e0631af0305 | 629 | @param fs File storage for the iterator. |
RyoheiHagimoto | 0:0e0631af0305 | 630 | @param node File node for the iterator. |
RyoheiHagimoto | 0:0e0631af0305 | 631 | @param ofs Index of the element in the node. The created iterator will point to this element. |
RyoheiHagimoto | 0:0e0631af0305 | 632 | */ |
RyoheiHagimoto | 0:0e0631af0305 | 633 | FileNodeIterator(const CvFileStorage* fs, const CvFileNode* node, size_t ofs=0); |
RyoheiHagimoto | 0:0e0631af0305 | 634 | |
RyoheiHagimoto | 0:0e0631af0305 | 635 | /** @overload |
RyoheiHagimoto | 0:0e0631af0305 | 636 | @param it Iterator to be used as initialization for the created iterator. |
RyoheiHagimoto | 0:0e0631af0305 | 637 | */ |
RyoheiHagimoto | 0:0e0631af0305 | 638 | FileNodeIterator(const FileNodeIterator& it); |
RyoheiHagimoto | 0:0e0631af0305 | 639 | |
RyoheiHagimoto | 0:0e0631af0305 | 640 | //! returns the currently observed element |
RyoheiHagimoto | 0:0e0631af0305 | 641 | FileNode operator *() const; |
RyoheiHagimoto | 0:0e0631af0305 | 642 | //! accesses the currently observed element methods |
RyoheiHagimoto | 0:0e0631af0305 | 643 | FileNode operator ->() const; |
RyoheiHagimoto | 0:0e0631af0305 | 644 | |
RyoheiHagimoto | 0:0e0631af0305 | 645 | //! moves iterator to the next node |
RyoheiHagimoto | 0:0e0631af0305 | 646 | FileNodeIterator& operator ++ (); |
RyoheiHagimoto | 0:0e0631af0305 | 647 | //! moves iterator to the next node |
RyoheiHagimoto | 0:0e0631af0305 | 648 | FileNodeIterator operator ++ (int); |
RyoheiHagimoto | 0:0e0631af0305 | 649 | //! moves iterator to the previous node |
RyoheiHagimoto | 0:0e0631af0305 | 650 | FileNodeIterator& operator -- (); |
RyoheiHagimoto | 0:0e0631af0305 | 651 | //! moves iterator to the previous node |
RyoheiHagimoto | 0:0e0631af0305 | 652 | FileNodeIterator operator -- (int); |
RyoheiHagimoto | 0:0e0631af0305 | 653 | //! moves iterator forward by the specified offset (possibly negative) |
RyoheiHagimoto | 0:0e0631af0305 | 654 | FileNodeIterator& operator += (int ofs); |
RyoheiHagimoto | 0:0e0631af0305 | 655 | //! moves iterator backward by the specified offset (possibly negative) |
RyoheiHagimoto | 0:0e0631af0305 | 656 | FileNodeIterator& operator -= (int ofs); |
RyoheiHagimoto | 0:0e0631af0305 | 657 | |
RyoheiHagimoto | 0:0e0631af0305 | 658 | /** @brief Reads node elements to the buffer with the specified format. |
RyoheiHagimoto | 0:0e0631af0305 | 659 | |
RyoheiHagimoto | 0:0e0631af0305 | 660 | Usually it is more convenient to use operator `>>` instead of this method. |
RyoheiHagimoto | 0:0e0631af0305 | 661 | @param fmt Specification of each array element. See @ref format_spec "format specification" |
RyoheiHagimoto | 0:0e0631af0305 | 662 | @param vec Pointer to the destination array. |
RyoheiHagimoto | 0:0e0631af0305 | 663 | @param maxCount Number of elements to read. If it is greater than number of remaining elements then |
RyoheiHagimoto | 0:0e0631af0305 | 664 | all of them will be read. |
RyoheiHagimoto | 0:0e0631af0305 | 665 | */ |
RyoheiHagimoto | 0:0e0631af0305 | 666 | FileNodeIterator& readRaw( const String& fmt, uchar* vec, |
RyoheiHagimoto | 0:0e0631af0305 | 667 | size_t maxCount=(size_t)INT_MAX ); |
RyoheiHagimoto | 0:0e0631af0305 | 668 | |
RyoheiHagimoto | 0:0e0631af0305 | 669 | struct SeqReader |
RyoheiHagimoto | 0:0e0631af0305 | 670 | { |
RyoheiHagimoto | 0:0e0631af0305 | 671 | int header_size; |
RyoheiHagimoto | 0:0e0631af0305 | 672 | void* seq; /* sequence, beign read; CvSeq */ |
RyoheiHagimoto | 0:0e0631af0305 | 673 | void* block; /* current block; CvSeqBlock */ |
RyoheiHagimoto | 0:0e0631af0305 | 674 | schar* ptr; /* pointer to element be read next */ |
RyoheiHagimoto | 0:0e0631af0305 | 675 | schar* block_min; /* pointer to the beginning of block */ |
RyoheiHagimoto | 0:0e0631af0305 | 676 | schar* block_max; /* pointer to the end of block */ |
RyoheiHagimoto | 0:0e0631af0305 | 677 | int delta_index;/* = seq->first->start_index */ |
RyoheiHagimoto | 0:0e0631af0305 | 678 | schar* prev_elem; /* pointer to previous element */ |
RyoheiHagimoto | 0:0e0631af0305 | 679 | }; |
RyoheiHagimoto | 0:0e0631af0305 | 680 | |
RyoheiHagimoto | 0:0e0631af0305 | 681 | const CvFileStorage* fs; |
RyoheiHagimoto | 0:0e0631af0305 | 682 | const CvFileNode* container; |
RyoheiHagimoto | 0:0e0631af0305 | 683 | SeqReader reader; |
RyoheiHagimoto | 0:0e0631af0305 | 684 | size_t remaining; |
RyoheiHagimoto | 0:0e0631af0305 | 685 | }; |
RyoheiHagimoto | 0:0e0631af0305 | 686 | |
RyoheiHagimoto | 0:0e0631af0305 | 687 | //! @} core_xml |
RyoheiHagimoto | 0:0e0631af0305 | 688 | |
RyoheiHagimoto | 0:0e0631af0305 | 689 | /////////////////// XML & YAML I/O implementation ////////////////// |
RyoheiHagimoto | 0:0e0631af0305 | 690 | |
RyoheiHagimoto | 0:0e0631af0305 | 691 | //! @relates cv::FileStorage |
RyoheiHagimoto | 0:0e0631af0305 | 692 | //! @{ |
RyoheiHagimoto | 0:0e0631af0305 | 693 | |
RyoheiHagimoto | 0:0e0631af0305 | 694 | CV_EXPORTS void write( FileStorage& fs, const String& name, int value ); |
RyoheiHagimoto | 0:0e0631af0305 | 695 | CV_EXPORTS void write( FileStorage& fs, const String& name, float value ); |
RyoheiHagimoto | 0:0e0631af0305 | 696 | CV_EXPORTS void write( FileStorage& fs, const String& name, double value ); |
RyoheiHagimoto | 0:0e0631af0305 | 697 | CV_EXPORTS void write( FileStorage& fs, const String& name, const String& value ); |
RyoheiHagimoto | 0:0e0631af0305 | 698 | CV_EXPORTS void write( FileStorage& fs, const String& name, const Mat& value ); |
RyoheiHagimoto | 0:0e0631af0305 | 699 | CV_EXPORTS void write( FileStorage& fs, const String& name, const SparseMat& value ); |
RyoheiHagimoto | 0:0e0631af0305 | 700 | CV_EXPORTS void write( FileStorage& fs, const String& name, const std::vector<KeyPoint>& value); |
RyoheiHagimoto | 0:0e0631af0305 | 701 | CV_EXPORTS void write( FileStorage& fs, const String& name, const std::vector<DMatch>& value); |
RyoheiHagimoto | 0:0e0631af0305 | 702 | |
RyoheiHagimoto | 0:0e0631af0305 | 703 | CV_EXPORTS void writeScalar( FileStorage& fs, int value ); |
RyoheiHagimoto | 0:0e0631af0305 | 704 | CV_EXPORTS void writeScalar( FileStorage& fs, float value ); |
RyoheiHagimoto | 0:0e0631af0305 | 705 | CV_EXPORTS void writeScalar( FileStorage& fs, double value ); |
RyoheiHagimoto | 0:0e0631af0305 | 706 | CV_EXPORTS void writeScalar( FileStorage& fs, const String& value ); |
RyoheiHagimoto | 0:0e0631af0305 | 707 | |
RyoheiHagimoto | 0:0e0631af0305 | 708 | //! @} |
RyoheiHagimoto | 0:0e0631af0305 | 709 | |
RyoheiHagimoto | 0:0e0631af0305 | 710 | //! @relates cv::FileNode |
RyoheiHagimoto | 0:0e0631af0305 | 711 | //! @{ |
RyoheiHagimoto | 0:0e0631af0305 | 712 | |
RyoheiHagimoto | 0:0e0631af0305 | 713 | CV_EXPORTS void read(const FileNode& node, int& value, int default_value); |
RyoheiHagimoto | 0:0e0631af0305 | 714 | CV_EXPORTS void read(const FileNode& node, float& value, float default_value); |
RyoheiHagimoto | 0:0e0631af0305 | 715 | CV_EXPORTS void read(const FileNode& node, double& value, double default_value); |
RyoheiHagimoto | 0:0e0631af0305 | 716 | CV_EXPORTS void read(const FileNode& node, String& value, const String& default_value); |
RyoheiHagimoto | 0:0e0631af0305 | 717 | CV_EXPORTS void read(const FileNode& node, Mat& mat, const Mat& default_mat = Mat() ); |
RyoheiHagimoto | 0:0e0631af0305 | 718 | CV_EXPORTS void read(const FileNode& node, SparseMat& mat, const SparseMat& default_mat = SparseMat() ); |
RyoheiHagimoto | 0:0e0631af0305 | 719 | CV_EXPORTS void read(const FileNode& node, std::vector<KeyPoint>& keypoints); |
RyoheiHagimoto | 0:0e0631af0305 | 720 | CV_EXPORTS void read(const FileNode& node, std::vector<DMatch>& matches); |
RyoheiHagimoto | 0:0e0631af0305 | 721 | |
RyoheiHagimoto | 0:0e0631af0305 | 722 | template<typename _Tp> static inline void read(const FileNode& node, Point_<_Tp>& value, const Point_<_Tp>& default_value) |
RyoheiHagimoto | 0:0e0631af0305 | 723 | { |
RyoheiHagimoto | 0:0e0631af0305 | 724 | std::vector<_Tp> temp; FileNodeIterator it = node.begin(); it >> temp; |
RyoheiHagimoto | 0:0e0631af0305 | 725 | value = temp.size() != 2 ? default_value : Point_<_Tp>(saturate_cast<_Tp>(temp[0]), saturate_cast<_Tp>(temp[1])); |
RyoheiHagimoto | 0:0e0631af0305 | 726 | } |
RyoheiHagimoto | 0:0e0631af0305 | 727 | |
RyoheiHagimoto | 0:0e0631af0305 | 728 | template<typename _Tp> static inline void read(const FileNode& node, Point3_<_Tp>& value, const Point3_<_Tp>& default_value) |
RyoheiHagimoto | 0:0e0631af0305 | 729 | { |
RyoheiHagimoto | 0:0e0631af0305 | 730 | std::vector<_Tp> temp; FileNodeIterator it = node.begin(); it >> temp; |
RyoheiHagimoto | 0:0e0631af0305 | 731 | value = temp.size() != 3 ? default_value : Point3_<_Tp>(saturate_cast<_Tp>(temp[0]), saturate_cast<_Tp>(temp[1]), |
RyoheiHagimoto | 0:0e0631af0305 | 732 | saturate_cast<_Tp>(temp[2])); |
RyoheiHagimoto | 0:0e0631af0305 | 733 | } |
RyoheiHagimoto | 0:0e0631af0305 | 734 | |
RyoheiHagimoto | 0:0e0631af0305 | 735 | template<typename _Tp> static inline void read(const FileNode& node, Size_<_Tp>& value, const Size_<_Tp>& default_value) |
RyoheiHagimoto | 0:0e0631af0305 | 736 | { |
RyoheiHagimoto | 0:0e0631af0305 | 737 | std::vector<_Tp> temp; FileNodeIterator it = node.begin(); it >> temp; |
RyoheiHagimoto | 0:0e0631af0305 | 738 | value = temp.size() != 2 ? default_value : Size_<_Tp>(saturate_cast<_Tp>(temp[0]), saturate_cast<_Tp>(temp[1])); |
RyoheiHagimoto | 0:0e0631af0305 | 739 | } |
RyoheiHagimoto | 0:0e0631af0305 | 740 | |
RyoheiHagimoto | 0:0e0631af0305 | 741 | template<typename _Tp> static inline void read(const FileNode& node, Complex<_Tp>& value, const Complex<_Tp>& default_value) |
RyoheiHagimoto | 0:0e0631af0305 | 742 | { |
RyoheiHagimoto | 0:0e0631af0305 | 743 | std::vector<_Tp> temp; FileNodeIterator it = node.begin(); it >> temp; |
RyoheiHagimoto | 0:0e0631af0305 | 744 | value = temp.size() != 2 ? default_value : Complex<_Tp>(saturate_cast<_Tp>(temp[0]), saturate_cast<_Tp>(temp[1])); |
RyoheiHagimoto | 0:0e0631af0305 | 745 | } |
RyoheiHagimoto | 0:0e0631af0305 | 746 | |
RyoheiHagimoto | 0:0e0631af0305 | 747 | template<typename _Tp> static inline void read(const FileNode& node, Rect_<_Tp>& value, const Rect_<_Tp>& default_value) |
RyoheiHagimoto | 0:0e0631af0305 | 748 | { |
RyoheiHagimoto | 0:0e0631af0305 | 749 | std::vector<_Tp> temp; FileNodeIterator it = node.begin(); it >> temp; |
RyoheiHagimoto | 0:0e0631af0305 | 750 | value = temp.size() != 4 ? default_value : Rect_<_Tp>(saturate_cast<_Tp>(temp[0]), saturate_cast<_Tp>(temp[1]), |
RyoheiHagimoto | 0:0e0631af0305 | 751 | saturate_cast<_Tp>(temp[2]), saturate_cast<_Tp>(temp[3])); |
RyoheiHagimoto | 0:0e0631af0305 | 752 | } |
RyoheiHagimoto | 0:0e0631af0305 | 753 | |
RyoheiHagimoto | 0:0e0631af0305 | 754 | template<typename _Tp, int cn> static inline void read(const FileNode& node, Vec<_Tp, cn>& value, const Vec<_Tp, cn>& default_value) |
RyoheiHagimoto | 0:0e0631af0305 | 755 | { |
RyoheiHagimoto | 0:0e0631af0305 | 756 | std::vector<_Tp> temp; FileNodeIterator it = node.begin(); it >> temp; |
RyoheiHagimoto | 0:0e0631af0305 | 757 | value = temp.size() != cn ? default_value : Vec<_Tp, cn>(&temp[0]); |
RyoheiHagimoto | 0:0e0631af0305 | 758 | } |
RyoheiHagimoto | 0:0e0631af0305 | 759 | |
RyoheiHagimoto | 0:0e0631af0305 | 760 | template<typename _Tp> static inline void read(const FileNode& node, Scalar_<_Tp>& value, const Scalar_<_Tp>& default_value) |
RyoheiHagimoto | 0:0e0631af0305 | 761 | { |
RyoheiHagimoto | 0:0e0631af0305 | 762 | std::vector<_Tp> temp; FileNodeIterator it = node.begin(); it >> temp; |
RyoheiHagimoto | 0:0e0631af0305 | 763 | value = temp.size() != 4 ? default_value : Scalar_<_Tp>(saturate_cast<_Tp>(temp[0]), saturate_cast<_Tp>(temp[1]), |
RyoheiHagimoto | 0:0e0631af0305 | 764 | saturate_cast<_Tp>(temp[2]), saturate_cast<_Tp>(temp[3])); |
RyoheiHagimoto | 0:0e0631af0305 | 765 | } |
RyoheiHagimoto | 0:0e0631af0305 | 766 | |
RyoheiHagimoto | 0:0e0631af0305 | 767 | static inline void read(const FileNode& node, Range& value, const Range& default_value) |
RyoheiHagimoto | 0:0e0631af0305 | 768 | { |
RyoheiHagimoto | 0:0e0631af0305 | 769 | Point2i temp(value.start, value.end); const Point2i default_temp = Point2i(default_value.start, default_value.end); |
RyoheiHagimoto | 0:0e0631af0305 | 770 | read(node, temp, default_temp); |
RyoheiHagimoto | 0:0e0631af0305 | 771 | value.start = temp.x; value.end = temp.y; |
RyoheiHagimoto | 0:0e0631af0305 | 772 | } |
RyoheiHagimoto | 0:0e0631af0305 | 773 | |
RyoheiHagimoto | 0:0e0631af0305 | 774 | //! @} |
RyoheiHagimoto | 0:0e0631af0305 | 775 | |
RyoheiHagimoto | 0:0e0631af0305 | 776 | /** @brief Writes string to a file storage. |
RyoheiHagimoto | 0:0e0631af0305 | 777 | @relates cv::FileStorage |
RyoheiHagimoto | 0:0e0631af0305 | 778 | */ |
RyoheiHagimoto | 0:0e0631af0305 | 779 | CV_EXPORTS FileStorage& operator << (FileStorage& fs, const String& str); |
RyoheiHagimoto | 0:0e0631af0305 | 780 | |
RyoheiHagimoto | 0:0e0631af0305 | 781 | //! @cond IGNORED |
RyoheiHagimoto | 0:0e0631af0305 | 782 | |
RyoheiHagimoto | 0:0e0631af0305 | 783 | namespace internal |
RyoheiHagimoto | 0:0e0631af0305 | 784 | { |
RyoheiHagimoto | 0:0e0631af0305 | 785 | class CV_EXPORTS WriteStructContext |
RyoheiHagimoto | 0:0e0631af0305 | 786 | { |
RyoheiHagimoto | 0:0e0631af0305 | 787 | public: |
RyoheiHagimoto | 0:0e0631af0305 | 788 | WriteStructContext(FileStorage& _fs, const String& name, int flags, const String& typeName = String()); |
RyoheiHagimoto | 0:0e0631af0305 | 789 | ~WriteStructContext(); |
RyoheiHagimoto | 0:0e0631af0305 | 790 | private: |
RyoheiHagimoto | 0:0e0631af0305 | 791 | FileStorage* fs; |
RyoheiHagimoto | 0:0e0631af0305 | 792 | }; |
RyoheiHagimoto | 0:0e0631af0305 | 793 | |
RyoheiHagimoto | 0:0e0631af0305 | 794 | template<typename _Tp, int numflag> class VecWriterProxy |
RyoheiHagimoto | 0:0e0631af0305 | 795 | { |
RyoheiHagimoto | 0:0e0631af0305 | 796 | public: |
RyoheiHagimoto | 0:0e0631af0305 | 797 | VecWriterProxy( FileStorage* _fs ) : fs(_fs) {} |
RyoheiHagimoto | 0:0e0631af0305 | 798 | void operator()(const std::vector<_Tp>& vec) const |
RyoheiHagimoto | 0:0e0631af0305 | 799 | { |
RyoheiHagimoto | 0:0e0631af0305 | 800 | size_t count = vec.size(); |
RyoheiHagimoto | 0:0e0631af0305 | 801 | for (size_t i = 0; i < count; i++) |
RyoheiHagimoto | 0:0e0631af0305 | 802 | write(*fs, vec[i]); |
RyoheiHagimoto | 0:0e0631af0305 | 803 | } |
RyoheiHagimoto | 0:0e0631af0305 | 804 | private: |
RyoheiHagimoto | 0:0e0631af0305 | 805 | FileStorage* fs; |
RyoheiHagimoto | 0:0e0631af0305 | 806 | }; |
RyoheiHagimoto | 0:0e0631af0305 | 807 | |
RyoheiHagimoto | 0:0e0631af0305 | 808 | template<typename _Tp> class VecWriterProxy<_Tp, 1> |
RyoheiHagimoto | 0:0e0631af0305 | 809 | { |
RyoheiHagimoto | 0:0e0631af0305 | 810 | public: |
RyoheiHagimoto | 0:0e0631af0305 | 811 | VecWriterProxy( FileStorage* _fs ) : fs(_fs) {} |
RyoheiHagimoto | 0:0e0631af0305 | 812 | void operator()(const std::vector<_Tp>& vec) const |
RyoheiHagimoto | 0:0e0631af0305 | 813 | { |
RyoheiHagimoto | 0:0e0631af0305 | 814 | int _fmt = DataType<_Tp>::fmt; |
RyoheiHagimoto | 0:0e0631af0305 | 815 | char fmt[] = { (char)((_fmt >> 8) + '1'), (char)_fmt, '\0' }; |
RyoheiHagimoto | 0:0e0631af0305 | 816 | fs->writeRaw(fmt, !vec.empty() ? (uchar*)&vec[0] : 0, vec.size() * sizeof(_Tp)); |
RyoheiHagimoto | 0:0e0631af0305 | 817 | } |
RyoheiHagimoto | 0:0e0631af0305 | 818 | private: |
RyoheiHagimoto | 0:0e0631af0305 | 819 | FileStorage* fs; |
RyoheiHagimoto | 0:0e0631af0305 | 820 | }; |
RyoheiHagimoto | 0:0e0631af0305 | 821 | |
RyoheiHagimoto | 0:0e0631af0305 | 822 | template<typename _Tp, int numflag> class VecReaderProxy |
RyoheiHagimoto | 0:0e0631af0305 | 823 | { |
RyoheiHagimoto | 0:0e0631af0305 | 824 | public: |
RyoheiHagimoto | 0:0e0631af0305 | 825 | VecReaderProxy( FileNodeIterator* _it ) : it(_it) {} |
RyoheiHagimoto | 0:0e0631af0305 | 826 | void operator()(std::vector<_Tp>& vec, size_t count) const |
RyoheiHagimoto | 0:0e0631af0305 | 827 | { |
RyoheiHagimoto | 0:0e0631af0305 | 828 | count = std::min(count, it->remaining); |
RyoheiHagimoto | 0:0e0631af0305 | 829 | vec.resize(count); |
RyoheiHagimoto | 0:0e0631af0305 | 830 | for (size_t i = 0; i < count; i++, ++(*it)) |
RyoheiHagimoto | 0:0e0631af0305 | 831 | read(**it, vec[i], _Tp()); |
RyoheiHagimoto | 0:0e0631af0305 | 832 | } |
RyoheiHagimoto | 0:0e0631af0305 | 833 | private: |
RyoheiHagimoto | 0:0e0631af0305 | 834 | FileNodeIterator* it; |
RyoheiHagimoto | 0:0e0631af0305 | 835 | }; |
RyoheiHagimoto | 0:0e0631af0305 | 836 | |
RyoheiHagimoto | 0:0e0631af0305 | 837 | template<typename _Tp> class VecReaderProxy<_Tp, 1> |
RyoheiHagimoto | 0:0e0631af0305 | 838 | { |
RyoheiHagimoto | 0:0e0631af0305 | 839 | public: |
RyoheiHagimoto | 0:0e0631af0305 | 840 | VecReaderProxy( FileNodeIterator* _it ) : it(_it) {} |
RyoheiHagimoto | 0:0e0631af0305 | 841 | void operator()(std::vector<_Tp>& vec, size_t count) const |
RyoheiHagimoto | 0:0e0631af0305 | 842 | { |
RyoheiHagimoto | 0:0e0631af0305 | 843 | size_t remaining = it->remaining; |
RyoheiHagimoto | 0:0e0631af0305 | 844 | size_t cn = DataType<_Tp>::channels; |
RyoheiHagimoto | 0:0e0631af0305 | 845 | int _fmt = DataType<_Tp>::fmt; |
RyoheiHagimoto | 0:0e0631af0305 | 846 | char fmt[] = { (char)((_fmt >> 8)+'1'), (char)_fmt, '\0' }; |
RyoheiHagimoto | 0:0e0631af0305 | 847 | size_t remaining1 = remaining / cn; |
RyoheiHagimoto | 0:0e0631af0305 | 848 | count = count < remaining1 ? count : remaining1; |
RyoheiHagimoto | 0:0e0631af0305 | 849 | vec.resize(count); |
RyoheiHagimoto | 0:0e0631af0305 | 850 | it->readRaw(fmt, !vec.empty() ? (uchar*)&vec[0] : 0, count*sizeof(_Tp)); |
RyoheiHagimoto | 0:0e0631af0305 | 851 | } |
RyoheiHagimoto | 0:0e0631af0305 | 852 | private: |
RyoheiHagimoto | 0:0e0631af0305 | 853 | FileNodeIterator* it; |
RyoheiHagimoto | 0:0e0631af0305 | 854 | }; |
RyoheiHagimoto | 0:0e0631af0305 | 855 | |
RyoheiHagimoto | 0:0e0631af0305 | 856 | } // internal |
RyoheiHagimoto | 0:0e0631af0305 | 857 | |
RyoheiHagimoto | 0:0e0631af0305 | 858 | //! @endcond |
RyoheiHagimoto | 0:0e0631af0305 | 859 | |
RyoheiHagimoto | 0:0e0631af0305 | 860 | //! @relates cv::FileStorage |
RyoheiHagimoto | 0:0e0631af0305 | 861 | //! @{ |
RyoheiHagimoto | 0:0e0631af0305 | 862 | |
RyoheiHagimoto | 0:0e0631af0305 | 863 | template<typename _Tp> static inline |
RyoheiHagimoto | 0:0e0631af0305 | 864 | void write(FileStorage& fs, const _Tp& value) |
RyoheiHagimoto | 0:0e0631af0305 | 865 | { |
RyoheiHagimoto | 0:0e0631af0305 | 866 | write(fs, String(), value); |
RyoheiHagimoto | 0:0e0631af0305 | 867 | } |
RyoheiHagimoto | 0:0e0631af0305 | 868 | |
RyoheiHagimoto | 0:0e0631af0305 | 869 | template<> inline |
RyoheiHagimoto | 0:0e0631af0305 | 870 | void write( FileStorage& fs, const int& value ) |
RyoheiHagimoto | 0:0e0631af0305 | 871 | { |
RyoheiHagimoto | 0:0e0631af0305 | 872 | writeScalar(fs, value); |
RyoheiHagimoto | 0:0e0631af0305 | 873 | } |
RyoheiHagimoto | 0:0e0631af0305 | 874 | |
RyoheiHagimoto | 0:0e0631af0305 | 875 | template<> inline |
RyoheiHagimoto | 0:0e0631af0305 | 876 | void write( FileStorage& fs, const float& value ) |
RyoheiHagimoto | 0:0e0631af0305 | 877 | { |
RyoheiHagimoto | 0:0e0631af0305 | 878 | writeScalar(fs, value); |
RyoheiHagimoto | 0:0e0631af0305 | 879 | } |
RyoheiHagimoto | 0:0e0631af0305 | 880 | |
RyoheiHagimoto | 0:0e0631af0305 | 881 | template<> inline |
RyoheiHagimoto | 0:0e0631af0305 | 882 | void write( FileStorage& fs, const double& value ) |
RyoheiHagimoto | 0:0e0631af0305 | 883 | { |
RyoheiHagimoto | 0:0e0631af0305 | 884 | writeScalar(fs, value); |
RyoheiHagimoto | 0:0e0631af0305 | 885 | } |
RyoheiHagimoto | 0:0e0631af0305 | 886 | |
RyoheiHagimoto | 0:0e0631af0305 | 887 | template<> inline |
RyoheiHagimoto | 0:0e0631af0305 | 888 | void write( FileStorage& fs, const String& value ) |
RyoheiHagimoto | 0:0e0631af0305 | 889 | { |
RyoheiHagimoto | 0:0e0631af0305 | 890 | writeScalar(fs, value); |
RyoheiHagimoto | 0:0e0631af0305 | 891 | } |
RyoheiHagimoto | 0:0e0631af0305 | 892 | |
RyoheiHagimoto | 0:0e0631af0305 | 893 | template<typename _Tp> static inline |
RyoheiHagimoto | 0:0e0631af0305 | 894 | void write(FileStorage& fs, const Point_<_Tp>& pt ) |
RyoheiHagimoto | 0:0e0631af0305 | 895 | { |
RyoheiHagimoto | 0:0e0631af0305 | 896 | write(fs, pt.x); |
RyoheiHagimoto | 0:0e0631af0305 | 897 | write(fs, pt.y); |
RyoheiHagimoto | 0:0e0631af0305 | 898 | } |
RyoheiHagimoto | 0:0e0631af0305 | 899 | |
RyoheiHagimoto | 0:0e0631af0305 | 900 | template<typename _Tp> static inline |
RyoheiHagimoto | 0:0e0631af0305 | 901 | void write(FileStorage& fs, const Point3_<_Tp>& pt ) |
RyoheiHagimoto | 0:0e0631af0305 | 902 | { |
RyoheiHagimoto | 0:0e0631af0305 | 903 | write(fs, pt.x); |
RyoheiHagimoto | 0:0e0631af0305 | 904 | write(fs, pt.y); |
RyoheiHagimoto | 0:0e0631af0305 | 905 | write(fs, pt.z); |
RyoheiHagimoto | 0:0e0631af0305 | 906 | } |
RyoheiHagimoto | 0:0e0631af0305 | 907 | |
RyoheiHagimoto | 0:0e0631af0305 | 908 | template<typename _Tp> static inline |
RyoheiHagimoto | 0:0e0631af0305 | 909 | void write(FileStorage& fs, const Size_<_Tp>& sz ) |
RyoheiHagimoto | 0:0e0631af0305 | 910 | { |
RyoheiHagimoto | 0:0e0631af0305 | 911 | write(fs, sz.width); |
RyoheiHagimoto | 0:0e0631af0305 | 912 | write(fs, sz.height); |
RyoheiHagimoto | 0:0e0631af0305 | 913 | } |
RyoheiHagimoto | 0:0e0631af0305 | 914 | |
RyoheiHagimoto | 0:0e0631af0305 | 915 | template<typename _Tp> static inline |
RyoheiHagimoto | 0:0e0631af0305 | 916 | void write(FileStorage& fs, const Complex<_Tp>& c ) |
RyoheiHagimoto | 0:0e0631af0305 | 917 | { |
RyoheiHagimoto | 0:0e0631af0305 | 918 | write(fs, c.re); |
RyoheiHagimoto | 0:0e0631af0305 | 919 | write(fs, c.im); |
RyoheiHagimoto | 0:0e0631af0305 | 920 | } |
RyoheiHagimoto | 0:0e0631af0305 | 921 | |
RyoheiHagimoto | 0:0e0631af0305 | 922 | template<typename _Tp> static inline |
RyoheiHagimoto | 0:0e0631af0305 | 923 | void write(FileStorage& fs, const Rect_<_Tp>& r ) |
RyoheiHagimoto | 0:0e0631af0305 | 924 | { |
RyoheiHagimoto | 0:0e0631af0305 | 925 | write(fs, r.x); |
RyoheiHagimoto | 0:0e0631af0305 | 926 | write(fs, r.y); |
RyoheiHagimoto | 0:0e0631af0305 | 927 | write(fs, r.width); |
RyoheiHagimoto | 0:0e0631af0305 | 928 | write(fs, r.height); |
RyoheiHagimoto | 0:0e0631af0305 | 929 | } |
RyoheiHagimoto | 0:0e0631af0305 | 930 | |
RyoheiHagimoto | 0:0e0631af0305 | 931 | template<typename _Tp, int cn> static inline |
RyoheiHagimoto | 0:0e0631af0305 | 932 | void write(FileStorage& fs, const Vec<_Tp, cn>& v ) |
RyoheiHagimoto | 0:0e0631af0305 | 933 | { |
RyoheiHagimoto | 0:0e0631af0305 | 934 | for(int i = 0; i < cn; i++) |
RyoheiHagimoto | 0:0e0631af0305 | 935 | write(fs, v.val[i]); |
RyoheiHagimoto | 0:0e0631af0305 | 936 | } |
RyoheiHagimoto | 0:0e0631af0305 | 937 | |
RyoheiHagimoto | 0:0e0631af0305 | 938 | template<typename _Tp> static inline |
RyoheiHagimoto | 0:0e0631af0305 | 939 | void write(FileStorage& fs, const Scalar_<_Tp>& s ) |
RyoheiHagimoto | 0:0e0631af0305 | 940 | { |
RyoheiHagimoto | 0:0e0631af0305 | 941 | write(fs, s.val[0]); |
RyoheiHagimoto | 0:0e0631af0305 | 942 | write(fs, s.val[1]); |
RyoheiHagimoto | 0:0e0631af0305 | 943 | write(fs, s.val[2]); |
RyoheiHagimoto | 0:0e0631af0305 | 944 | write(fs, s.val[3]); |
RyoheiHagimoto | 0:0e0631af0305 | 945 | } |
RyoheiHagimoto | 0:0e0631af0305 | 946 | |
RyoheiHagimoto | 0:0e0631af0305 | 947 | static inline |
RyoheiHagimoto | 0:0e0631af0305 | 948 | void write(FileStorage& fs, const Range& r ) |
RyoheiHagimoto | 0:0e0631af0305 | 949 | { |
RyoheiHagimoto | 0:0e0631af0305 | 950 | write(fs, r.start); |
RyoheiHagimoto | 0:0e0631af0305 | 951 | write(fs, r.end); |
RyoheiHagimoto | 0:0e0631af0305 | 952 | } |
RyoheiHagimoto | 0:0e0631af0305 | 953 | |
RyoheiHagimoto | 0:0e0631af0305 | 954 | template<typename _Tp> static inline |
RyoheiHagimoto | 0:0e0631af0305 | 955 | void write( FileStorage& fs, const std::vector<_Tp>& vec ) |
RyoheiHagimoto | 0:0e0631af0305 | 956 | { |
RyoheiHagimoto | 0:0e0631af0305 | 957 | cv::internal::VecWriterProxy<_Tp, DataType<_Tp>::fmt != 0> w(&fs); |
RyoheiHagimoto | 0:0e0631af0305 | 958 | w(vec); |
RyoheiHagimoto | 0:0e0631af0305 | 959 | } |
RyoheiHagimoto | 0:0e0631af0305 | 960 | |
RyoheiHagimoto | 0:0e0631af0305 | 961 | template<typename _Tp> static inline |
RyoheiHagimoto | 0:0e0631af0305 | 962 | void write(FileStorage& fs, const String& name, const Point_<_Tp>& pt ) |
RyoheiHagimoto | 0:0e0631af0305 | 963 | { |
RyoheiHagimoto | 0:0e0631af0305 | 964 | cv::internal::WriteStructContext ws(fs, name, FileNode::SEQ+FileNode::FLOW); |
RyoheiHagimoto | 0:0e0631af0305 | 965 | write(fs, pt); |
RyoheiHagimoto | 0:0e0631af0305 | 966 | } |
RyoheiHagimoto | 0:0e0631af0305 | 967 | |
RyoheiHagimoto | 0:0e0631af0305 | 968 | template<typename _Tp> static inline |
RyoheiHagimoto | 0:0e0631af0305 | 969 | void write(FileStorage& fs, const String& name, const Point3_<_Tp>& pt ) |
RyoheiHagimoto | 0:0e0631af0305 | 970 | { |
RyoheiHagimoto | 0:0e0631af0305 | 971 | cv::internal::WriteStructContext ws(fs, name, FileNode::SEQ+FileNode::FLOW); |
RyoheiHagimoto | 0:0e0631af0305 | 972 | write(fs, pt); |
RyoheiHagimoto | 0:0e0631af0305 | 973 | } |
RyoheiHagimoto | 0:0e0631af0305 | 974 | |
RyoheiHagimoto | 0:0e0631af0305 | 975 | template<typename _Tp> static inline |
RyoheiHagimoto | 0:0e0631af0305 | 976 | void write(FileStorage& fs, const String& name, const Size_<_Tp>& sz ) |
RyoheiHagimoto | 0:0e0631af0305 | 977 | { |
RyoheiHagimoto | 0:0e0631af0305 | 978 | cv::internal::WriteStructContext ws(fs, name, FileNode::SEQ+FileNode::FLOW); |
RyoheiHagimoto | 0:0e0631af0305 | 979 | write(fs, sz); |
RyoheiHagimoto | 0:0e0631af0305 | 980 | } |
RyoheiHagimoto | 0:0e0631af0305 | 981 | |
RyoheiHagimoto | 0:0e0631af0305 | 982 | template<typename _Tp> static inline |
RyoheiHagimoto | 0:0e0631af0305 | 983 | void write(FileStorage& fs, const String& name, const Complex<_Tp>& c ) |
RyoheiHagimoto | 0:0e0631af0305 | 984 | { |
RyoheiHagimoto | 0:0e0631af0305 | 985 | cv::internal::WriteStructContext ws(fs, name, FileNode::SEQ+FileNode::FLOW); |
RyoheiHagimoto | 0:0e0631af0305 | 986 | write(fs, c); |
RyoheiHagimoto | 0:0e0631af0305 | 987 | } |
RyoheiHagimoto | 0:0e0631af0305 | 988 | |
RyoheiHagimoto | 0:0e0631af0305 | 989 | template<typename _Tp> static inline |
RyoheiHagimoto | 0:0e0631af0305 | 990 | void write(FileStorage& fs, const String& name, const Rect_<_Tp>& r ) |
RyoheiHagimoto | 0:0e0631af0305 | 991 | { |
RyoheiHagimoto | 0:0e0631af0305 | 992 | cv::internal::WriteStructContext ws(fs, name, FileNode::SEQ+FileNode::FLOW); |
RyoheiHagimoto | 0:0e0631af0305 | 993 | write(fs, r); |
RyoheiHagimoto | 0:0e0631af0305 | 994 | } |
RyoheiHagimoto | 0:0e0631af0305 | 995 | |
RyoheiHagimoto | 0:0e0631af0305 | 996 | template<typename _Tp, int cn> static inline |
RyoheiHagimoto | 0:0e0631af0305 | 997 | void write(FileStorage& fs, const String& name, const Vec<_Tp, cn>& v ) |
RyoheiHagimoto | 0:0e0631af0305 | 998 | { |
RyoheiHagimoto | 0:0e0631af0305 | 999 | cv::internal::WriteStructContext ws(fs, name, FileNode::SEQ+FileNode::FLOW); |
RyoheiHagimoto | 0:0e0631af0305 | 1000 | write(fs, v); |
RyoheiHagimoto | 0:0e0631af0305 | 1001 | } |
RyoheiHagimoto | 0:0e0631af0305 | 1002 | |
RyoheiHagimoto | 0:0e0631af0305 | 1003 | template<typename _Tp> static inline |
RyoheiHagimoto | 0:0e0631af0305 | 1004 | void write(FileStorage& fs, const String& name, const Scalar_<_Tp>& s ) |
RyoheiHagimoto | 0:0e0631af0305 | 1005 | { |
RyoheiHagimoto | 0:0e0631af0305 | 1006 | cv::internal::WriteStructContext ws(fs, name, FileNode::SEQ+FileNode::FLOW); |
RyoheiHagimoto | 0:0e0631af0305 | 1007 | write(fs, s); |
RyoheiHagimoto | 0:0e0631af0305 | 1008 | } |
RyoheiHagimoto | 0:0e0631af0305 | 1009 | |
RyoheiHagimoto | 0:0e0631af0305 | 1010 | static inline |
RyoheiHagimoto | 0:0e0631af0305 | 1011 | void write(FileStorage& fs, const String& name, const Range& r ) |
RyoheiHagimoto | 0:0e0631af0305 | 1012 | { |
RyoheiHagimoto | 0:0e0631af0305 | 1013 | cv::internal::WriteStructContext ws(fs, name, FileNode::SEQ+FileNode::FLOW); |
RyoheiHagimoto | 0:0e0631af0305 | 1014 | write(fs, r); |
RyoheiHagimoto | 0:0e0631af0305 | 1015 | } |
RyoheiHagimoto | 0:0e0631af0305 | 1016 | |
RyoheiHagimoto | 0:0e0631af0305 | 1017 | template<typename _Tp> static inline |
RyoheiHagimoto | 0:0e0631af0305 | 1018 | void write( FileStorage& fs, const String& name, const std::vector<_Tp>& vec ) |
RyoheiHagimoto | 0:0e0631af0305 | 1019 | { |
RyoheiHagimoto | 0:0e0631af0305 | 1020 | cv::internal::WriteStructContext ws(fs, name, FileNode::SEQ+(DataType<_Tp>::fmt != 0 ? FileNode::FLOW : 0)); |
RyoheiHagimoto | 0:0e0631af0305 | 1021 | write(fs, vec); |
RyoheiHagimoto | 0:0e0631af0305 | 1022 | } |
RyoheiHagimoto | 0:0e0631af0305 | 1023 | |
RyoheiHagimoto | 0:0e0631af0305 | 1024 | template<typename _Tp> static inline |
RyoheiHagimoto | 0:0e0631af0305 | 1025 | void write( FileStorage& fs, const String& name, const std::vector< std::vector<_Tp> >& vec ) |
RyoheiHagimoto | 0:0e0631af0305 | 1026 | { |
RyoheiHagimoto | 0:0e0631af0305 | 1027 | cv::internal::WriteStructContext ws(fs, name, FileNode::SEQ); |
RyoheiHagimoto | 0:0e0631af0305 | 1028 | for(size_t i = 0; i < vec.size(); i++) |
RyoheiHagimoto | 0:0e0631af0305 | 1029 | { |
RyoheiHagimoto | 0:0e0631af0305 | 1030 | cv::internal::WriteStructContext ws_(fs, name, FileNode::SEQ+(DataType<_Tp>::fmt != 0 ? FileNode::FLOW : 0)); |
RyoheiHagimoto | 0:0e0631af0305 | 1031 | write(fs, vec[i]); |
RyoheiHagimoto | 0:0e0631af0305 | 1032 | } |
RyoheiHagimoto | 0:0e0631af0305 | 1033 | } |
RyoheiHagimoto | 0:0e0631af0305 | 1034 | |
RyoheiHagimoto | 0:0e0631af0305 | 1035 | //! @} FileStorage |
RyoheiHagimoto | 0:0e0631af0305 | 1036 | |
RyoheiHagimoto | 0:0e0631af0305 | 1037 | //! @relates cv::FileNode |
RyoheiHagimoto | 0:0e0631af0305 | 1038 | //! @{ |
RyoheiHagimoto | 0:0e0631af0305 | 1039 | |
RyoheiHagimoto | 0:0e0631af0305 | 1040 | static inline |
RyoheiHagimoto | 0:0e0631af0305 | 1041 | void read(const FileNode& node, bool& value, bool default_value) |
RyoheiHagimoto | 0:0e0631af0305 | 1042 | { |
RyoheiHagimoto | 0:0e0631af0305 | 1043 | int temp; |
RyoheiHagimoto | 0:0e0631af0305 | 1044 | read(node, temp, (int)default_value); |
RyoheiHagimoto | 0:0e0631af0305 | 1045 | value = temp != 0; |
RyoheiHagimoto | 0:0e0631af0305 | 1046 | } |
RyoheiHagimoto | 0:0e0631af0305 | 1047 | |
RyoheiHagimoto | 0:0e0631af0305 | 1048 | static inline |
RyoheiHagimoto | 0:0e0631af0305 | 1049 | void read(const FileNode& node, uchar& value, uchar default_value) |
RyoheiHagimoto | 0:0e0631af0305 | 1050 | { |
RyoheiHagimoto | 0:0e0631af0305 | 1051 | int temp; |
RyoheiHagimoto | 0:0e0631af0305 | 1052 | read(node, temp, (int)default_value); |
RyoheiHagimoto | 0:0e0631af0305 | 1053 | value = saturate_cast<uchar>(temp); |
RyoheiHagimoto | 0:0e0631af0305 | 1054 | } |
RyoheiHagimoto | 0:0e0631af0305 | 1055 | |
RyoheiHagimoto | 0:0e0631af0305 | 1056 | static inline |
RyoheiHagimoto | 0:0e0631af0305 | 1057 | void read(const FileNode& node, schar& value, schar default_value) |
RyoheiHagimoto | 0:0e0631af0305 | 1058 | { |
RyoheiHagimoto | 0:0e0631af0305 | 1059 | int temp; |
RyoheiHagimoto | 0:0e0631af0305 | 1060 | read(node, temp, (int)default_value); |
RyoheiHagimoto | 0:0e0631af0305 | 1061 | value = saturate_cast<schar>(temp); |
RyoheiHagimoto | 0:0e0631af0305 | 1062 | } |
RyoheiHagimoto | 0:0e0631af0305 | 1063 | |
RyoheiHagimoto | 0:0e0631af0305 | 1064 | static inline |
RyoheiHagimoto | 0:0e0631af0305 | 1065 | void read(const FileNode& node, ushort& value, ushort default_value) |
RyoheiHagimoto | 0:0e0631af0305 | 1066 | { |
RyoheiHagimoto | 0:0e0631af0305 | 1067 | int temp; |
RyoheiHagimoto | 0:0e0631af0305 | 1068 | read(node, temp, (int)default_value); |
RyoheiHagimoto | 0:0e0631af0305 | 1069 | value = saturate_cast<ushort>(temp); |
RyoheiHagimoto | 0:0e0631af0305 | 1070 | } |
RyoheiHagimoto | 0:0e0631af0305 | 1071 | |
RyoheiHagimoto | 0:0e0631af0305 | 1072 | static inline |
RyoheiHagimoto | 0:0e0631af0305 | 1073 | void read(const FileNode& node, short& value, short default_value) |
RyoheiHagimoto | 0:0e0631af0305 | 1074 | { |
RyoheiHagimoto | 0:0e0631af0305 | 1075 | int temp; |
RyoheiHagimoto | 0:0e0631af0305 | 1076 | read(node, temp, (int)default_value); |
RyoheiHagimoto | 0:0e0631af0305 | 1077 | value = saturate_cast<short>(temp); |
RyoheiHagimoto | 0:0e0631af0305 | 1078 | } |
RyoheiHagimoto | 0:0e0631af0305 | 1079 | |
RyoheiHagimoto | 0:0e0631af0305 | 1080 | template<typename _Tp> static inline |
RyoheiHagimoto | 0:0e0631af0305 | 1081 | void read( FileNodeIterator& it, std::vector<_Tp>& vec, size_t maxCount = (size_t)INT_MAX ) |
RyoheiHagimoto | 0:0e0631af0305 | 1082 | { |
RyoheiHagimoto | 0:0e0631af0305 | 1083 | cv::internal::VecReaderProxy<_Tp, DataType<_Tp>::fmt != 0> r(&it); |
RyoheiHagimoto | 0:0e0631af0305 | 1084 | r(vec, maxCount); |
RyoheiHagimoto | 0:0e0631af0305 | 1085 | } |
RyoheiHagimoto | 0:0e0631af0305 | 1086 | |
RyoheiHagimoto | 0:0e0631af0305 | 1087 | template<typename _Tp> static inline |
RyoheiHagimoto | 0:0e0631af0305 | 1088 | void read( const FileNode& node, std::vector<_Tp>& vec, const std::vector<_Tp>& default_value = std::vector<_Tp>() ) |
RyoheiHagimoto | 0:0e0631af0305 | 1089 | { |
RyoheiHagimoto | 0:0e0631af0305 | 1090 | if(!node.node) |
RyoheiHagimoto | 0:0e0631af0305 | 1091 | vec = default_value; |
RyoheiHagimoto | 0:0e0631af0305 | 1092 | else |
RyoheiHagimoto | 0:0e0631af0305 | 1093 | { |
RyoheiHagimoto | 0:0e0631af0305 | 1094 | FileNodeIterator it = node.begin(); |
RyoheiHagimoto | 0:0e0631af0305 | 1095 | read( it, vec ); |
RyoheiHagimoto | 0:0e0631af0305 | 1096 | } |
RyoheiHagimoto | 0:0e0631af0305 | 1097 | } |
RyoheiHagimoto | 0:0e0631af0305 | 1098 | |
RyoheiHagimoto | 0:0e0631af0305 | 1099 | //! @} FileNode |
RyoheiHagimoto | 0:0e0631af0305 | 1100 | |
RyoheiHagimoto | 0:0e0631af0305 | 1101 | //! @relates cv::FileStorage |
RyoheiHagimoto | 0:0e0631af0305 | 1102 | //! @{ |
RyoheiHagimoto | 0:0e0631af0305 | 1103 | |
RyoheiHagimoto | 0:0e0631af0305 | 1104 | /** @brief Writes data to a file storage. |
RyoheiHagimoto | 0:0e0631af0305 | 1105 | */ |
RyoheiHagimoto | 0:0e0631af0305 | 1106 | template<typename _Tp> static inline |
RyoheiHagimoto | 0:0e0631af0305 | 1107 | FileStorage& operator << (FileStorage& fs, const _Tp& value) |
RyoheiHagimoto | 0:0e0631af0305 | 1108 | { |
RyoheiHagimoto | 0:0e0631af0305 | 1109 | if( !fs.isOpened() ) |
RyoheiHagimoto | 0:0e0631af0305 | 1110 | return fs; |
RyoheiHagimoto | 0:0e0631af0305 | 1111 | if( fs.state == FileStorage::NAME_EXPECTED + FileStorage::INSIDE_MAP ) |
RyoheiHagimoto | 0:0e0631af0305 | 1112 | CV_Error( Error::StsError, "No element name has been given" ); |
RyoheiHagimoto | 0:0e0631af0305 | 1113 | write( fs, fs.elname, value ); |
RyoheiHagimoto | 0:0e0631af0305 | 1114 | if( fs.state & FileStorage::INSIDE_MAP ) |
RyoheiHagimoto | 0:0e0631af0305 | 1115 | fs.state = FileStorage::NAME_EXPECTED + FileStorage::INSIDE_MAP; |
RyoheiHagimoto | 0:0e0631af0305 | 1116 | return fs; |
RyoheiHagimoto | 0:0e0631af0305 | 1117 | } |
RyoheiHagimoto | 0:0e0631af0305 | 1118 | |
RyoheiHagimoto | 0:0e0631af0305 | 1119 | /** @brief Writes data to a file storage. |
RyoheiHagimoto | 0:0e0631af0305 | 1120 | */ |
RyoheiHagimoto | 0:0e0631af0305 | 1121 | static inline |
RyoheiHagimoto | 0:0e0631af0305 | 1122 | FileStorage& operator << (FileStorage& fs, const char* str) |
RyoheiHagimoto | 0:0e0631af0305 | 1123 | { |
RyoheiHagimoto | 0:0e0631af0305 | 1124 | return (fs << String(str)); |
RyoheiHagimoto | 0:0e0631af0305 | 1125 | } |
RyoheiHagimoto | 0:0e0631af0305 | 1126 | |
RyoheiHagimoto | 0:0e0631af0305 | 1127 | /** @brief Writes data to a file storage. |
RyoheiHagimoto | 0:0e0631af0305 | 1128 | */ |
RyoheiHagimoto | 0:0e0631af0305 | 1129 | static inline |
RyoheiHagimoto | 0:0e0631af0305 | 1130 | FileStorage& operator << (FileStorage& fs, char* value) |
RyoheiHagimoto | 0:0e0631af0305 | 1131 | { |
RyoheiHagimoto | 0:0e0631af0305 | 1132 | return (fs << String(value)); |
RyoheiHagimoto | 0:0e0631af0305 | 1133 | } |
RyoheiHagimoto | 0:0e0631af0305 | 1134 | |
RyoheiHagimoto | 0:0e0631af0305 | 1135 | //! @} FileStorage |
RyoheiHagimoto | 0:0e0631af0305 | 1136 | |
RyoheiHagimoto | 0:0e0631af0305 | 1137 | //! @relates cv::FileNodeIterator |
RyoheiHagimoto | 0:0e0631af0305 | 1138 | //! @{ |
RyoheiHagimoto | 0:0e0631af0305 | 1139 | |
RyoheiHagimoto | 0:0e0631af0305 | 1140 | /** @brief Reads data from a file storage. |
RyoheiHagimoto | 0:0e0631af0305 | 1141 | */ |
RyoheiHagimoto | 0:0e0631af0305 | 1142 | template<typename _Tp> static inline |
RyoheiHagimoto | 0:0e0631af0305 | 1143 | FileNodeIterator& operator >> (FileNodeIterator& it, _Tp& value) |
RyoheiHagimoto | 0:0e0631af0305 | 1144 | { |
RyoheiHagimoto | 0:0e0631af0305 | 1145 | read( *it, value, _Tp()); |
RyoheiHagimoto | 0:0e0631af0305 | 1146 | return ++it; |
RyoheiHagimoto | 0:0e0631af0305 | 1147 | } |
RyoheiHagimoto | 0:0e0631af0305 | 1148 | |
RyoheiHagimoto | 0:0e0631af0305 | 1149 | /** @brief Reads data from a file storage. |
RyoheiHagimoto | 0:0e0631af0305 | 1150 | */ |
RyoheiHagimoto | 0:0e0631af0305 | 1151 | template<typename _Tp> static inline |
RyoheiHagimoto | 0:0e0631af0305 | 1152 | FileNodeIterator& operator >> (FileNodeIterator& it, std::vector<_Tp>& vec) |
RyoheiHagimoto | 0:0e0631af0305 | 1153 | { |
RyoheiHagimoto | 0:0e0631af0305 | 1154 | cv::internal::VecReaderProxy<_Tp, DataType<_Tp>::fmt != 0> r(&it); |
RyoheiHagimoto | 0:0e0631af0305 | 1155 | r(vec, (size_t)INT_MAX); |
RyoheiHagimoto | 0:0e0631af0305 | 1156 | return it; |
RyoheiHagimoto | 0:0e0631af0305 | 1157 | } |
RyoheiHagimoto | 0:0e0631af0305 | 1158 | |
RyoheiHagimoto | 0:0e0631af0305 | 1159 | //! @} FileNodeIterator |
RyoheiHagimoto | 0:0e0631af0305 | 1160 | |
RyoheiHagimoto | 0:0e0631af0305 | 1161 | //! @relates cv::FileNode |
RyoheiHagimoto | 0:0e0631af0305 | 1162 | //! @{ |
RyoheiHagimoto | 0:0e0631af0305 | 1163 | |
RyoheiHagimoto | 0:0e0631af0305 | 1164 | /** @brief Reads data from a file storage. |
RyoheiHagimoto | 0:0e0631af0305 | 1165 | */ |
RyoheiHagimoto | 0:0e0631af0305 | 1166 | template<typename _Tp> static inline |
RyoheiHagimoto | 0:0e0631af0305 | 1167 | void operator >> (const FileNode& n, _Tp& value) |
RyoheiHagimoto | 0:0e0631af0305 | 1168 | { |
RyoheiHagimoto | 0:0e0631af0305 | 1169 | read( n, value, _Tp()); |
RyoheiHagimoto | 0:0e0631af0305 | 1170 | } |
RyoheiHagimoto | 0:0e0631af0305 | 1171 | |
RyoheiHagimoto | 0:0e0631af0305 | 1172 | /** @brief Reads data from a file storage. |
RyoheiHagimoto | 0:0e0631af0305 | 1173 | */ |
RyoheiHagimoto | 0:0e0631af0305 | 1174 | template<typename _Tp> static inline |
RyoheiHagimoto | 0:0e0631af0305 | 1175 | void operator >> (const FileNode& n, std::vector<_Tp>& vec) |
RyoheiHagimoto | 0:0e0631af0305 | 1176 | { |
RyoheiHagimoto | 0:0e0631af0305 | 1177 | FileNodeIterator it = n.begin(); |
RyoheiHagimoto | 0:0e0631af0305 | 1178 | it >> vec; |
RyoheiHagimoto | 0:0e0631af0305 | 1179 | } |
RyoheiHagimoto | 0:0e0631af0305 | 1180 | |
RyoheiHagimoto | 0:0e0631af0305 | 1181 | /** @brief Reads KeyPoint from a file storage. |
RyoheiHagimoto | 0:0e0631af0305 | 1182 | */ |
RyoheiHagimoto | 0:0e0631af0305 | 1183 | //It needs special handling because it contains two types of fields, int & float. |
RyoheiHagimoto | 0:0e0631af0305 | 1184 | static inline |
RyoheiHagimoto | 0:0e0631af0305 | 1185 | void operator >> (const FileNode& n, std::vector<KeyPoint>& vec) |
RyoheiHagimoto | 0:0e0631af0305 | 1186 | { |
RyoheiHagimoto | 0:0e0631af0305 | 1187 | read(n, vec); |
RyoheiHagimoto | 0:0e0631af0305 | 1188 | } |
RyoheiHagimoto | 0:0e0631af0305 | 1189 | /** @brief Reads DMatch from a file storage. |
RyoheiHagimoto | 0:0e0631af0305 | 1190 | */ |
RyoheiHagimoto | 0:0e0631af0305 | 1191 | //It needs special handling because it contains two types of fields, int & float. |
RyoheiHagimoto | 0:0e0631af0305 | 1192 | static inline |
RyoheiHagimoto | 0:0e0631af0305 | 1193 | void operator >> (const FileNode& n, std::vector<DMatch>& vec) |
RyoheiHagimoto | 0:0e0631af0305 | 1194 | { |
RyoheiHagimoto | 0:0e0631af0305 | 1195 | read(n, vec); |
RyoheiHagimoto | 0:0e0631af0305 | 1196 | } |
RyoheiHagimoto | 0:0e0631af0305 | 1197 | |
RyoheiHagimoto | 0:0e0631af0305 | 1198 | //! @} FileNode |
RyoheiHagimoto | 0:0e0631af0305 | 1199 | |
RyoheiHagimoto | 0:0e0631af0305 | 1200 | //! @relates cv::FileNodeIterator |
RyoheiHagimoto | 0:0e0631af0305 | 1201 | //! @{ |
RyoheiHagimoto | 0:0e0631af0305 | 1202 | |
RyoheiHagimoto | 0:0e0631af0305 | 1203 | static inline |
RyoheiHagimoto | 0:0e0631af0305 | 1204 | bool operator == (const FileNodeIterator& it1, const FileNodeIterator& it2) |
RyoheiHagimoto | 0:0e0631af0305 | 1205 | { |
RyoheiHagimoto | 0:0e0631af0305 | 1206 | return it1.fs == it2.fs && it1.container == it2.container && |
RyoheiHagimoto | 0:0e0631af0305 | 1207 | it1.reader.ptr == it2.reader.ptr && it1.remaining == it2.remaining; |
RyoheiHagimoto | 0:0e0631af0305 | 1208 | } |
RyoheiHagimoto | 0:0e0631af0305 | 1209 | |
RyoheiHagimoto | 0:0e0631af0305 | 1210 | static inline |
RyoheiHagimoto | 0:0e0631af0305 | 1211 | bool operator != (const FileNodeIterator& it1, const FileNodeIterator& it2) |
RyoheiHagimoto | 0:0e0631af0305 | 1212 | { |
RyoheiHagimoto | 0:0e0631af0305 | 1213 | return !(it1 == it2); |
RyoheiHagimoto | 0:0e0631af0305 | 1214 | } |
RyoheiHagimoto | 0:0e0631af0305 | 1215 | |
RyoheiHagimoto | 0:0e0631af0305 | 1216 | static inline |
RyoheiHagimoto | 0:0e0631af0305 | 1217 | ptrdiff_t operator - (const FileNodeIterator& it1, const FileNodeIterator& it2) |
RyoheiHagimoto | 0:0e0631af0305 | 1218 | { |
RyoheiHagimoto | 0:0e0631af0305 | 1219 | return it2.remaining - it1.remaining; |
RyoheiHagimoto | 0:0e0631af0305 | 1220 | } |
RyoheiHagimoto | 0:0e0631af0305 | 1221 | |
RyoheiHagimoto | 0:0e0631af0305 | 1222 | static inline |
RyoheiHagimoto | 0:0e0631af0305 | 1223 | bool operator < (const FileNodeIterator& it1, const FileNodeIterator& it2) |
RyoheiHagimoto | 0:0e0631af0305 | 1224 | { |
RyoheiHagimoto | 0:0e0631af0305 | 1225 | return it1.remaining > it2.remaining; |
RyoheiHagimoto | 0:0e0631af0305 | 1226 | } |
RyoheiHagimoto | 0:0e0631af0305 | 1227 | |
RyoheiHagimoto | 0:0e0631af0305 | 1228 | //! @} FileNodeIterator |
RyoheiHagimoto | 0:0e0631af0305 | 1229 | |
RyoheiHagimoto | 0:0e0631af0305 | 1230 | //! @cond IGNORED |
RyoheiHagimoto | 0:0e0631af0305 | 1231 | |
RyoheiHagimoto | 0:0e0631af0305 | 1232 | inline FileNode FileStorage::getFirstTopLevelNode() const { FileNode r = root(); FileNodeIterator it = r.begin(); return it != r.end() ? *it : FileNode(); } |
RyoheiHagimoto | 0:0e0631af0305 | 1233 | inline FileNode::FileNode() : fs(0), node(0) {} |
RyoheiHagimoto | 0:0e0631af0305 | 1234 | inline FileNode::FileNode(const CvFileStorage* _fs, const CvFileNode* _node) : fs(_fs), node(_node) {} |
RyoheiHagimoto | 0:0e0631af0305 | 1235 | inline FileNode::FileNode(const FileNode& _node) : fs(_node.fs), node(_node.node) {} |
RyoheiHagimoto | 0:0e0631af0305 | 1236 | inline bool FileNode::empty() const { return node == 0; } |
RyoheiHagimoto | 0:0e0631af0305 | 1237 | inline bool FileNode::isNone() const { return type() == NONE; } |
RyoheiHagimoto | 0:0e0631af0305 | 1238 | inline bool FileNode::isSeq() const { return type() == SEQ; } |
RyoheiHagimoto | 0:0e0631af0305 | 1239 | inline bool FileNode::isMap() const { return type() == MAP; } |
RyoheiHagimoto | 0:0e0631af0305 | 1240 | inline bool FileNode::isInt() const { return type() == INT; } |
RyoheiHagimoto | 0:0e0631af0305 | 1241 | inline bool FileNode::isReal() const { return type() == REAL; } |
RyoheiHagimoto | 0:0e0631af0305 | 1242 | inline bool FileNode::isString() const { return type() == STR; } |
RyoheiHagimoto | 0:0e0631af0305 | 1243 | inline CvFileNode* FileNode::operator *() { return (CvFileNode*)node; } |
RyoheiHagimoto | 0:0e0631af0305 | 1244 | inline const CvFileNode* FileNode::operator* () const { return node; } |
RyoheiHagimoto | 0:0e0631af0305 | 1245 | inline FileNode::operator int() const { int value; read(*this, value, 0); return value; } |
RyoheiHagimoto | 0:0e0631af0305 | 1246 | inline FileNode::operator float() const { float value; read(*this, value, 0.f); return value; } |
RyoheiHagimoto | 0:0e0631af0305 | 1247 | inline FileNode::operator double() const { double value; read(*this, value, 0.); return value; } |
RyoheiHagimoto | 0:0e0631af0305 | 1248 | inline FileNode::operator String() const { String value; read(*this, value, value); return value; } |
RyoheiHagimoto | 0:0e0631af0305 | 1249 | inline double FileNode::real() const { return double(*this); } |
RyoheiHagimoto | 0:0e0631af0305 | 1250 | inline String FileNode::string() const { return String(*this); } |
RyoheiHagimoto | 0:0e0631af0305 | 1251 | inline Mat FileNode::mat() const { Mat value; read(*this, value, value); return value; } |
RyoheiHagimoto | 0:0e0631af0305 | 1252 | inline FileNodeIterator FileNode::begin() const { return FileNodeIterator(fs, node); } |
RyoheiHagimoto | 0:0e0631af0305 | 1253 | inline FileNodeIterator FileNode::end() const { return FileNodeIterator(fs, node, size()); } |
RyoheiHagimoto | 0:0e0631af0305 | 1254 | inline void FileNode::readRaw( const String& fmt, uchar* vec, size_t len ) const { begin().readRaw( fmt, vec, len ); } |
RyoheiHagimoto | 0:0e0631af0305 | 1255 | inline FileNode FileNodeIterator::operator *() const { return FileNode(fs, (const CvFileNode*)(const void*)reader.ptr); } |
RyoheiHagimoto | 0:0e0631af0305 | 1256 | inline FileNode FileNodeIterator::operator ->() const { return FileNode(fs, (const CvFileNode*)(const void*)reader.ptr); } |
RyoheiHagimoto | 0:0e0631af0305 | 1257 | inline String::String(const FileNode& fn): cstr_(0), len_(0) { read(fn, *this, *this); } |
RyoheiHagimoto | 0:0e0631af0305 | 1258 | |
RyoheiHagimoto | 0:0e0631af0305 | 1259 | //! @endcond |
RyoheiHagimoto | 0:0e0631af0305 | 1260 | |
RyoheiHagimoto | 0:0e0631af0305 | 1261 | |
RyoheiHagimoto | 0:0e0631af0305 | 1262 | CV_EXPORTS void cvStartWriteRawData_Base64(::CvFileStorage * fs, const char* name, int len, const char* dt); |
RyoheiHagimoto | 0:0e0631af0305 | 1263 | |
RyoheiHagimoto | 0:0e0631af0305 | 1264 | CV_EXPORTS void cvWriteRawData_Base64(::CvFileStorage * fs, const void* _data, int len); |
RyoheiHagimoto | 0:0e0631af0305 | 1265 | |
RyoheiHagimoto | 0:0e0631af0305 | 1266 | CV_EXPORTS void cvEndWriteRawData_Base64(::CvFileStorage * fs); |
RyoheiHagimoto | 0:0e0631af0305 | 1267 | |
RyoheiHagimoto | 0:0e0631af0305 | 1268 | CV_EXPORTS void cvWriteMat_Base64(::CvFileStorage* fs, const char* name, const ::CvMat* mat); |
RyoheiHagimoto | 0:0e0631af0305 | 1269 | |
RyoheiHagimoto | 0:0e0631af0305 | 1270 | CV_EXPORTS void cvWriteMatND_Base64(::CvFileStorage* fs, const char* name, const ::CvMatND* mat); |
RyoheiHagimoto | 0:0e0631af0305 | 1271 | |
RyoheiHagimoto | 0:0e0631af0305 | 1272 | } // cv |
RyoheiHagimoto | 0:0e0631af0305 | 1273 | |
RyoheiHagimoto | 0:0e0631af0305 | 1274 | #endif // OPENCV_CORE_PERSISTENCE_HPP |