Camera.h
Go to the documentation of this file.
1 /*
2  * This file is part of ALVAR, A Library for Virtual and Augmented Reality.
3  *
4  * Copyright 2007-2012 VTT Technical Research Centre of Finland
5  *
6  * Contact: VTT Augmented Reality Team <alvar.info@vtt.fi>
7  * <http://www.vtt.fi/multimedia/alvar.html>
8  *
9  * ALVAR is free software; you can redistribute it and/or modify it under the
10  * terms of the GNU Lesser General Public License as published by the Free
11  * Software Foundation; either version 2.1 of the License, or (at your option)
12  * any later version.
13  *
14  * This library is distributed in the hope that it will be useful, but WITHOUT
15  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
16  * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
17  * for more details.
18  *
19  * You should have received a copy of the GNU Lesser General Public License
20  * along with ALVAR; if not, see
21  * <http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html>.
22  */
23 
24 #ifndef CAMERA_H
25 #define CAMERA_H
26 
34 #include "Alvar.h"
35 #include "Pose.h"
36 #include "Util.h"
37 #include "FileFormat.h"
38 #include <vector>
39 
40 #include <ros/ros.h>
41 #include <ros/package.h>
42 #include <ros/console.h>
43 #include <geometry_msgs/TransformStamped.h>
45 #include <sensor_msgs/CameraInfo.h>
46 #include <visualization_msgs/Marker.h>
48 
49 namespace alvar {
50 
53  int width;
54  int height;
55 
57  std::vector<CvPoint3D64f> object_points;
64  std::vector<CvPoint2D64f> image_points;
66  std::vector<int> point_counts;
67 
69  void Reset();
70 
72  bool AddPointsUsingChessboard(IplImage *image, double etalon_square_size, int etalon_rows, int etalon_columns, bool visualize);
73 
75  bool AddPointsUsingMarkers(std::vector<PointDouble> &marker_corners, std::vector<PointDouble> &marker_corners_img, IplImage* image);
76 };
77 
78 
83 
84 public:
85 
86  CvMat calib_K; double calib_K_data[3][3];
87  CvMat calib_D; double calib_D_data[4];
90  int x_res;
91  int y_res;
93 
94 protected:
95  std::string cameraInfoTopic_;
96  sensor_msgs::CameraInfo cam_info_;
97  void camInfoCallback (const sensor_msgs::CameraInfoConstPtr &);
100 
101 private:
102  bool LoadCalibXML(const char *calibfile);
103  bool LoadCalibOpenCV(const char *calibfile);
104  bool SaveCalibXML(const char *calibfile);
105  bool SaveCalibOpenCV(const char *calibfile);
106 
107 public:
109  std::string SerializeId() { return "camera"; };
137  if (!ser->Serialize(calib_x_res, "width")) return false;
138  if (!ser->Serialize(calib_y_res, "height")) return false;
139  if (!ser->Serialize(calib_K, "intrinsic_matrix")) return false;
140  if (!ser->Serialize(calib_D, "distortion")) return false;
141  return true;
142  }
143 
145  Camera();
146  Camera(ros::NodeHandle & n, std::string cam_info_topic);
147 
149  void SetCameraInfo(const sensor_msgs::CameraInfo& camInfo);
150 
152  double GetFovX() {
153  return (2.0f * atan2(double(x_res) / 2.0f, (double)calib_K_data[0][0]));
154  }
156  double GetFovY() {
157  return (2.0f * atan2(double(y_res) / 2.0f, (double)calib_K_data[1][1]));
158  }
159 
160  void SetSimpleCalib(int _x_res, int _y_res, double f_fac=1.);
161 
168  bool SetCalib(const char *calibfile, int _x_res, int _y_res,
170 
175  bool SaveCalib(const char *calibfile, FILE_FORMAT format = FILE_FORMAT_DEFAULT);
176 
178  void Calibrate(ProjPoints &pp);
179 
181  void SetRes(int _x_res, int _y_res);
182 
202  void GetOpenglProjectionMatrix(double proj_matrix[16], const int width, const int height, const float far_clip = 1000.0f, const float near_clip = 0.1f);
203 
205  void SetOpenglProjectionMatrix(double proj_matrix[16], const int width, const int height);
206 
208  void Undistort(std::vector<PointDouble >& points);
209 
211  void Undistort(PointDouble &point);
212 
214  void Undistort(CvPoint2D32f& point);
215 
217  void Distort(CvPoint2D32f& point);
218 
220  void Distort(std::vector<PointDouble>& points);
221 
223  void Distort(PointDouble &point);
224 
226  void CalcExteriorOrientation(std::vector<CvPoint3D64f>& pw, std::vector<CvPoint2D64f>& pi, Pose *pose);
227 
230  void CalcExteriorOrientation(std::vector<CvPoint3D64f>& pw, std::vector<PointDouble >& pi,
231  CvMat *rodriques, CvMat *tra);
232 
235  void CalcExteriorOrientation(std::vector<PointDouble >& pw, std::vector<PointDouble >& pi,
236  CvMat *rodriques, CvMat *tra);
237 
240  void CalcExteriorOrientation(std::vector<PointDouble>& pw, std::vector<PointDouble >& pi, Pose *pose);
241 
243  bool CalcExteriorOrientation(const CvMat* object_points, CvMat* image_points, Pose *pose);
244 
246  bool CalcExteriorOrientation(const CvMat* object_points, CvMat* image_points, CvMat *rodriques, CvMat *tra);
247 
249  void ProjectPoint(const CvPoint3D64f pw, const Pose *pose, CvPoint2D64f &pi) const;
250 
252  void ProjectPoint(const CvPoint3D32f pw, const Pose *pose, CvPoint2D32f &pi) const;
253 
255  void ProjectPoints(std::vector<CvPoint3D64f>& pw, Pose *pose, std::vector<CvPoint2D64f>& pi) const;
256 
259  void ProjectPoints(const CvMat* object_points, const CvMat* rotation_vector,
260  const CvMat* translation_vector, CvMat* image_points) const;
261 
264  void ProjectPoints(const CvMat* object_points, double gl[16], CvMat* image_points) const;
265 
267  void ProjectPoints(const CvMat* object_points, const Pose* pose, CvMat* image_points) const;
268 };
269 
274  double H_data[3][3];
275  CvMat H;
276 
278  Homography();
279 
281  void Find(const std::vector<PointDouble>& pw, const std::vector<PointDouble>& pi);
282 
284  void ProjectPoints(const std::vector<PointDouble>& from, std::vector<PointDouble>& to);
285 };
286 
287 } // namespace alvar
288 
289 #endif
Main ALVAR namespace.
Definition: Alvar.h:174
ros::Subscriber sub_
Definition: Camera.h:98
Default file format.
Definition: FileFormat.h:45
const int etalon_columns
std::string SerializeId()
One of the two methods to make this class serializable by Serialization class.
Definition: Camera.h:109
double GetFovX()
Get x-direction FOV in radians.
Definition: Camera.h:152
f
std::string cam_info_topic
int x_res
Definition: Camera.h:90
int visualize
std::vector< int > point_counts
Vector indicating how many points are detected for each frame.
Definition: Camera.h:66
Simple Homography class for finding and projecting points between two planes.
Definition: Camera.h:273
bool Serialize(Serialization *ser)
One of the two methods to make this class serializable by Serialization class.
Definition: Camera.h:136
unsigned char * image
Definition: GlutViewer.cpp:155
int height
Definition: GlutViewer.cpp:160
Simple Camera class for calculating distortions, orientation or projections with pre-calibrated camer...
Definition: Camera.h:82
int calib_x_res
Definition: Camera.h:88
ros::NodeHandle n_
Definition: Camera.h:99
bool Serialize(int &data, const std::string &name)
Method for serializing &#39;int&#39; data element. Used from your serializable class.
Definition: Util.cpp:453
int calib_y_res
Definition: Camera.h:89
std::vector< CvPoint3D64f > object_points
3D object points corresponding with the detected 2D image points.
Definition: Camera.h:57
FILE_FORMAT
Definition: FileFormat.h:39
sensor_msgs::CameraInfo cam_info_
Definition: Camera.h:96
Simple structure for collecting 2D and 3D points e.g. for camera calibration.
Definition: Camera.h:52
Pose representation derived from the Rotation class
Definition: Pose.h:50
int width
Definition: GlutViewer.cpp:159
const int etalon_rows
This file defines various file formats.
double GetFovY()
Get y-direction FOV in radians.
Definition: Camera.h:156
This file implements generic utility functions and a serialization interface.
std::vector< CvPoint2D64f > image_points
Detected 2D object points If point_counts[0] == 10, then the first 10 points are detected in the firs...
Definition: Camera.h:64
#define ALVAR_EXPORT
Definition: Alvar.h:168
ALVAR_EXPORT Point< CvPoint2D64f > PointDouble
The default double point type.
Definition: Util.h:108
This file implements a pose.
Class for serializing class content to/from file or std::iostream.
Definition: Util.h:352
This file defines library export definitions, version numbers and build information.
int y_res
Definition: Camera.h:91
std::string cameraInfoTopic_
Definition: Camera.h:95
bool getCamInfo_
Definition: Camera.h:92


ar_track_alvar
Author(s): Scott Niekum
autogenerated on Mon Jun 10 2019 12:47:03