mirror of
https://github.com/opencv/opencv.git
synced 2026-07-25 21:33:04 +04:00
6ca45a9d33
Move Aruco tutorials and samples to main repo #23018 merge with https://github.com/opencv/opencv_contrib/pull/3401 merge with https://github.com/opencv/opencv_extra/pull/1143 ### Pull Request Readiness Checklist See details at https://github.com/opencv/opencv/wiki/How_to_contribute#making-a-good-pull-request - [x] I agree to contribute to the project under Apache 2 License. - [x] To the best of my knowledge, the proposed patch is not based on a code under GPL or another license that is incompatible with OpenCV - [x] The PR is proposed to the proper branch - [ ] There is a reference to the original bug report and related work - [ ] There is accuracy test, performance test and test data in opencv_extra repository, if applicable Patch to opencv_extra has the same branch name. - [ ] The feature is well documented and sample code can be built with the project CMake --------- Co-authored-by: AleksandrPanov <alexander.panov@xperience.ai> Co-authored-by: Alexander Smorkalov <alexander.smorkalov@xperience.ai>
49 lines
1.7 KiB
C++
49 lines
1.7 KiB
C++
#include <opencv2/highgui.hpp>
|
|
#include <opencv2/objdetect/aruco_detector.hpp>
|
|
#include <opencv2/calib3d.hpp>
|
|
#include <ctime>
|
|
|
|
namespace {
|
|
inline static bool readCameraParameters(const std::string& filename, cv::Mat &camMatrix, cv::Mat &distCoeffs) {
|
|
cv::FileStorage fs(filename, cv::FileStorage::READ);
|
|
if (!fs.isOpened())
|
|
return false;
|
|
fs["camera_matrix"] >> camMatrix;
|
|
fs["distortion_coefficients"] >> distCoeffs;
|
|
return true;
|
|
}
|
|
|
|
inline static bool saveCameraParams(const std::string &filename, cv::Size imageSize, float aspectRatio, int flags,
|
|
const cv::Mat &cameraMatrix, const cv::Mat &distCoeffs, double totalAvgErr) {
|
|
cv::FileStorage fs(filename, cv::FileStorage::WRITE);
|
|
if (!fs.isOpened())
|
|
return false;
|
|
|
|
time_t tt;
|
|
time(&tt);
|
|
struct tm *t2 = localtime(&tt);
|
|
char buf[1024];
|
|
strftime(buf, sizeof(buf) - 1, "%c", t2);
|
|
|
|
fs << "calibration_time" << buf;
|
|
fs << "image_width" << imageSize.width;
|
|
fs << "image_height" << imageSize.height;
|
|
|
|
if (flags & cv::CALIB_FIX_ASPECT_RATIO) fs << "aspectRatio" << aspectRatio;
|
|
|
|
if (flags != 0) {
|
|
sprintf(buf, "flags: %s%s%s%s",
|
|
flags & cv::CALIB_USE_INTRINSIC_GUESS ? "+use_intrinsic_guess" : "",
|
|
flags & cv::CALIB_FIX_ASPECT_RATIO ? "+fix_aspectRatio" : "",
|
|
flags & cv::CALIB_FIX_PRINCIPAL_POINT ? "+fix_principal_point" : "",
|
|
flags & cv::CALIB_ZERO_TANGENT_DIST ? "+zero_tangent_dist" : "");
|
|
}
|
|
fs << "flags" << flags;
|
|
fs << "camera_matrix" << cameraMatrix;
|
|
fs << "distortion_coefficients" << distCoeffs;
|
|
fs << "avg_reprojection_error" << totalAvgErr;
|
|
return true;
|
|
}
|
|
|
|
}
|