61 # pragma warning(push)
62 # pragma warning(disable : 4251) // "X needs to have dll-interface to be used by clients of class Y."
71 static constexpr
size_t version{ 1 };
84 CameraIntrinsics(
const CameraIntrinsics &other);
87 CameraIntrinsics &operator=(
const CameraIntrinsics &other);
90 CameraIntrinsics(CameraIntrinsics &&other) noexcept;
93 CameraIntrinsics &operator=(CameraIntrinsics &&other) noexcept;
96 CameraIntrinsics() =
default;
99 static constexpr
bool isContainer{
true };
102 static constexpr
const char *path{
"" };
105 static constexpr
const char *name{
"CameraIntrinsics" };
108 static constexpr
const char *description{
109 R
"description(Information about the intrinsic parameters of the camera (OpenCV model))description"
113 void set(
const std::string &fullPath,
const std::string &value);
116 std::string getString(
const std::string &fullPath)
const;
123 CameraMatrix() =
default;
126 static constexpr
bool isContainer{
true };
129 static constexpr
const char *path{
"CameraMatrix" };
132 static constexpr
const char *name{
"CameraMatrix" };
135 static constexpr
const char *description{
136 R
"description(The camera matrix K (=[fx,0,cx;0,fy,cy;0,0,1]))description"
140 void set(
const std::string &fullPath,
const std::string &value);
143 std::string getString(
const std::string &fullPath)
const;
150 using ValueType = double;
153 static constexpr
bool isContainer{
false };
156 static constexpr
const char *path{
"CameraMatrix/CX" };
159 static constexpr
const char *name{
"CX" };
162 static constexpr
const char *description{
163 R
"description(x coordinate of the principal point)description"
170 explicit constexpr CX(ValueType value) noexcept(std::is_nothrow_copy_constructible<ValueType>::value)
175 const ValueType &value()
const
183 return { std::numeric_limits<ValueType>::lowest(), std::numeric_limits<ValueType>::max() };
187 void setFromString(
const std::string &value)
189 m_value = std::stod(value);
195 return std::to_string(m_value);
199 bool operator==(
const CX &other)
const
201 return m_value == other.m_value;
205 bool operator!=(
const CX &other)
const
207 return m_value != other.m_value;
211 bool operator<(
const CX &other)
const
213 return m_value < other.m_value;
217 bool operator>(
const CX &other)
const
219 return m_value > other.m_value;
223 friend std::ostream &
operator<<(std::ostream &stream,
const CX &value)
225 return stream << value.toString();
229 friend std::istream &operator>>(std::istream &stream,
CX &value)
232 std::string{ std::istreambuf_iterator<char>{ stream }, std::istreambuf_iterator<char>{} });
248 static constexpr
bool isContainer{
false };
251 static constexpr
const char *path{
"CameraMatrix/CY" };
254 static constexpr
const char *name{
"CY" };
257 static constexpr
const char *description{
258 R
"description(y coordinate of the principal point)description"
265 explicit constexpr
CY(
ValueType value) noexcept(std::is_nothrow_copy_constructible<ValueType>::value)
270 const ValueType &value()
const
278 return { std::numeric_limits<ValueType>::lowest(), std::numeric_limits<ValueType>::max() };
282 void setFromString(
const std::string &value)
284 m_value = std::stod(value);
290 return std::to_string(m_value);
294 bool operator==(
const CY &other)
const
296 return m_value == other.m_value;
300 bool operator!=(
const CY &other)
const
302 return m_value != other.m_value;
306 bool operator<(
const CY &other)
const
308 return m_value < other.m_value;
312 bool operator>(
const CY &other)
const
314 return m_value > other.m_value;
318 friend std::ostream &
operator<<(std::ostream &stream,
const CY &value)
320 return stream << value.toString();
324 friend std::istream &operator>>(std::istream &stream,
CY &value)
327 std::string{ std::istreambuf_iterator<char>{ stream }, std::istreambuf_iterator<char>{} });
343 static constexpr
bool isContainer{
false };
346 static constexpr
const char *path{
"CameraMatrix/FX" };
349 static constexpr
const char *name{
"FX" };
352 static constexpr
const char *description{ R
"description(Focal length in x)description" };
358 explicit constexpr
FX(
ValueType value) noexcept(std::is_nothrow_copy_constructible<ValueType>::value)
371 return { std::numeric_limits<ValueType>::lowest(), std::numeric_limits<ValueType>::max() };
375 void setFromString(
const std::string &value)
377 m_value = std::stod(value);
383 return std::to_string(m_value);
387 bool operator==(
const FX &other)
const
389 return m_value == other.m_value;
393 bool operator!=(
const FX &other)
const
395 return m_value != other.m_value;
399 bool operator<(
const FX &other)
const
401 return m_value < other.m_value;
405 bool operator>(
const FX &other)
const
407 return m_value > other.m_value;
411 friend std::ostream &
operator<<(std::ostream &stream,
const FX &value)
417 friend std::istream &operator>>(std::istream &stream,
FX &value)
420 std::string{ std::istreambuf_iterator<char>{ stream }, std::istreambuf_iterator<char>{} });
436 static constexpr
bool isContainer{
false };
439 static constexpr
const char *path{
"CameraMatrix/FY" };
442 static constexpr
const char *name{
"FY" };
445 static constexpr
const char *description{ R
"description(Focal length in y)description" };
451 explicit constexpr
FY(
ValueType value) noexcept(std::is_nothrow_copy_constructible<ValueType>::value)
464 return { std::numeric_limits<ValueType>::lowest(), std::numeric_limits<ValueType>::max() };
468 void setFromString(
const std::string &value)
470 m_value = std::stod(value);
476 return std::to_string(m_value);
480 bool operator==(
const FY &other)
const
482 return m_value == other.m_value;
486 bool operator!=(
const FY &other)
const
488 return m_value != other.m_value;
492 bool operator<(
const FY &other)
const
494 return m_value < other.m_value;
498 bool operator>(
const FY &other)
const
500 return m_value > other.m_value;
504 friend std::ostream &
operator<<(std::ostream &stream,
const FY &value)
510 friend std::istream &operator>>(std::istream &stream,
FY &value)
513 std::string{ std::istreambuf_iterator<char>{ stream }, std::istreambuf_iterator<char>{} });
522 typename std::enable_if<std::is_same<T, CameraIntrinsics::CameraMatrix::CX>::value,
int>::type = 0>
529 typename std::enable_if<std::is_same<T, CameraIntrinsics::CameraMatrix::CY>::value,
int>::type = 0>
536 typename std::enable_if<std::is_same<T, CameraIntrinsics::CameraMatrix::FX>::value,
int>::type = 0>
543 typename std::enable_if<std::is_same<T, CameraIntrinsics::CameraMatrix::FY>::value,
int>::type = 0>
549 template<size_t i, typename std::enable_if<i == 0, int>::type = 0>
555 template<size_t i, typename std::enable_if<i == 1, int>::type = 0>
561 template<size_t i, typename std::enable_if<i == 2, int>::type = 0>
567 template<size_t i, typename std::enable_if<i == 3, int>::type = 0>
585 throw std::out_of_range(
"CX{ " + std::to_string(value.
value()) +
" } is not in range ["
586 + std::to_string(value.
range().min()) +
", "
587 + std::to_string(value.
range().max()) +
"]");
608 throw std::out_of_range(
"CY{ " + std::to_string(value.
value()) +
" } is not in range ["
609 + std::to_string(value.
range().min()) +
", "
610 + std::to_string(value.
range().max()) +
"]");
629 if(value.value() < value.range().min() || value.value() > value.range().max())
631 throw std::out_of_range(
"FX{ " + std::to_string(value.value()) +
" } is not in range ["
632 + std::to_string(value.range().min()) +
", "
633 + std::to_string(value.range().max()) +
"]");
654 throw std::out_of_range(
"FY{ " + std::to_string(value.
value()) +
" } is not in range ["
655 + std::to_string(value.
range().min()) +
", "
656 + std::to_string(value.
range().max()) +
"]");
670 void forEach(
const F &f)
const
680 void forEach(
const F &f)
690 void traverseValues(
const F &f)
const
700 void traverseValues(
const F &f)
718 void setFromString(
const std::string &value);
721 friend std::istream &operator>>(std::istream &stream,
CameraMatrix &value)
724 std::string{ std::istreambuf_iterator<char>{ stream }, std::istreambuf_iterator<char>{} });
743 static constexpr
bool isContainer{
true };
746 static constexpr
const char *path{
"Distortion" };
749 static constexpr
const char *name{
"Distortion" };
752 static constexpr
const char *description{
753 R
"description(The radial and tangential distortion parameters)description"
757 void set(
const std::string &fullPath,
const std::string &value);
760 std::string getString(
const std::string &fullPath)
const;
767 using ValueType = double;
770 static constexpr
bool isContainer{
false };
773 static constexpr
const char *path{
"Distortion/K1" };
776 static constexpr
const char *name{
"K1" };
779 static constexpr
const char *description{ R
"description(First radial distortion term)description" };
785 explicit constexpr K1(ValueType value) noexcept(std::is_nothrow_copy_constructible<ValueType>::value)
790 const ValueType &value()
const
798 return { std::numeric_limits<ValueType>::lowest(), std::numeric_limits<ValueType>::max() };
802 void setFromString(
const std::string &value)
804 m_value = std::stod(value);
810 return std::to_string(m_value);
814 bool operator==(
const K1 &other)
const
816 return m_value == other.m_value;
820 bool operator!=(
const K1 &other)
const
822 return m_value != other.m_value;
826 bool operator<(
const K1 &other)
const
828 return m_value < other.m_value;
832 bool operator>(
const K1 &other)
const
834 return m_value > other.m_value;
838 friend std::ostream &
operator<<(std::ostream &stream,
const K1 &value)
840 return stream << value.toString();
844 friend std::istream &operator>>(std::istream &stream,
K1 &value)
847 std::string{ std::istreambuf_iterator<char>{ stream }, std::istreambuf_iterator<char>{} });
863 static constexpr
bool isContainer{
false };
866 static constexpr
const char *path{
"Distortion/K2" };
869 static constexpr
const char *name{
"K2" };
872 static constexpr
const char *description{ R
"description(Second radial distortion term)description" };
878 explicit constexpr
K2(
ValueType value) noexcept(std::is_nothrow_copy_constructible<ValueType>::value)
891 return { std::numeric_limits<ValueType>::lowest(), std::numeric_limits<ValueType>::max() };
895 void setFromString(
const std::string &value)
897 m_value = std::stod(value);
903 return std::to_string(m_value);
907 bool operator==(
const K2 &other)
const
909 return m_value == other.m_value;
913 bool operator!=(
const K2 &other)
const
915 return m_value != other.m_value;
919 bool operator<(
const K2 &other)
const
921 return m_value < other.m_value;
925 bool operator>(
const K2 &other)
const
927 return m_value > other.m_value;
931 friend std::ostream &
operator<<(std::ostream &stream,
const K2 &value)
937 friend std::istream &operator>>(std::istream &stream,
K2 &value)
940 std::string{ std::istreambuf_iterator<char>{ stream }, std::istreambuf_iterator<char>{} });
956 static constexpr
bool isContainer{
false };
959 static constexpr
const char *path{
"Distortion/K3" };
962 static constexpr
const char *name{
"K3" };
965 static constexpr
const char *description{ R
"description(Third radial distortion term)description" };
971 explicit constexpr
K3(
ValueType value) noexcept(std::is_nothrow_copy_constructible<ValueType>::value)
984 return { std::numeric_limits<ValueType>::lowest(), std::numeric_limits<ValueType>::max() };
988 void setFromString(
const std::string &value)
990 m_value = std::stod(value);
996 return std::to_string(m_value);
1000 bool operator==(
const K3 &other)
const
1002 return m_value == other.m_value;
1006 bool operator!=(
const K3 &other)
const
1008 return m_value != other.m_value;
1012 bool operator<(
const K3 &other)
const
1014 return m_value < other.m_value;
1018 bool operator>(
const K3 &other)
const
1020 return m_value > other.m_value;
1024 friend std::ostream &
operator<<(std::ostream &stream,
const K3 &value)
1030 friend std::istream &operator>>(std::istream &stream,
K3 &value)
1033 std::string{ std::istreambuf_iterator<char>{ stream }, std::istreambuf_iterator<char>{} });
1049 static constexpr
bool isContainer{
false };
1052 static constexpr
const char *path{
"Distortion/P1" };
1055 static constexpr
const char *name{
"P1" };
1058 static constexpr
const char *description{ R
"description(First tangential distortion term)description" };
1064 explicit constexpr
P1(
ValueType value) noexcept(std::is_nothrow_copy_constructible<ValueType>::value)
1077 return { std::numeric_limits<ValueType>::lowest(), std::numeric_limits<ValueType>::max() };
1081 void setFromString(
const std::string &value)
1083 m_value = std::stod(value);
1089 return std::to_string(m_value);
1093 bool operator==(
const P1 &other)
const
1095 return m_value == other.m_value;
1099 bool operator!=(
const P1 &other)
const
1101 return m_value != other.m_value;
1105 bool operator<(
const P1 &other)
const
1107 return m_value < other.m_value;
1111 bool operator>(
const P1 &other)
const
1113 return m_value > other.m_value;
1117 friend std::ostream &
operator<<(std::ostream &stream,
const P1 &value)
1123 friend std::istream &operator>>(std::istream &stream,
P1 &value)
1126 std::string{ std::istreambuf_iterator<char>{ stream }, std::istreambuf_iterator<char>{} });
1142 static constexpr
bool isContainer{
false };
1145 static constexpr
const char *path{
"Distortion/P2" };
1148 static constexpr
const char *name{
"P2" };
1151 static constexpr
const char *description{
1152 R
"description(Second tangential distortion term)description"
1159 explicit constexpr
P2(
ValueType value) noexcept(std::is_nothrow_copy_constructible<ValueType>::value)
1164 const ValueType &value()
const
1172 return { std::numeric_limits<ValueType>::lowest(), std::numeric_limits<ValueType>::max() };
1176 void setFromString(
const std::string &value)
1178 m_value = std::stod(value);
1184 return std::to_string(m_value);
1188 bool operator==(
const P2 &other)
const
1190 return m_value == other.m_value;
1194 bool operator!=(
const P2 &other)
const
1196 return m_value != other.m_value;
1200 bool operator<(
const P2 &other)
const
1202 return m_value < other.m_value;
1206 bool operator>(
const P2 &other)
const
1208 return m_value > other.m_value;
1212 friend std::ostream &
operator<<(std::ostream &stream,
const P2 &value)
1214 return stream << value.toString();
1218 friend std::istream &operator>>(std::istream &stream,
P2 &value)
1221 std::string{ std::istreambuf_iterator<char>{ stream }, std::istreambuf_iterator<char>{} });
1229 template<
typename T,
1230 typename std::enable_if<std::is_same<T, CameraIntrinsics::Distortion::K1>::value,
int>::type = 0>
1236 template<
typename T,
1237 typename std::enable_if<std::is_same<T, CameraIntrinsics::Distortion::K2>::value,
int>::type = 0>
1243 template<
typename T,
1244 typename std::enable_if<std::is_same<T, CameraIntrinsics::Distortion::K3>::value,
int>::type = 0>
1250 template<
typename T,
1251 typename std::enable_if<std::is_same<T, CameraIntrinsics::Distortion::P1>::value,
int>::type = 0>
1257 template<
typename T,
1258 typename std::enable_if<std::is_same<T, CameraIntrinsics::Distortion::P2>::value,
int>::type = 0>
1264 template<size_t i, typename std::enable_if<i == 0, int>::type = 0>
1270 template<size_t i, typename std::enable_if<i == 1, int>::type = 0>
1276 template<size_t i, typename std::enable_if<i == 2, int>::type = 0>
1282 template<size_t i, typename std::enable_if<i == 3, int>::type = 0>
1288 template<size_t i, typename std::enable_if<i == 4, int>::type = 0>
1306 throw std::out_of_range(
"K1{ " + std::to_string(value.
value()) +
" } is not in range ["
1307 + std::to_string(value.
range().min()) +
", "
1308 + std::to_string(value.
range().max()) +
"]");
1315 const K1 &k1()
const
1325 Distortion &set(
const K2 &value)
1327 if(value.value() < value.range().min() || value.value() > value.range().max())
1329 throw std::out_of_range(
"K2{ " + std::to_string(value.value()) +
" } is not in range ["
1330 + std::to_string(value.range().min()) +
", "
1331 + std::to_string(value.range().max()) +
"]");
1350 if(value.value() < value.range().min() || value.value() > value.range().max())
1352 throw std::out_of_range(
"K3{ " + std::to_string(value.value()) +
" } is not in range ["
1353 + std::to_string(value.range().min()) +
", "
1354 + std::to_string(value.range().max()) +
"]");
1361 const K3 &k3()
const
1375 throw std::out_of_range(
"P1{ " + std::to_string(value.
value()) +
" } is not in range ["
1376 + std::to_string(value.
range().min()) +
", "
1377 + std::to_string(value.
range().max()) +
"]");
1384 const P1 &p1()
const
1398 throw std::out_of_range(
"P2{ " + std::to_string(value.
value()) +
" } is not in range ["
1399 + std::to_string(value.
range().min()) +
", "
1400 + std::to_string(value.
range().max()) +
"]");
1407 const P2 &p2()
const
1413 template<
typename F>
1414 void forEach(
const F &f)
const
1424 template<
typename F>
1425 void forEach(
const F &f)
1435 template<
typename F>
1436 void traverseValues(
const F &f)
const
1446 template<
typename F>
1447 void traverseValues(
const F &f)
1466 void setFromString(
const std::string &value);
1469 friend std::istream &operator>>(std::istream &stream,
Distortion &value)
1472 std::string{ std::istreambuf_iterator<char>{ stream }, std::istreambuf_iterator<char>{} });
1477 bool operator==(
const Distortion &other)
const;
1480 bool operator!=(
const Distortion &other)
const;
1483 template<
typename T,
1484 typename std::enable_if<std::is_same<T, CameraIntrinsics::CameraMatrix>::value,
int>::type = 0>
1487 return m_cameraMatrix;
1490 template<
typename T,
1491 typename std::enable_if<std::is_same<T, CameraIntrinsics::CameraMatrix::CX>::value,
int>::type = 0>
1497 template<
typename T,
1498 typename std::enable_if<std::is_same<T, CameraIntrinsics::CameraMatrix::CY>::value,
int>::type = 0>
1504 template<
typename T,
1505 typename std::enable_if<std::is_same<T, CameraIntrinsics::CameraMatrix::FX>::value,
int>::type = 0>
1511 template<
typename T,
1512 typename std::enable_if<std::is_same<T, CameraIntrinsics::CameraMatrix::FY>::value,
int>::type = 0>
1518 template<
typename T,
1519 typename std::enable_if<std::is_same<T, CameraIntrinsics::Distortion>::value,
int>::type = 0>
1522 return m_distortion;
1525 template<
typename T,
1526 typename std::enable_if<std::is_same<T, CameraIntrinsics::Distortion::K1>::value,
int>::type = 0>
1532 template<
typename T,
1533 typename std::enable_if<std::is_same<T, CameraIntrinsics::Distortion::K2>::value,
int>::type = 0>
1539 template<
typename T,
1540 typename std::enable_if<std::is_same<T, CameraIntrinsics::Distortion::K3>::value,
int>::type = 0>
1546 template<
typename T,
1547 typename std::enable_if<std::is_same<T, CameraIntrinsics::Distortion::P1>::value,
int>::type = 0>
1553 template<
typename T,
1554 typename std::enable_if<std::is_same<T, CameraIntrinsics::Distortion::P2>::value,
int>::type = 0>
1560 template<size_t i, typename std::enable_if<i == 0, int>::type = 0>
1563 return m_cameraMatrix;
1566 template<size_t i, typename std::enable_if<i == 1, int>::type = 0>
1569 return m_distortion;
1582 m_cameraMatrix = value;
1586 const CameraMatrix &cameraMatrix()
const
1588 return m_cameraMatrix;
1594 m_cameraMatrix.
set(value);
1601 m_cameraMatrix.
set(value);
1608 m_cameraMatrix.
set(value);
1615 m_cameraMatrix.
set(value);
1626 m_distortion = value;
1630 const Distortion &distortion()
const
1632 return m_distortion;
1638 m_distortion.
set(value);
1645 m_distortion.
set(value);
1652 m_distortion.
set(value);
1657 CameraIntrinsics &set(
const Distortion::P1 &value)
1659 m_distortion.set(value);
1666 m_distortion.
set(value);
1671 template<
typename F>
1672 void forEach(
const F &f)
const
1679 template<
typename F>
1680 void forEach(
const F &f)
1687 template<
typename F>
1688 void traverseValues(
const F &f)
const
1690 m_cameraMatrix.traverseValues(f);
1691 m_distortion.traverseValues(f);
1695 template<
typename F>
1696 void traverseValues(
const F &f)
1698 m_cameraMatrix.traverseValues(f);
1699 m_distortion.traverseValues(f);
1712 void setFromString(
const std::string &value);
1718 std::string{ std::istreambuf_iterator<char>{ stream }, std::istreambuf_iterator<char>{} });
1732 void save(
const std::string &fileName)
const;
1735 void load(
const std::string &fileName);
1740 struct CameraIntrinsics::Version<1>
1749 # pragma warning(pop)
1753 # if !(defined(_MSC_VER) && (_MSC_VER <= 1900))
1764 = decltype(declval<Zivid::CameraIntrinsics::CameraMatrix>().get<i>());
1775 = decltype(declval<Zivid::CameraIntrinsics::Distortion>().get<i>());
1783 struct tuple_element<i,
Zivid::CameraIntrinsics>
1786 = decltype(declval<Zivid::CameraIntrinsics>().get<i>());