JeVois  1.21
JeVois Smart Embedded Machine Vision Toolkit
Share this page:
Loading...
Searching...
No Matches
CameraCalibration.C
Go to the documentation of this file.
1// ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////
2//
3// JeVois Smart Embedded Machine Vision Toolkit - Copyright (C) 2024 by Laurent Itti, the University of Southern
4// California (USC), and iLab at USC. See http://iLab.usc.edu and http://jevois.org for information about this project.
5//
6// This file is part of the JeVois Smart Embedded Machine Vision Toolkit. This program is free software; you can
7// redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software
8// Foundation, version 2. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
9// without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
10// License for more details. You should have received a copy of the GNU General Public License along with this program;
11// if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
12//
13// Contact information: Laurent Itti - 3641 Watt Way, HNB-07A - Los Angeles, CA 90089-2520 - USA.
14// Tel: +1 213 740 3527 - itti@pollux.usc.edu - http://iLab.usc.edu - http://jevois.org
15// ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////
16/*! \file */
17
19#include <jevois/Util/Utils.H>
20#include <ctime>
21
22// ####################################################################################################
23void jevois::CameraCalibration::load(std::string const & fname)
24{
25 cv::FileStorage fs(fname, cv::FileStorage::READ);
26 if (fs.isOpened() == false) throw std::runtime_error("Failed to load [" + fname + ']');
27 std::string str;
28 fs["sensor"] >> str; sensor = jevois::from_string<jevois::CameraSensor>(str);
29 fs["lens"] >> str; lens = jevois::from_string<jevois::CameraLens>(str);
30 fs["image_width"] >> w;
31 fs["image_height"] >> h;
32 fs["camera_matrix"] >> camMatrix;
33 fs["distortion_coefficients"] >> distCoeffs;
34 fs["avg_reprojection_error"] >> avgReprojErr;
35}
36
37// ####################################################################################################
38void jevois::CameraCalibration::save(std::string const & fname) const
39{
40 cv::FileStorage fs(fname, cv::FileStorage::WRITE);
41 if (fs.isOpened() == false) throw std::runtime_error("Failed to save [" + fname + ']');
42
43 time_t tm;
44 time(&tm);
45 struct tm *t2 = localtime(&tm);
46 char buf[1024];
47 strftime(buf, sizeof(buf), "%c", t2);
48
49 fs << "calibration_time" << buf;
50 fs << "sensor" << jevois::to_string(sensor);
51 fs << "lens" << jevois::to_string(lens);
52 fs << "image_width" << w;
53 fs << "image_height" << h;
54 fs << "camera_matrix" << camMatrix;
55 fs << "distortion_coefficients" << distCoeffs;
56 fs << "avg_reprojection_error" << avgReprojErr;
57}
int h
Definition GUIhelper.C:2491
void save(std::string const &fname) const
Save to file.
jevois::CameraLens lens
Camera lens.
cv::Mat camMatrix
3x3 camera matrix
cv::Mat distCoeffs
5x1 distortion coefficients
double avgReprojErr
Average reprojection error.
int h
Image width and height (camera resolution)
jevois::CameraSensor sensor
Camera sensor.
void load(std::string const &fname)
Load from file.
std::string to_string(T const &val)
Convert from type to string.