marker_map_config.cpp
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2016, Lukas Pfeifhofer <lukas.pfeifhofer@devlabs.pro>
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions are met:
7  *
8  * 1. Redistributions of source code must retain the above copyright notice,
9  * this list of conditions and the following disclaimer.
10  *
11  * 2. Redistributions in binary form must reproduce the above copyright notice,
12  * this list of conditions and the following disclaimer in the documentation
13  * and/or other materials provided with the distribution.
14  *
15  * 3. Neither the name of the copyright holder nor the names of its contributors
16  * may be used to endorse or promote products derived from this software without
17  * specific prior written permission.
18  *
19  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
20  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
23  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29  * POSSIBILITY OF SUCH DAMAGE.
30  */
31 
33 
34 using namespace cv;
35 
37  cv::FileStorage fs(path, cv::FileStorage::READ);
38  MarkerMapConfig markerMapConfig;
39  fs["markerMapConfig"] >> markerMapConfig;
40  return markerMapConfig;
41 }
42 
43 void MarkerMapConfig::writeFromFile(std::string path, MarkerMapConfig markerMapConfig) {
44  cv::FileStorage fs(path, cv::FileStorage::WRITE);
45  fs << "markerMapConfig" << markerMapConfig;
46  fs.release();
47 }
48 
49 MarkerDetails::MarkerDetails() : id(-1), type("") {
50 
51 }
52 
53 void MarkerDetails::write(cv::FileStorage &fs) const {
54  fs << "{";
55  fs << "id" << this->id;
56  fs << "type" << this->type;
57  fs << "position" << this->position;
58  fs << "rotation" << this->rotation;
59  fs << "}";
60 }
61 
62 void MarkerDetails::read(const cv::FileNode &node) {
63  this->id = (int) node["id"];
64  this->type = (std::string) node["type"];
65  node["position"] >> this->position;
66  node["rotation"] >> this->rotation;
67 }
68 
70 
71 }
72 
73 void MarkerMapDetails::write(cv::FileStorage &fs) const {
74  fs << "{";
75  fs << "id" << this->id;
76  fs << "type" << this->type;
77  fs << "markers";
78  fs << "{";
79  fs << "size" << (int) this->markers.size();
80  fs << "data";
81  fs << "[";
82  for(auto &markerDetails:this->markers){
83  fs << markerDetails;
84  }
85  fs << "]";
86  fs << "}";
87  fs << "}";
88 }
89 
90 void MarkerMapDetails::read(const cv::FileNode &node) {
91  this->id = (int) node["id"];
92  this->type = (std::string) node["type"];
93 
94  FileNode markersNode = node["markers"];
95 
96  // int markersArraySize = markersNode["size"]; // Size is ignored
97  FileNode dataNodes = markersNode["data"];
98  if (dataNodes.type() != FileNode::SEQ) {
99  return;
100  }
101 
102  FileNodeIterator it = dataNodes.begin(), it_end = dataNodes.end();
103  for (; it != it_end; ++it) {
104  MarkerDetails markerDetails;
105  *it >> markerDetails;
106  this->markers.push_back(markerDetails);
107  }
108 }
109 
110 
112 
113 }
114 
115 void MarkerMapConfig::write(cv::FileStorage &fs) const {
116  fs << "{";
117  fs << "size" << (int) this->markerMaps.size();
118  fs << "data";
119  fs << "[";
120  for(auto &markerMapDetails:this->markerMaps){
121  fs << markerMapDetails;
122  }
123  fs << "]";
124  fs << "}";
125 }
126 
127 void MarkerMapConfig::read(const cv::FileNode &node) {
128  // int markersArraySize = node["size"]; // Size is ignored
129  FileNode dataNodes = node["data"];
130  if (dataNodes.type() != FileNode::SEQ) {
131  return;
132  }
133 
134  FileNodeIterator it = dataNodes.begin(), it_end = dataNodes.end();
135  for (; it != it_end; ++it) {
136  MarkerMapDetails markerMapDetails;
137  *it >> markerMapDetails;
138  this->markerMaps.push_back(markerMapDetails);
139  }
140 }
void read(const cv::FileNode &node)
void write(cv::FileStorage &fs) const
std::string type
void write(cv::FileStorage &fs) const
static void writeFromFile(std::string path, MarkerMapConfig markerMapConfig)
static MarkerMapConfig readFromFile(std::string path)
void write(cv::FileStorage &fs) const
void read(const cv::FileNode &node)
void read(const cv::FileNode &node)


tuw_marker_pose_estimation
Author(s): Lukas Pfeifhofer
autogenerated on Mon Jun 10 2019 15:42:13