BitmapToolkit Scol plugin
ArCameraParam.cpp
Go to the documentation of this file.
1/*
2-----------------------------------------------------------------------------
3This source file is part of OpenSpace3D
4For the latest info, see http://www.openspace3d.com
5
6Copyright (c) 2012 I-maginer
7
8This program is free software; you can redistribute it and/or modify it under
9the terms of the GNU Lesser General Public License as published by the Free Software
10Foundation; either version 2 of the License, or (at your option) any later
11version.
12
13This program is distributed in the hope that it will be useful, but WITHOUT
14ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
15FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
16
17You should have received a copy of the GNU Lesser General Public License along with
18this program; if not, write to the Free Software Foundation, Inc., 59 Temple
19Place - Suite 330, Boston, MA 02111-1307, USA, or go to
20http://www.gnu.org/copyleft/lesser.txt
21
22-----------------------------------------------------------------------------
23*/
24
25#include "ArCameraParam.h"
26#include "Prerequisites.h"
27
28ArCameraParam::ArCameraParam(int width, int height, float nearclip, float farclip, std::string yamlfile)
29{
30 SetBitmapSize(width, height);
31 SetClipping(nearclip, farclip);
32
33 cv::Mat Distorsion=cv::Mat::zeros(5,1,CV_32FC1);
34 cv::Mat CameraMatrix=cv::Mat::eye(3,3,CV_32FC1);
35
36 //set default camera values
37 float f = std::max(bitmapSize.width, bitmapSize.height);
38
39 CameraMatrix.at<float>(0, 0) = f;
40 CameraMatrix.at<float>(0, 2) = static_cast<float>(bitmapSize.width) * 0.5f;
41 CameraMatrix.at<float>(1, 1) = f;
42 CameraMatrix.at<float>(1, 2) = static_cast<float>(bitmapSize.height) * 0.5f;
43
44 Distorsion.at<float>(0, 0) = 0.0f;
45 Distorsion.at<float>(1, 0) = 0.0f;
46 Distorsion.at<float>(2, 0) = 0.0f;
47 Distorsion.at<float>(3, 0) = 0.0f;
48 Distorsion.at<float>(4, 0) = 0.0f;
49
50 camParam = aruco::CameraParameters(CameraMatrix, Distorsion, bitmapSize);
51 SetCameraParameter(yamlfile);
52}
53
54ArCameraParam::ArCameraParam(int width, int height, float nearclip, float farclip, Vector2 &flength, Vector2 &center)
55{
56 SetBitmapSize(width, height);
57 SetClipping(nearclip, farclip);
58
59 cv::Mat Distorsion = cv::Mat::zeros(5, 1, CV_32FC1);
60 cv::Mat CameraMatrix = cv::Mat::eye(3, 3, CV_32FC1);
61
62 CameraMatrix.at<float>(0, 0) = flength.x;
63 CameraMatrix.at<float>(0, 2) = center.x;
64 CameraMatrix.at<float>(1, 1) = flength.y;
65 CameraMatrix.at<float>(1, 2) = center.y;
66
67 Distorsion.at<float>(0, 0) = 0.0f;
68 Distorsion.at<float>(1, 0) = 0.0f;
69 Distorsion.at<float>(2, 0) = 0.0f;
70 Distorsion.at<float>(3, 0) = 0.0f;
71 Distorsion.at<float>(4, 0) = 0.0f;
72
73 camParam = aruco::CameraParameters(CameraMatrix, Distorsion, bitmapSize);
74}
75
79
81{
82 bitmapSize = CI.bitmapSize;
83 camParam = aruco::CameraParameters(CI.camParam);
84 clipping = CI.clipping;
85 mCamQuat = CI.mCamQuat;
87
88 std::vector<ArImuData> cimu = CI.GetCameraImu();
89 std::vector<ArImuData> imuCpy;
90 for (unsigned int i = 0; i < cimu.size(); i++)
91 imuCpy.push_back(ArImuData(Vector3(cimu[i].m_gry), Vector3(cimu[i].m_acc), cimu[i].m_delta));
92 mImuData = imuCpy;
93}
94
95aruco::CameraParameters ArCameraParam::GetCameraParameter()
96{
97 return camParam;
98}
99
100void ArCameraParam::SetCameraParameter(std::string yamlfile)
101{
102 // load yaml calibration file or default values
103 if (!yamlfile.empty())
104 {
105 try
106 {
107 camParam.readFromXMLFile(yamlfile.c_str());
108 }
109 catch (cv::Exception e)
110 {
111 MMechostr(MSKDEBUG, "ArCameraParam::SetCameraParameter cloud not read file : %s", yamlfile.c_str());
112 }
113 }
114}
115
117{
118 return bitmapSize;
119}
120
121void ArCameraParam::SetBitmapSize(int width, int height)
122{
123 bitmapSize.height = height;
124 bitmapSize.width = width;
125}
126
128{
129 return clipping;
130}
131
132void ArCameraParam::SetClipping(float nearclip, float farclip)
133{
134 clipping.x = std::max(0.001f, nearclip);
135 clipping.y = std::max(0.002f, std::min(100000.0f, farclip));
136}
137
138void ArCameraParam::GetProjectionMatrix(double m_proj[16], cv::Size screensize)
139{
140 try
141 {
142 camParam.glGetProjectionMatrix(bitmapSize, screensize, m_proj, clipping.x, clipping.y, true);
143 }
144 catch(cv::Exception e)
145 {
146 MMechostr(MSKDEBUG,"error : %s \n", e.what());
147 }
148}
149
151{
152 mCamQuat = quat;
153}
154
159
160void ArCameraParam::AddCameraImu(Vector3 gyro, Vector3 accel, double delta)
161{
162 mImuData.push_back(ArImuData(gyro, accel, delta));
163}
164
165std::vector<ArImuData> ArCameraParam::GetCameraImu() const
166{
167 return mImuData;
168}
169
171{
172 mImuData.clear();
173}
174
179
181{
182 mCamOffset = offset;
183}
cv::Point2f GetClipping()
void SetCameraOffset(Vector3 offset)
void SetCameraQuat(BtQuaternion quat)
BtQuaternion GetCameraQuat()
void GetProjectionMatrix(double m_proj[16], cv::Size screensize)
void AddCameraImu(Vector3 gyro, Vector3 accel, double delta)
void SetClipping(float nearclip, float farclip)
std::vector< ArImuData > GetCameraImu() const
Vector3 GetCameraOffset()
void SetBitmapSize(int width, int height)
cv::Size GetBitmapSize()
BtQuaternion mCamQuat
void SetCameraParameter(std::string yamlfile)
std::vector< ArImuData > mImuData
aruco::CameraParameters GetCameraParameter()
aruco::CameraParameters camParam
Vector3 mCamOffset