25 #ifndef _IO_UTILS__HH_
26 #define _IO_UTILS__HH_
28 #include <bias_config.h>
29 #include <Utils/Param.hh>
30 #include <Base/Image/ImageIO.hh>
31 #include <Base/Image/MetaData.hh>
32 #include <Image/Camera.hh>
33 #include <Geometry/Projection.hh>
55 const bool verbose =
false) {
56 std::vector<std::string> imageNameList;
58 BIASERR(
"could not read list file");
62 unsigned int num = imageNameList.size();
64 for(
unsigned int i=0; i<num; i++) {
65 if(verbose) std::cout<<
"loading "<<imageNameList[i]<<
"... "<<std::flush;
67 if(verbose) std::cout<<
"failed!\n";
71 if(verbose) std::cout<<
"ok\n";
80 std::vector<ProjectionParametersPerspective*>& ppp,
81 const bool verbose =
false) {
82 std::vector<std::string> imageNameList;
84 BIASERR(
"could not read list file");
88 unsigned int num = imageNameList.size();
90 ppp.resize(num, NULL);
91 for(
unsigned int i=0; i<num; i++) {
92 if(verbose) std::cout<<
"loading "<<imageNameList[i]<<
"... "<<std::flush;
94 if(verbose) std::cout<<
"failed!\n";
96 for(
unsigned int j=0; j<i; j++) {
102 if(verbose) std::cout<<
"ok\n";
109 std::vector<ImageBase>& imgs,
110 std::vector<ProjectionParametersPerspective*>& ppp,
111 const bool verbose =
false) {
112 std::vector<std::string> imageNameList;
114 BIASERR(
"could not read list file");
118 unsigned int num = (
unsigned int)imageNameList.size();
120 ppp.resize(num, NULL);
121 for(
unsigned int i=0; i<num; i++) {
122 if(verbose) std::cout<<
"loading "<<imageNameList[i]<<
"... "<<std::flush;
124 if(verbose) std::cout<<
"failed!\n";
126 for(
unsigned int j=0; j<i; j++) {
132 if(verbose) std::cout<<
"ok\n";
138 std::vector<ImageBase>& imgs,
139 std::vector<ProjectionParametersPerspective>& ppp,
140 const bool verbose =
false) {
141 std::vector<ProjectionParametersPerspective*> pppPntr;
142 if(!LoadImageList(listFileName, imgs, pppPntr, verbose))
return false;
145 ppp.reserve(pppPntr.size());
146 for(
unsigned int i=0; i<pppPntr.size(); i++)
147 ppp.push_back(*(pppPntr[i]));
156 static bool ReadIn2DPointList(
const std::string& fileName,
159 static bool ReadIn2DPointList(
const std::string& fileName,
160 std::vector<unsigned int>& xPos,
161 std::vector<unsigned int>& yPos);
165 std::vector<unsigned int>& xPos,
166 std::vector<unsigned int>& yPos,
167 std::vector<T>& datum) {
169 BIASASSERT(xPos.size() == yPos.size());
170 BIASASSERT(xPos.size() == datum.size());
172 std::ofstream ofs(fileName.c_str());
178 for(
unsigned int i=0; i<xPos.size(); i++) {
184 ofs << xPos[i] <<
"\t";
185 ofs << yPos[i]<<
"\t";
186 ofs << datum[i]<<
"\n";
211 std::ifstream ifs(fileName.c_str());
224 pointList.push_back(pt);
247 std::ifstream ifs(fileName.c_str());
261 pointList.push_back(pt);
272 static std::string ExtendOutName(
const std::string& outname,
const std::string& suffix,
273 const std::string& extension);
278 static std::string ExtendOutName(
const std::string& outname,
const std::string& extension);
284 static bool ExtractSubPaths(
const std::string& environmentVariable,
285 std::vector<std::string>& subPaths);
293 static bool FindFile(
const std::string& searchPaths,
294 const std::string& baseFileName,
295 std::string& fullFileName);
299 static bool FindFileEnv(
const std::string& environmentVariable,
300 const std::string& baseFileName,
301 std::string& fullFileName);
305 static bool FindShaderFile(
const std::string& shaderFileName, std::string& res);
307 static bool LoadImage(
308 const std::string& fileName,
311 unsigned int& height,
312 unsigned int& channels);
314 template<
class dataType>
319 BIASERR(
"could not load camera: "<<*fileName);
325 template<
class dataType>
330 BIASERR(
"could not load camera: "<<fileName);
337 template<
class dataType>
342 if(!LoadCamera<dataType>(fileName, cam))
346 BIASERR(
"could not parse metadata from file: "<<*fileName);
353 template<
class dataType>
358 if(!LoadCamera<dataType>(fileName, cam))
362 BIASERR(
"could not parse metadata from file: "<<fileName);
369 template<
class dataType>
374 unsigned int& height,
375 unsigned int& channels)
377 std::string fileNameBak = fileName;
378 if(!LoadCamera<dataType>(&fileNameBak, cam, proj))
388 template<
class dataType>
393 BIASERR(
"could not save camera: "<<fileName);
399 template<
class dataType>
406 if(!SaveCamera<dataType>(fileName, cam))
413 static bool ParseCommandLineEvalHelp(
Param& params,
414 int argc,
char* argv[]);
417 static bool ParseCommandLineEvalHelp(
Param& params,
418 int argc,
char* argv[],
422 template<
class ptType,
class inPtType>
423 static bool CheckType(inPtType* checked, ptType*& result) {
424 result =
dynamic_cast<ptType*
>(checked);
431 template<
class ptType,
class inPtType>
433 result =
dynamic_cast<ptType*
>(checked);
444 if(tempProj.
Load(*fileName)!=0) {
445 BIASERR(
"could not load projection from "<<fileName);
449 BIASERR(
"projection file is not of type projection parameters perspective!");
455 static void PrintWithLineNumbers(
const std::string& text, std::ostream& out = std::cout);
459 long int totalmemory = 0;
460 std::ifstream memfile(
"/proc/self/statm");
461 memfile >> totalmemory;
468 #ifdef BIAS_HAVE_XML2
475 static bool GetProjectionParametersPerspective(
ImageBase& imgBase,
482 BIASERR(
"could not load the image file! : "<<*fileName);
486 if(!GetProjection(cam, proj)) {
487 BIASERR(
"could not retrive projection.");
499 if(!LoadCamera(fileName, cam, tempProj))
return false;
501 BIASERR(
"meta data do not contain projection parameters perspective!");
507 template<
class dataType>
512 unsigned int& height,
513 unsigned int& channels)
515 std::string fileNameBak = fileName;
516 if(!LoadCamera(&fileNameBak, cam, proj))
531 if(!LoadCamera(fileName, cam, tempProj))
return false;
533 BIASERR(
"meta data do not contain projection parameters perspective depth!");
539 template<
class dataType>
544 unsigned int& height,
545 unsigned int& channels)
547 std::string fileNameBak = fileName;
548 if(!LoadCamera(&fileNameBak, cam, proj))
561 #endif //BIAS_HAVE_XML2
567 void operator++(
int);
574 clear_(cl), incrementThreshold_(1), incrementPos_(0) {};
575 void Init(
const int steps);
577 void Init(
const int steps,
const int maxLength);
578 void operator++(
int);
582 unsigned int incrementThreshold_;
583 unsigned int incrementPos_;
589 static bool SaveForPlot(
const std::string& filename,
const std::vector<double>& x_vector,
const std::vector<double>& y_vector);
static bool LoadCamera(const std::string *fileName, BIAS::ImageBase &cam, BIAS::ProjectionParametersPerspective *&ppp)
virtual int Load(const std::string &filename)
convenience wrapper which tries to read different formats
additional depth calibration parameters for a perspective depth camera to be used for ToF-(PMD) camer...
static int GetApplicationMemory()
extends the Image by MetaData support (e.g.
camera parameters which define the mapping between rays in the camera coordinate system and pixels in...
static bool LoadCamera(const std::string &fileName, BIAS::Camera< dataType > &cam, BIAS::ProjectionParametersPerspective *&proj, unsigned int &width, unsigned int &height, unsigned int &channels)
static bool LoadCamera(std::string *fileName, BIAS::Camera< dataType > &cam)
virtual ProjectionParametersBase * Clone() const =0
Covariant virtual copy constructor used in BIAS::Projection.
static bool LoadCamera(const std::string &fileName, BIAS::Camera< dataType > &cam, BIAS::Projection &proj)
static bool LoadImageList(const std::string &listFileName, std::vector< Image< type > > &imgs, std::vector< ProjectionParametersPerspective * > &ppp, const bool verbose=false)
unsigned int GetWidth() const
static bool ReadIn2DPointList(const std::string &fileName, std::vector< BIAS::Vector2< T > > &pointList)
Reads a list of 2D points from a text file and appends them to the given vector.
const ProjectionParametersBase * GetParameters(unsigned int cam=0) const
const parameter access function
static bool ReadIn3DPointList(const std::string &fileName, std::vector< BIAS::Vector3< T > > &pointList)
Reads a list of 3D points from a text file and appends them to the given vector.
This class hides the underlying projection model, like projection matrix, spherical camera...
static bool LoadCamera(std::string *fileName, BIAS::Camera< dataType > &cam, BIAS::Projection &proj)
Class grouping together some IO code often used in (small) application, like loading images...
static bool Write2DPointWithDatumList(const std::string &fileName, std::vector< unsigned int > &xPos, std::vector< unsigned int > &yPos, std::vector< T > &datum)
static bool LoadImageList(const std::string &listFileName, std::vector< Image< type > > &imgs, const bool verbose=false)
Takes in the name of a text file, that contains an image file-name per line, tries to load these imag...
unsigned int GetChannelCount() const
returns the number of Color channels, e.g.
int SetProj(const Projection &Proj)
unsigned int GetHeight() const
static bool LoadCamera(const std::string &fileName, BIAS::Camera< dataType > &cam)
static int ParseListFile(const std::string &ListFileName, std::vector< std::string > &LinesInFile)
Extracts lines from passed file.
The image template class for specific storage types.
static int Save(const std::string &filename, const ImageBase &img, const enum TFileFormat FileFormat=FF_auto, const bool sync=BIAS_DEFAULT_SYNC, const int c_jpeg_quality=BIAS_DEFAULT_IMAGE_QUALITY, const bool forceNewID=BIAS_DEFAULT_FORCENEWID, const bool &writeMetaData=true)
Export image as file using extrnal libs.
static bool CheckType(inPtType *checked, ptType *&result)
class Vector3 contains a Vector of fixed dim.
int UpdateMetaData()
copy P_ and co.
This class Param provides generic support for parameters.
static bool SaveCamera(const std::string &fileName, const BIAS::Camera< dataType > &cam)
static bool LoadCamera(const std::string &fileName, BIAS::Camera< dataType > &cam, BIAS::Projection &proj, unsigned int &width, unsigned int &height, unsigned int &channels)
static int Load(const std::string &FileName, ImageBase &img)
first tries a call to Read MIP image and if that fails, tries to Import Image with all other availabl...
static bool LoadCamera(const std::string &fileName, BIAS::Camera< dataType > &cam, BIAS::ProjectionParametersPerspectiveDepth *&proj, unsigned int &width, unsigned int &height, unsigned int &channels)
ProgressBar(bool cl=false)
static bool LoadImageList(const std::string &listFileName, std::vector< ImageBase > &imgs, std::vector< ProjectionParametersPerspective > &ppp, const bool verbose=false)
static bool CheckTypeDelete(inPtType *checked, ptType *&result)
const BIAS::Projection & GetProj() const
This is the base class for images in BIAS.
unsigned int indicatorState
int ParseMetaData(bool bUse2x64bitTS=true)
After ImageIO::Load() operated on AppData_, this method fills P_, Timestamp, DC_*, ...
static bool LoadCamera(const std::string *fileName, BIAS::ImageBase &cam, BIAS::ProjectionParametersPerspectiveDepth *&ppp)
static bool LoadImageList(const std::string &listFileName, std::vector< ImageBase > &imgs, std::vector< ProjectionParametersPerspective * > &ppp, const bool verbose=false)
static bool LoadParameters(const std::string *fileName, BIAS::ProjectionParametersPerspective *&ppp)
static bool LoadCamera(const std::string *fileName, BIAS::ImageBase &cam, BIAS::Projection &proj)
static bool SaveCamera(const std::string &fileName, BIAS::Camera< dataType > &cam, const BIAS::Projection &proj)