summaryrefslogtreecommitdiffhomepage
path: root/opentrack/opencv-calibration.hpp
diff options
context:
space:
mode:
authorStanislaw Halik <sthalik@misaki.pl>2015-07-13 19:04:22 +0200
committerStanislaw Halik <sthalik@misaki.pl>2015-07-13 19:04:30 +0200
commit279d6c1b0534edd7c49f2f1fbf56acf9ed1c4a21 (patch)
tree7a89a52bace10932625e47320c77d3e661fc2b9c /opentrack/opencv-calibration.hpp
parentedfde661b2d1ff0b891056b22dc7ca2f92b62206 (diff)
allow for camera calibration
Diffstat (limited to 'opentrack/opencv-calibration.hpp')
-rw-r--r--opentrack/opencv-calibration.hpp26
1 files changed, 26 insertions, 0 deletions
diff --git a/opentrack/opencv-calibration.hpp b/opentrack/opencv-calibration.hpp
new file mode 100644
index 00000000..6dee9908
--- /dev/null
+++ b/opentrack/opencv-calibration.hpp
@@ -0,0 +1,26 @@
+#pragma once
+#include <QCoreApplication>
+#include <QString>
+#include <QByteArray>
+#include <string>
+#include <opencv2/core.hpp>
+
+template<typename = void>
+bool get_camera_calibration(const QString& camera_name, cv::Mat& intrinsics, cv::Mat& distortion, int w, int h)
+{
+ QString pathname_ = QCoreApplication::applicationDirPath() + "/camera/" + camera_name + ".yml";
+ std::string pathname = pathname_.toStdString();
+ cv::FileStorage fs(pathname, cv::FileStorage::READ);
+ if (!fs.isOpened())
+ return false;
+ cv::Mat intrinsics_, distortion_;
+ fs["camera_matrix"] >> intrinsics_;
+ fs["distortion_coefficients"] >> distortion_;
+ intrinsics_.at<double>(0, 0) *= w / 640.;
+ intrinsics_.at<double>(2, 0) *= w / 640.;
+ intrinsics_.at<double>(1, 1) *= h / 480.;
+ intrinsics_.at<double>(2, 1) *= h / 480.;
+ intrinsics = intrinsics_;
+ distortion = distortion_;
+ return true;
+}