OSVR-Core
LoadCalibration.h
Go to the documentation of this file.
1 
11 // Copyright 2016 Sensics, Inc.
12 //
13 // Licensed under the Apache License, Version 2.0 (the "License");
14 // you may not use this file except in compliance with the License.
15 // You may obtain a copy of the License at
16 //
17 // http://www.apache.org/licenses/LICENSE-2.0
18 //
19 // Unless required by applicable law or agreed to in writing, software
20 // distributed under the License is distributed on an "AS IS" BASIS,
21 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
22 // See the License for the specific language governing permissions and
23 // limitations under the License.
24 
25 #ifndef INCLUDED_LoadCalibration_h_GUID_50FCDBB2_367E_4589_A034_FCFDF13C8714
26 #define INCLUDED_LoadCalibration_h_GUID_50FCDBB2_367E_4589_A034_FCFDF13C8714
27 
28 // Internal Includes
29 // - none
30 
31 // Library/third-party includes
32 #include <json/reader.h>
33 #include <json/value.h>
34 #include <opencv2/core/core.hpp>
35 
36 // Standard includes
37 #include <fstream>
38 #include <iostream>
39 #include <vector>
40 
41 namespace osvr {
42 namespace vbtracker {
43 
46  inline cv::Point3f parsePoint(Json::Value const &jsonArray) {
47  return cv::Point3f(jsonArray[0].asFloat(), jsonArray[1].asFloat(),
48  jsonArray[2].asFloat());
49  }
50 
51  inline std::vector<cv::Point3f>
52  parseArrayOfPoints(Json::Value const &jsonArray) {
54  std::vector<cv::Point3f> ret;
55  if (!jsonArray.isArray()) {
56  return ret;
57  }
58  for (auto &entry : jsonArray) {
59 
60  if (!entry.isArray() || entry.size() != 3) {
61  ret.clear();
62  return ret;
63  }
64  ret.emplace_back(parsePoint(entry));
65  }
66  return ret;
67  }
68 
69  inline std::vector<cv::Point3f>
70  tryLoadingArrayOfPointsFromFile(std::string const &filename) {
71  std::vector<cv::Point3f> ret;
72  if (filename.empty()) {
73  return ret;
74  }
75  Json::Value root;
76  {
77  std::ifstream calibfile(filename);
78  if (!calibfile.good()) {
79  return ret;
80  }
81  Json::Reader reader;
82  if (!reader.parse(calibfile, root)) {
83  return ret;
84  }
85  }
86  ret = parseArrayOfPoints(root);
87  return ret;
88  }
90 
93  static const double BEACON_AUTOCALIB_ERROR_SCALE_IF_CALIBRATED = 0.1;
94 
95  namespace messages {
96  inline void loadedCalibFileSuccessfully(std::string const &filename) {
97  std::cout << "Video-based tracker: Successfully loaded "
98  "beacon calibration file "
99  << filename << std::endl;
100  }
101 
102  inline void
103  calibFileSpecifiedButNotLoaded(std::string const &filename) {
104  std::cout << "Video-based tracker: NOTE: Beacon calibration "
105  "filename "
106  << filename
107  << " was specified, but not found or could not "
108  "be loaded. This is not an error: This may just mean "
109  "you have not run the optional beacon "
110  "pre-calibration step."
111  << std::endl;
112  }
113  } // namespace messages
114 
115 } // namespace vbtracker
116 } // namespace osvr
117 
118 #endif // INCLUDED_LoadCalibration_h_GUID_50FCDBB2_367E_4589_A034_FCFDF13C8714
std::vector< cv::Point3f > parseArrayOfPoints(Json::Value const &jsonArray)
Definition: LoadCalibration.h:52
Definition: CommonComponent.h:44
The main namespace for all C++ elements of the framework, internal and external.
Definition: namespace_osvr.dox:3