From 279d6c1b0534edd7c49f2f1fbf56acf9ed1c4a21 Mon Sep 17 00:00:00 2001 From: Stanislaw Halik Date: Mon, 13 Jul 2015 19:04:22 +0200 Subject: allow for camera calibration --- opentrack/opencv-calibration.hpp | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 opentrack/opencv-calibration.hpp (limited to 'opentrack') 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 +#include +#include +#include +#include + +template +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(0, 0) *= w / 640.; + intrinsics_.at(2, 0) *= w / 640.; + intrinsics_.at(1, 1) *= h / 480.; + intrinsics_.at(2, 1) *= h / 480.; + intrinsics = intrinsics_; + distortion = distortion_; + return true; +} -- cgit v1.2.3