My Project
Public Member Functions | Public Attributes | Protected Attributes | List of all members
Camera Class Reference

Simple Camera class for calculating distortions, orientation or projections with pre-calibrated camera. More...

#include <Camera.h>

Inheritance diagram for Camera:
CameraEC

Public Member Functions

std::string SerializeId ()
 One of the two methods to make this class serializable by Serialization class.
 
bool Serialize (Serialization *ser)
 One of the two methods to make this class serializable by Serialization class. More...
 
 Camera ()
 Constructor.
 
double GetFovX ()
 Get x-direction FOV in radians.
 
double GetFovY ()
 Get y-direction FOV in radians.
 
void SetSimpleCalib (int _x_res, int _y_res, double f_fac=1.)
 
bool SetCalib (const char *calibfile, int _x_res, int _y_res, FILE_FORMAT format=FILE_FORMAT_DEFAULT)
 Set the calibration file and the current resolution for which the calibration is adjusted to. More...
 
bool SaveCalib (const char *calibfile, FILE_FORMAT format=FILE_FORMAT_DEFAULT)
 Save the current calibration information to a file. More...
 
void Calibrate (ProjPoints &pp)
 Calibrate using the collected ProjPoints.
 
void SetRes (int _x_res, int _y_res)
 If we have no calibration file we can still adjust the default calibration to current resolution

 
void GetOpenglProjectionMatrix (double proj_matrix[16], const int width, const int height, const float far_clip=1000.0f, const float near_clip=0.1f)
 Get OpenGL matrix Generates the OpenGL projection matrix based on OpenCV intrinsic camera matrix K. More...
 
void SetOpenglProjectionMatrix (double proj_matrix[16], const int width, const int height)
 Invert operation for GetOpenglProjectionMatrix.
 
void Undistort (std::vector< PointDouble > &points)
 Unapplys the lens distortion for points on image plane.
 
void Undistort (PointDouble &point)
 Unapplys the lens distortion for one point on an image plane.
 
void Undistort (cv::Point2f &point)
 Unapplys the lens distortion for one point on an image plane.
 
void Distort (cv::Point2f &point)
 Applys the lens distortion for one point on an image plane.
 
void Distort (std::vector< PointDouble > &points)
 Applys the lens distortion for points on image plane.
 
void Distort (PointDouble &point)
 Applys the lens distortion for points on image plane.
 
void CalcExteriorOrientation (const std::vector< cv::Point3d > &pw, const std::vector< PointDouble > &pi, cv::Mat &rodriques, cv::Mat &tra) const
 Calculate exterior orientation.
 
void CalcExteriorOrientation (const std::vector< PointDouble > &pw, const std::vector< PointDouble > &pi, cv::Mat &rodriques, cv::Mat &tra) const
 Calculate exterior orientation.
 
void CalcExteriorOrientation (const std::vector< PointDouble > &pw, const std::vector< PointDouble > &pi, Pose *pose) const
 Update existing pose (in rodriques&tra) based on new observations. Use (CV_32FC3 and CV_32FC2) for matrices.
 
void CalcExteriorOrientation (std::vector< cv::Point3d > &pw, std::vector< cv::Point2d > &pi, Pose *pose)
 
bool CalcExteriorOrientation (const cv::Mat &object_points, cv::Mat &image_points, Pose *pose)
 
bool CalcExteriorOrientation (const cv::Mat &object_points, cv::Mat &image_points, cv::Mat &rodriques, cv::Mat &tra)
 
void ProjectPoint (const cv::Point3d &pw, const Pose *pose, cv::Point2d &pi) const
 Project one point.
 
void ProjectPoint (const cv::Point3f &pw, const Pose *pose, cv::Point2f &pi) const
 Project one point.
 
void ProjectPoints (std::vector< cv::Point3d > &pw, Pose *pose, std::vector< cv::Point2d > &pi) const
 Project points.
 
void ProjectPoints (const cv::Mat &object_points, const cv::Mat &rotation_vector, const cv::Mat &translation_vector, cv::Mat &image_points) const
 Project points.
 
void ProjectPoints (const cv::Mat &object_points, double gl[16], cv::Mat &image_points) const
 Project points.
 
void ProjectPoints (const cv::Mat &object_points, const Pose *pose, cv::Mat &image_points) const
 Project points

 

Public Attributes

cv::Mat calib_K
 
double calib_K_data [3][3]
 
cv::Mat calib_D
 
double calib_D_data [4]
 

Protected Attributes

int calib_x_res
 
int calib_y_res
 
int x_res
 
int y_res
 

Detailed Description

Simple Camera class for calculating distortions, orientation or projections with pre-calibrated camera.

Definition at line 81 of file Camera.h.

Member Function Documentation

◆ GetOpenglProjectionMatrix()

void GetOpenglProjectionMatrix ( double  proj_matrix[16],
const int  width,
const int  height,
const float  far_clip = 1000.0f,
const float  near_clip = 0.1f 
)

Get OpenGL matrix Generates the OpenGL projection matrix based on OpenCV intrinsic camera matrix K.

2*K[0][0]/width 2*K[0][1]/width -(2*K[0][2]/width+1) 0
0 2*K[1][1]/height 2*K[1][2]/height-1 0
0 0 -(f+n)/(f-n) -2*f*n/(f-n)
0 0 -1 0

Note, that the sign of the element [2][0] is changed. It should be

2*K[0][2]/width+1

The sign change is due to the fact that with OpenCV and OpenGL projection matrices both y and z should be mirrored. With other matrix elements the sign changes eliminate each other, but with principal point in x-direction we need to make the change by hand.

◆ SaveCalib()

bool SaveCalib ( const char *  calibfile,
FILE_FORMAT  format = FILE_FORMAT_DEFAULT 
)

Save the current calibration information to a file.

Parameters
calibfileFile to save.
formatFILE_FORMAT_OPENCV (default) or FILE_FORMAT_XML (see doc/Camera.xsd).

◆ Serialize()

bool Serialize ( Serialization ser)
inline

One of the two methods to make this class serializable by Serialization class.

You can serialize the Camera class using filename or any std::iostream as follows:

cam.SetCalib("calib.xml", 320, 240);
Serialization sero("calib1.xml");
sero<<cam;
Simple Camera class for calculating distortions, orientation or projections with pre-calibrated camer...
Definition: Camera.h:82
bool SetCalib(const char *calibfile, int _x_res, int _y_res, FILE_FORMAT format=FILE_FORMAT_DEFAULT)
Set the calibration file and the current resolution for which the calibration is adjusted to.
Serialization seri("calib1.xml");
seri>>cam;
cam.SetRes(320, 240);
std::stringstream ss;
Serialization sero(ss);
sero<<cam;
std::cout<<ss.str()<<std::endl;
// ...
Serialization seri(ss);
seri>>cam;

Definition at line 135 of file Camera.h.

◆ SetCalib()

bool SetCalib ( const char *  calibfile,
int  _x_res,
int  _y_res,
FILE_FORMAT  format = FILE_FORMAT_DEFAULT 
)

Set the calibration file and the current resolution for which the calibration is adjusted to.

Parameters
calibfileFile to load.
_x_resWidth of images captured from the real camera.
_y_resHeight of images captured from the real camera.
formatFILE_FORMAT_OPENCV (default) or FILE_FORMAT_XML (see doc/Camera.xsd).

The documentation for this class was generated from the following file: