Extrinsics.cpp
Go to the documentation of this file.
00001 /*
00002  * Extrinsics.cpp
00003  *
00004  *  Created on: Oct 20, 2010
00005  *      Author: erublee
00006  */
00007 
00008 #include "pano_core/Extrinsics.h"
00009 #include <opencv2/highgui/highgui.hpp>
00010 
00011 using namespace cv;
00012 using namespace std;
00013 namespace pano
00014 {
00015 Extrinsics::Extrinsics() :
00016   mats_(N_STD_MATS), vals_(N_STD_VALS), flags_(N_STD_FLAGS)
00017 {
00018 
00019 }
00020 
00021 Extrinsics::~Extrinsics()
00022 {
00023 
00024 }
00025 Extrinsics::Extrinsics(const std::vector<Mat>& mats, const std::vector<double>& vals, const std::vector<int>& flags) :
00026   mats_(mats), vals_(vals), flags_(flags)
00027 {
00028 
00029 }
00030 Extrinsics::Extrinsics(const cv::Mat& R, const cv::Mat& T, double latitude, double longitude, double gps_accuracy, double confidence, double gps_time,
00031                        bool estimated) :
00032   mats_(N_STD_MATS), vals_(N_STD_VALS), flags_(N_STD_FLAGS)
00033 {
00034   mat(Extrinsics::R) = R;
00035   mat(Extrinsics::T) = T;
00036   val(LATITUDE) = latitude;
00037   val(LONGITUDE) = longitude;
00038   val(GPS_ACCURACY) = gps_accuracy;
00039   val(CONFIDENCE) = confidence;
00040   val(GPS_TIME) = gps_time;
00041   flag(ESTIMATED) = estimated;
00042 }
00043 Extrinsics::Extrinsics(const cv::Mat& R, double confidence) :
00044   mats_(N_STD_MATS), vals_(N_STD_VALS), flags_(N_STD_FLAGS)
00045 {
00046   mat(Extrinsics::R) = R;
00047 
00048   mat(Extrinsics::T) = Mat();
00049   val(LATITUDE) = 0;
00050   val(LONGITUDE) = 0;
00051   val(GPS_ACCURACY) = 0;
00052   val(CONFIDENCE) = confidence;
00053   flag(ESTIMATED) = false;
00054 
00055 }
00056 Extrinsics::Extrinsics(const Extrinsics& rhs) :
00057   vals_(rhs.vals_), flags_(rhs.flags_)
00058 {
00059   copyData(rhs);
00060 }
00061 Extrinsics& Extrinsics::operator=(const Extrinsics& rhs)
00062 {
00063 
00064   if (&rhs != this)
00065   {
00066     vals_ = rhs.vals_;
00067     flags_ = rhs.flags_;
00068     copyData(rhs);
00069   }
00070   return *this;
00071 }
00072 void Extrinsics::copyData(const Extrinsics& rhs)
00073 {
00074   mats_.resize(rhs.mats_.size());
00075   for (size_t i = 0; i < mats_.size(); ++i)
00076   {
00077     if (!rhs.mats_[i].empty())
00078     {
00079       rhs.mats_[i].copyTo(mats_[i]);
00080     }
00081     else
00082       mats_[i] = Mat();
00083   }
00084 }
00085 void Extrinsics::serialize(cv::FileStorage& fs) const
00086 {
00087   fs << "{";
00088   cvWriteComment(*fs, "Extrinsics class", 0);
00089   fs << "mats" << "[";
00090   for (size_t i = 0; i < mats_.size(); ++i)
00091   {
00092     if (mats_[i].empty())
00093     {
00094       fs << Mat::zeros(3, 1, CV_32FC1);
00095     }
00096     else
00097       fs << mats_[i];
00098   }
00099   fs << "]";
00100 
00101   fs << "vals" << "[";
00102   for (size_t i = 0; i < vals_.size(); ++i)
00103   {
00104     fs << vals_[i];
00105   }
00106   fs << "]";
00107 
00108   fs << "flags" << "[";
00109   for (size_t i = 0; i < flags_.size(); ++i)
00110   {
00111     fs << (int)flags_[i];
00112   }
00113   fs << "]";
00114 
00115   fs << "}";
00116 }
00117 void Extrinsics::deserialize(const cv::FileNode& fn)
00118 {
00119 
00120   FileNode mats = fn["mats"];
00121   CV_Assert(mats.type() == FileNode::SEQ);
00122   mats_.resize(mats.size());
00123   for (size_t i = 0; i < mats.size(); i++)
00124   {
00125     try
00126     {
00127       cv::read(mats[i], mats_[i], Mat());
00128     }
00129     catch (Exception exc)
00130     {
00131       if (exc.code == -201)
00132       {
00133         mats_[i] = Mat();
00134       }
00135       else
00136         throw exc;
00137     }
00138   }
00139 
00140   FileNode vals = fn["vals"];
00141   CV_Assert(vals.type() == FileNode::SEQ);
00142   vals_.resize(vals.size());
00143   for (size_t i = 0; i < vals.size(); i++)
00144   {
00145     vals_[i] = (double)vals[i];
00146   }
00147 
00148   FileNode flags = fn["flags"];
00149   CV_Assert(flags.type() == FileNode::SEQ);
00150   flags_.resize(flags.size());
00151   for (size_t i = 0; i < flags.size(); i++)
00152   {
00153     flags_[i] = (int)flags[i];
00154   }
00155 }
00156 
00157 }


pano_core
Author(s): Ethan Rublee
autogenerated on Mon Oct 6 2014 08:04:38