PMVSCamera.cpp
Go to the documentation of this file.
00001 
00024 #include <vector>
00025 #include <opencv/cv.h>
00026 #include <string>
00027 #include <sstream>
00028 #include <fstream>
00029 #include <iomanip>
00030 
00031 #include "PMVSCamera.h"
00032 #include "DUtils.h"
00033 
00034 using namespace std;
00035 using namespace DVision::PMVS;
00036 
00037 // ---------------------------------------------------------------------------
00038 
00039 void CameraFile::readFile(const std::string &filename, Camera &cameras)
00040 {
00041   fstream f(filename.c_str(), ios::in);
00042   
00043   string s;
00044   getline(f, s); // "CONTOUR"
00045   
00046   cv::Mat& P = cameras.P;
00047   P.create(3, 4, CV_64F);
00048   
00049   f >> P.at<double>(0,0) >> P.at<double>(0,1) >> P.at<double>(0,2) 
00050     >> P.at<double>(0,3)
00051     >> P.at<double>(1,0) >> P.at<double>(1,1) >> P.at<double>(1,2) 
00052     >> P.at<double>(1,3)
00053     >> P.at<double>(2,0) >> P.at<double>(2,1) >> P.at<double>(2,2) 
00054     >> P.at<double>(2,3);
00055 
00056   f.close();
00057 }
00058 
00059 // ---------------------------------------------------------------------------
00060 
00061 void CameraFile::readFile(const std::string &filedir, 
00062   std::vector<Camera> &cameras)
00063 {
00064   vector<string> files =
00065     DUtils::FileFunctions::Dir(filedir.c_str(), ".txt", true);
00066   
00067   cameras.resize(files.size());
00068   
00069   for(unsigned int i = 0; i < files.size(); ++i)
00070   {
00071     CameraFile::readFile(files[i], cameras[i]);
00072   }
00073 }
00074 
00075 // ---------------------------------------------------------------------------
00076 
00077 void CameraFile::saveFile(const std::string &filename, const Camera &cameras)
00078 {
00079   fstream f(filename.c_str(), ios::out);
00080   
00081   f << "CONTOUR" << endl;
00082   f.setf(ios::fixed, ios::floatfield);
00083   f.precision(6);
00084 
00085   const cv::Mat& P = cameras.P;
00086   
00087   f << P.at<double>(0,0) << " " << P.at<double>(0,1) << " "
00088     << P.at<double>(0,2) << " " << P.at<double>(0,3) << endl
00089     << P.at<double>(1,0) << " " << P.at<double>(1,1) << " "
00090     << P.at<double>(1,2) << " " << P.at<double>(1,3) << endl
00091     << P.at<double>(2,0) << " " << P.at<double>(2,1) << " "
00092     << P.at<double>(2,2) << " " << P.at<double>(2,3) << endl;
00093 
00094   f.close();
00095 }
00096 
00097 // ---------------------------------------------------------------------------
00098 
00099 void CameraFile::saveFile(const std::string &filedir, 
00100   const std::vector<Camera> &cameras,
00101   const std::string& format)
00102 { 
00103   char filename[1024];
00104 
00105   for(unsigned int i = 0; i < cameras.size(); ++i)
00106   {
00107     sprintf(filename, format.c_str(), i);    
00108     CameraFile::saveFile(filedir + "/" + filename, cameras[i]);
00109   }
00110 }
00111 
00112 // ---------------------------------------------------------------------------
00113 
00114 


re_vision
Author(s): Dorian Galvez-Lopez
autogenerated on Sun Jan 5 2014 11:32:08