argagg
Loading...
Searching...
No Matches
opencv.hpp
Go to the documentation of this file.
1/*
2 * @file
3 * @brief
4 * Defines argument conversion specializations for OpenCV.
5 *
6 * @copyright
7 * Copyright (c) 2018 Viet The Nguyen
8 *
9 * @copyright
10 * Permission is hereby granted, free of charge, to any person obtaining a copy
11 * of this software and associated documentation files (the "Software"), to
12 * deal in the Software without restriction, including without limitation the
13 * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
14 * sell copies of the Software, and to permit persons to whom the Software is
15 * furnished to do so, subject to the following conditions:
16 *
17 * @copyright
18 * The above copyright notice and this permission notice shall be included in
19 * all copies or substantial portions of the Software.
20 *
21 * @copyright
22 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
23 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
24 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
25 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
26 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
27 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
28 * IN THE SOFTWARE.
29 */
30#pragma once
31#ifndef ARGAGG_ARGAGG_CONVERT_OPENCV_HPP
32#define ARGAGG_ARGAGG_CONVERT_OPENCV_HPP
33
34#include "../argagg.hpp"
35
36#include <opencv2/opencv.hpp>
37
38#include <vector>
39
40
41namespace argagg {
42namespace convert {
43
49 template <typename T>
50 struct converter<cv::Point_<T>> {
51 static cv::Point_<T> convert(const char* s);
52 };
53
59 template <typename T>
60 struct converter<cv::Point3_<T>> {
61 static cv::Point3_<T> convert(const char* s);
62 };
63
70 template <typename T>
71 struct converter<cv::Size_<T>> {
72 static cv::Size_<T> convert(const char* s);
73 };
74
80 template <typename T>
81 struct converter<cv::Rect_<T>> {
82 static cv::Rect_<T> convert(const char* s);
83 };
84
85} // namespace convert
86
87} // namespace argagg
88
89
90// ---- end of declarations, header-only implementations follow ----
91
92
93namespace argagg {
94namespace convert {
95
96
97template <typename T>
98cv::Point_<T>
99converter<cv::Point_<T>>::convert(const char* s)
100{
101 cv::Point_<T> result {0, 0};
102 if (!parse_next_component(s, result.x)) {
103 return result;
104 }
105 if (!parse_next_component(s, result.y)) {
106 return result;
107 }
108 return result;
109}
110
111
112template <typename T>
113cv::Point3_<T>
114converter<cv::Point3_<T>>::convert(const char* s)
115{
116 cv::Point3_<T> result {0, 0, 0};
117 if (!parse_next_component(s, result.x)) {
118 return result;
119 }
120 if (!parse_next_component(s, result.y)) {
121 return result;
122 }
123 if (!parse_next_component(s, result.z)) {
124 return result;
125 }
126 return result;
127}
128
129
130template <typename T>
131cv::Size_<T>
132converter<cv::Size_<T>>::convert(const char* s)
133{
134 cv::Size_<T> result {0, 0};
135 if (!parse_next_component(s, result.width, 'x')) {
136 return result;
137 }
138 if (!parse_next_component(s, result.height, 'x')) {
139 return result;
140 }
141 return result;
142}
143
144
145template <typename T>
146cv::Rect_<T>
147converter<cv::Rect_<T>>::convert(const char* s)
148{
149 cv::Rect_<T> result {0, 0, 0, 0};
150 if (!parse_next_component(s, result.x)) {
151 return result;
152 }
153 if (!parse_next_component(s, result.y)) {
154 return result;
155 }
156 if (!parse_next_component(s, result.width)) {
157 return result;
158 }
159 if (!parse_next_component(s, result.height)) {
160 return result;
161 }
162 return result;
163}
164
165
166} // namespace convert
167} // namespace argagg
168
169
170#endif // ARGAGG_ARGAGG_CONVERT_OPENCV_HPP
bool parse_next_component(const char *&s, T &out_arg, const char delim=',')
A utility function for parsing an argument as a delimited list. To use, initialize a const char* poin...
Definition argagg.hpp:1552
T arg(const char *arg)
Explicit instantiations of this function are used to convert arguments to types.
Definition argagg.hpp:1488
There are only two hard things in Computer Science: cache invalidation and naming things (Phil Karlto...
Definition argagg.hpp:96
For simple types the main extension point for adding argument conversions is argagg::convert::arg<T>(...
Definition argagg.hpp:186