26 #include <Image/Camera.hh>
27 #include <Image/CameraParam.hh>
28 #include <Base/Image/ImageIO.hh>
29 #include <Base/Image/ImageAttributes.hh>
34 #include "Base/Common/getopt_W32.h"
39 #include <Utils/Param.hh>
52 cout <<
"Usage: biasextract [options] Image ..."<<endl
54 <<
"-a : extract ascii string"<<endl
55 <<
"-t : extract timestamp as [sec usec]"<<endl
56 <<
"-T : extract timestamp as [msec]"<<endl
57 <<
"-s : suppress current filename in output"<<endl
58 <<
"-P : extract P-Matrix"<<endl
59 <<
"-p : Decompose P-Matrix and extract axis-angle orientation"
61 <<
"-x file : extract pmatrix as xml data"<<endl
62 <<
"-K : extract internal parameter matrix"<<endl
63 <<
"-R : extract rotation matrix"<<endl
64 <<
"-r : extract axis-angle orientation"<<endl
65 <<
"-C : extract camera center position"<<endl
66 <<
"-A : extract viewing direction"<<endl
67 <<
"-V : extract 'down' vector"<<endl
68 <<
"-H : extract 'right' vector"<<endl
69 <<
"-e : compute K from EXIF data"<<endl
70 <<
"-c : compute CameraParam from KMatrix in header"<<endl
71 <<
"-E : compute CameraParam from EXIF data"<<endl
72 <<
"-u : extract UID"<<endl
73 <<
"-O : extract orientation"<<endl
74 <<
"-o file : write output to file"<<endl;
78 int main(
int argc,
char *argv[])
90 bool* GetASCIIString = params.
AddParamBool(
"GetASCIIString",
91 "extract ascii string",
93 additionalDataGroupID);
95 "extract timestamp as [sec usec]",
97 additionalDataGroupID);
99 "extract timestamp as [msec]",
101 additionalDataGroupID);
105 additionalDataGroupID);
106 params.
SetGroupName(additionalDataGroupID,
"extract additional data");
112 "Decompose P-Matrix",
115 bool* GetPandDecomposition =
117 "Decompose P-Matrix and "
118 "extract axis-angle orientation",
123 "extract axis-angle orientation",
126 bool* GetAxisAngle = params.
AddParamBool(
"GetAxisAngle",
127 "extract axis-angle orientation",
132 "extract orientation as yaw, pitch, roll",
138 "extract camera center position",
142 "extract internal parameter matrix",
146 bool* GetKFromEXIF = params.
AddParamBool(
"GetKFromEXIF",
147 "compute K from EXIF data",
150 bool* GetCameraParamFromEXIF =
152 "compute CameraParam from EXIF data",
155 bool* GetCameraParamFromK =
157 "compute CameraParam from KMatrix in header",
163 "extract viewing direction",
167 "extract 'right' vector",
171 "extract 'down' vector",
174 #ifdef BIAS_HAVE_XML2
177 "write out pmatrix as xml data"
183 string* GetProjection =
185 "extract projection and write into this file",
190 params.
SetGroupName(camParamGroupID,
"extract camera parameters");
195 bool* SuppressFilename =
197 "suppress current filename in output",
202 "write results into this file",
217 if(*GetTimeMsec) *GetTimeStamp =
true;
218 if(*GetPandDecomposition) {
222 *GetAxisAngle =
true;
226 bool GetPXML =
false;
227 #ifdef BIAS_HAVE_XML2
228 if(PXMLName->size()>0) GetPXML =
true;
295 cout <<
"==> To few arguments."<<endl;
301 if (Outfile->size()>0) {
302 ofs.open(Outfile->c_str());
304 perror(Outfile->c_str());
308 cout.rdbuf(ofs.rdbuf());
319 for (
int i=fup; i<argc;i++) {
322 ImageIO::Load(argv[i],tmp);
326 if(*GetASCIIString) {
333 if (Att.
Read(argv[i])!=BIAS_IMAGEATTRIBUTES_SUCCESS) {
334 cerr<<
"error reading exif tags ..."<<endl;
347 cerr<<
"Error, not enough EXIF data to get K:"<<KExif<<endl;
351 if (*GetCameraParamFromEXIF) {
352 #ifdef BIAS_HAVE_XML2
355 stringstream cpfilename;
356 cpfilename <<argv[i]<<
".cameraparam.xml";
359 cerr<<
"Error, not enough EXIF data to construct cameraparam"<<endl;
362 cerr<<
"Missing XML2 support led to missing class BIAS::CameraParam, "
363 <<
"cant extract EXIF."<<endl;
367 if (!(*SuppressFilename)) cout <<argv[i]<<
"\t"<<endl;
368 if (*GetUID) cout<<pic.
GetUID()<<
" ";
371 unsigned long long int sec,usec;
374 if (GetTimeMsec) cout<< (sec % 1000) * 1000 + (usec / 1000);
375 else cout<<sec<<
" "<<usec;
380 cout<<y<<
" "<<p<<
" "<<r;
382 if (*GetPMatrix || GetPXML) {
403 BIASERR(
"could not read R, assuming identity");
408 BIASERR(
"could not read C, assuming zero");
413 BIASERR(
"could not read K, assuming identity");
421 #ifdef BIAS_HAVE_XML2
424 cerr<<
"No XML support found, so no writing of P as xml !"<<endl;
436 cout<<
"K: "<<K<<endl;
440 cout<<
"R: "<<P.
GetR()<<endl;
449 cout<<
"r[axis, angle]: "<<axis[0]<<
" "<<axis[1]
450 <<
" "<<axis[2]<<
" "<<angle<<endl;
451 cout<<
"|axis|= "<<axis.
NormL2()<<endl;
452 cout<<
"R: "<<R<<endl;
454 temp.
Set(axis, angle);
455 cout<<
"R-axisAngle:\n "<<R-temp<<endl;
460 cout<<
"C: "<<P.
GetC()<<endl;
464 cout<<
"A: "<<P.
GetA()<<endl;
468 cout<<
"H: "<<P.
GetH()<<endl;
472 cout<<
"V: "<<P.
GetV()<<endl;
475 if (*GetCameraParamFromK) {
476 #ifdef BIAS_HAVE_XML2
489 stringstream cpfilename;
490 cpfilename <<argv[i]<<
".cameraparam.xml";
493 cerr<<
"Error, no K to construct cameraparam"<<endl;
496 cerr<<
"Missing XML2 support led to missing class BIAS::CameraParam, "
497 <<
"cant extract EXIF."<<endl;
501 #ifdef BIAS_HAVE_XML2
502 if(GetProjection->size() > 0) {
504 if(proj.
XMLWrite(*GetProjection)!=0) {
505 BIASERR(
"error writing projection");
512 if (Outfile->size() > 0)
void GetTime(unsigned long long int &sec, unsigned long long int &usec)
bool IsZero(double eps=0.0) const
Checks if the matrix is a null matrix.
const Vector3< double > & GetC() const
bool IsCValid() const
Is field of data valid or unknown ? if false, the return value of the Get...()-function is undefined...
bool IsKValid() const
Is field of data valid or unknown ? if false, the return value of the Get...()-function is undefined...
void GetOrientation(float &o0, float &o1, float &o2) const
bool * AddParamBool(const std::string &name, const std::string &help, bool deflt=false, char cmdshort=0, int Group=GRP_NOSHOW)
int GetPrincipalPoint(double &x, double &y)
look up principal point
int ReadFromEXIF(const std::string &filename)
read jpeg EXIF header and set camera parameter
int GetR(Matrix3x3< double > &R)
unsigned int GetWidth() const
int ParseCommandLine(int &argc, char *argv[])
scan command line arguments for valid parameters
const BIAS::UUID & GetUID() const
returns the UUID of the image
void Usage(std::ostream &os=std::cout)
print Help-Information to stdout
void Set(const Vector3< ROTATION_MATRIX_TYPE > &w, const ROTATION_MATRIX_TYPE phi)
Set from rotation axis w and angle phi (in rad)
void SetZero()
Sets all values to zero.
This class hides the underlying projection model, like projection matrix, spherical camera...
int XMLWrite(const std::string &Filename, int CompressionLevel=0, bool AutoAddCompressionSuffix=true, std::string encoding="UTF-8") const
call this to add the class to a new xml tree and write it to the file Filename.
int GetH(Vector3< double > &H)
returns the unit vector H0, while H0 and V0 span the camera coordinate system in world coordinates ...
unsigned int GetHeight() const
int GetFreeGroupID()
returns unused group id
std::string GetASCIIString()
int Read(const std::string &filename)
main entry routine to read all EXIF tags from the header of image file.
const BIAS::PMatrix & GetP() const
int GetFocalLengthXPixel(double &fp)
compute focallength in pixels
int GetC(Vector3< double > &C)
computes translation vector origin world coo -> origin camera coo (center), uses decomposition, which is cached
This class Param provides generic support for parameters.
int SetGroupName(const int group_id, const std::string &name)
sets the name for a group
contains all atribute info and values of e.g. a file.
void InitExifTags()
initialize me vector with all known EXIF tags
K describes the mapping from world coordinates (wcs) to pixel coordinates (pcs).
int GetA(Vector3< double > &A)
returns the unit vector A which is the normal vector to the image plane in world coordinates.
bool IsRValid() const
Is field of data valid or unknown ? if false, the return value of the Get...()-function is undefined...
int GetRotationAxisAngle(Vector3< ROTATION_MATRIX_TYPE > &axis, ROTATION_MATRIX_TYPE &angle) const
Calculates angle and rotation axis representation for this rotation matrix.
describes a projective 3D -> 2D mapping in homogenous coordinates
const RMatrix & GetR() const
int WriteCameraData(const std::string &Filename) const
Write all data to a camera data parameter file )
void SetMetaData(const MetaData &m)
bool IsPValid() const
Is field of data valid or unknown ? if false, the return value of the Get...()-function is undefined...
const BIAS::Projection & GetProj() const
This is the base class for images in BIAS.
std::string * AddParamString(const std::string &name, const std::string &help, std::string deflt="", char cmdshort=0, int Group=GRP_NOSHOW)
int ParseMetaData(bool bUse2x64bitTS=true)
After ImageIO::Load() operated on AppData_, this method fills P_, Timestamp, DC_*, ...
int GetFocalLengthYPixel(double &fp)
compute focallength in pixels
double NormL2() const
the L2 norm sqrt(a^2 + b^2 + c^2)
const KMatrix & GetK() const
int GetV(Vector3< double > &V)
This is not the cam.# standard CAHV, but the unit vector H0.
void Compose(const Matrix3x3< double > &K, const Matrix3x3< double > &R, const Vector3< double > &C)
composes this from K, R and C using P = [ K R' | -K R' C ] with R' = transpose(R) ...
void SetIdentity()
set the elements of this matrix to the identity matrix (possibly overriding the inherited method) ...
int GetK(KMatrix &K)
calibration matrix