From 8bf58b412d2b9c5cd3f1e1215c5ae9462d494888 Mon Sep 17 00:00:00 2001 From: Stanislaw Halik Date: Mon, 20 Jul 2015 08:08:58 +0200 Subject: calibration: rewrite - Intrinsics are floats, not doubles. - Try searching for calibration filename with fov specified first, then without fov. - Grab image width and height from calibration file, don't asume 640x480 --- opentrack/opencv-calibration.hpp | 42 +++++++++++++++++++++++++--------------- 1 file changed, 26 insertions(+), 16 deletions(-) diff --git a/opentrack/opencv-calibration.hpp b/opentrack/opencv-calibration.hpp index 71f30850..99e6d4c7 100644 --- a/opentrack/opencv-calibration.hpp +++ b/opentrack/opencv-calibration.hpp @@ -14,21 +14,31 @@ #include template -bool get_camera_calibration(const QString& camera_name, cv::Mat& intrinsics, cv::Mat& distortion, int w, int h) +bool get_camera_calibration(const QString& camera_name, cv::Mat& intrinsics, cv::Mat& distortion, int w, int h, int fov) { - 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; + const QString pathnames[] = { + QCoreApplication::applicationDirPath() + "/camera/" + camera_name + "-" + QString::number(fov) + ".yml", + QCoreApplication::applicationDirPath() + "/camera/" + camera_name + ".yml", + }; + for (auto& pathname : pathnames) + { + cv::FileStorage fs(pathname.toStdString(), cv::FileStorage::READ); + if (!fs.isOpened()) + continue; + cv::Mat intrinsics_, distortion_; + fs["camera_matrix"] >> intrinsics_; + fs["distortion_coefficients"] >> distortion_; + int w_, h_; + fs["image_width"] >> w_; + fs["image_height"] >> h_; + double w__ = w_, h__ = h_; + intrinsics_.at(0, 0) *= w / w__; + intrinsics_.at(2, 0) *= w / w__; + intrinsics_.at(1, 1) *= h / h__; + intrinsics_.at(2, 1) *= h / h__; + intrinsics = intrinsics_; + distortion = distortion_; + return true; + } + return false; } -- cgit v1.2.3