Program Listing for File cameraparameters.h

Return to documentation for file (/tmp/ws/src/aruco_ros/aruco/include/aruco/cameraparameters.h)

#ifndef _Aruco_CameraParameters_H
#define _Aruco_CameraParameters_H

#include "aruco_export.h"
#include <opencv2/core/core.hpp>
#include <string>
#include <stdexcept>

namespace aruco
{
class ARUCO_EXPORT CameraParameters
{
public:
  // 3x3 matrix (fx 0 cx, 0 fy cy, 0 0 1)
  cv::Mat CameraMatrix;
  //  distortion matrix
  cv::Mat Distorsion;
  // size of the image
  cv::Size CamSize;

  // 3x1 matrix (Tx, Ty, Tz), usually 0 for non-stereo cameras or stereo left cameras
  cv::Mat ExtrinsicMatrix;

  CameraParameters();
  CameraParameters(cv::Mat cameraMatrix, cv::Mat distorsionCoeff, cv::Size size);
  void setParams(cv::Mat cameraMatrix, cv::Mat distorsionCoeff, cv::Size size);
  CameraParameters(const CameraParameters &CI);

  bool isValid() const
  {
    return CameraMatrix.rows != 0 && CameraMatrix.cols != 0 && Distorsion.rows != 0 &&
           Distorsion.cols != 0 && CamSize.width != -1 && CamSize.height != -1;
  }
  CameraParameters &operator=(const CameraParameters &CI);

  void saveToFile(std::string path, bool inXML = true);

  void readFromXMLFile(std::string filePath);

  void resize(cv::Size size);

  static cv::Point3f getCameraLocation(const cv::Mat &Rvec, const cv::Mat &Tvec);

  void glGetProjectionMatrix(cv::Size orgImgSize, cv::Size size, double proj_matrix[16],
                             double gnear, double gfar, bool invert = false);

  void OgreGetProjectionMatrix(cv::Size orgImgSize, cv::Size size, double proj_matrix[16],
                               double gnear, double gfar, bool invert = false);

  static cv::Mat getRTMatrix(const cv::Mat &R_, const cv::Mat &T_, int forceType);


  void clear();

  ARUCO_EXPORT friend std::ostream &operator<<(std::ostream &str, const CameraParameters &cp);
  ARUCO_EXPORT friend std::istream &operator>>(std::istream &str, CameraParameters &cp);

private:
  // GL routines

  static void argConvGLcpara2(double cparam[3][4], int width, int height, double gnear,
                              double gfar, double m[16], bool invert);
  static int arParamDecompMat(double source[3][4], double cpara[3][4], double trans[3][4]);
  static double norm(double a, double b, double c);
  static double dot(double a1, double a2, double a3, double b1, double b2, double b3);
};
}  // namespace aruco
#endif