27 #include "CameraParam.hh"
28 #include <Geometry/ProjectionParametersIO.hh>
31 #include <Base/Image/ImageAttributes.hh>
72 #endif //BIAS_HAVE_XML2
89 cd_.CamModel_ =
"Default Initialization";
91 cd_.LensModel_ =
"Default Initialization";
92 cd_.LensIsSpherical_ =
false;
94 cd_.width_=cd_.height_=0;
96 cd_.focallengthDef_ = 0;
97 cd_.kc1Def_ = cd_.kc2Def_ = cd_.kc3Def_ = cd_.kc4Def_ = 0;
98 cd_.cellSizeX_ = cd_.cellSizeY_ = 0;
99 cd_.principalX_ = cd_.principalY_ =0;
100 cd_.IlluCorrX_.clear();
101 cd_.IlluCorrY_.clear();
102 cd_.knownparams_vect_.clear();
103 cd_.cellSizeX_ = cd_.cellSizeY_ = 1;
104 cd_.zoomCamera_=
false;
105 cd_.AngleCorrX_.clear();
106 cd_.AngleCorrY_.clear();
107 cd_.IlluCorrX_.clear();
108 cd_.IlluCorrY_.clear();
111 focallengthZoom_ = 0;
112 downsamplingFactor_ = 1.0;
145 if (cd_.zoomCamera_) {
146 zoom_ = cd_.knownparams_vect_[0].zoom;
147 focallengthZoom_ = cd_.knownparams_vect_[0].focallength;
151 #ifdef BIAS_HAVE_XML2
155 if (res <0)
return res;
159 #endif //BIAS_HAVE_XML2
175 if (IsPerspective()) {
176 K[0][0] = GetFocalLength();
177 K[1][1] = cd_.aspectratio_ * GetFocalLength();
179 K[0][2] = cd_.principalX_;
180 K[1][2] = cd_.principalY_;
182 BIASERR(
"No perspective camera-> No K-Matrix!");
194 return cd_.principalX_/downsamplingFactor_+0.000000001;
198 return cd_.principalY_/downsamplingFactor_+0.000000001;
202 return (
int)(cd_.height_/downsamplingFactor_+0.000000001);
206 return (
int)(cd_.width_/downsamplingFactor_+0.000000001);
210 const double AspectRatio) {
211 cd_.cellSizeX_ = CellSizeX;
212 if (AspectRatio!=0) {
213 cd_.cellSizeY_ = CellSizeX / AspectRatio;
214 cd_.aspectratio_ = AspectRatio;
216 cd_.cellSizeY_ = CellSizeX;
217 cd_.aspectratio_ = 1;
222 cd_.zoomCamera_=zoomCam;
227 return cd_.zoomCamera_;
231 if (IsPerspective()) {
232 if (cd_.zoomCamera_) {
237 BIASERR(
"No perspective camera!");
243 if (IsPerspective()) {
244 if ( cd_.zoomCamera_) {
245 return focallengthZoom_/downsamplingFactor_+0.000000001;
247 return cd_.focallengthDef_/downsamplingFactor_+0.000000001;
249 BIASERR(
"No perspective camera!");
256 return downsamplingFactor_;
260 if (cd_.zoomCamera_ && IsPerspective()) {
262 focallengthZoom_ = InterpolateFocalLength_();
263 cout <<
"interpolating zoom:" << abszoom <<
" to: " <<
264 focallengthZoom_ << endl;
266 BIASERR(
"No perspective/zoom camera!");
274 if (cd_.zoomCamera_){
275 focallengthZoom_=focallength;
276 zoom_=InterpolateAbsZoom_();
279 cd_.focallengthDef_ = focallength;
281 BIASERR(
"No perspective camera!");
285 downsamplingFactor_ = factor;
289 if (cd_.zoomCamera_ && IsPerspective()) {
290 if (cd_.focallengthDef_==0) {
291 zoom_=cd_.knownparams_vect_[0].zoom;
292 focallengthZoom_=cd_.knownparams_vect_[0].focallength;
295 focallengthZoom_=cd_.focallengthDef_;
301 #ifdef BIAS_HAVE_XML2
306 #endif //BIAS_HAVE_XML2
309 #ifdef BIAS_HAVE_XML2
314 #endif //BIAS_HAVE_XML2
318 #ifdef BIAS_HAVE_XML2
332 #endif //BIAS_HAVE_XML2
336 const int imgWidth,
const int imgHeight,
337 const double principalX,
338 const double principalY,
340 const vector<double> &AngleCorrX,
341 const vector<double> &AngleCorrY,
342 const vector<double> &IlluCorrX,
343 const vector<double> &IlluCorrY) {
347 downsamplingFactor_=1;
349 cd_.CamModel_ = CamModel;
353 cd_.width_ = imgWidth;
354 cd_.height_ = imgHeight;
355 cd_.principalX_ = principalX;
356 cd_.principalY_ = principalY;
357 cd_.radius_ = radius;
362 cd_.LensIsSpherical_ =
true;
363 cd_.zoomCamera_=
false;
365 cd_.AngleCorrX_ = AngleCorrX;
366 cd_.AngleCorrY_ = AngleCorrY;
367 cd_.IlluCorrX_ = IlluCorrX;
368 cd_.IlluCorrY_ = IlluCorrY;
374 const int imgWidth,
const int imgHeight,
375 const double principalX,
376 const double principalY,
377 const double focallength,
378 const double aspectratio,
379 const double k1,
const double k2,
const double k3,
const double k4,
380 const vector<double> &IlluCorrX,
381 const vector<double> &IlluCorrY) {
385 downsamplingFactor_=1;
386 cd_.CamModel_ = CamModel;
389 cd_.width_ = imgWidth;
390 cd_.height_ = imgHeight;
391 cd_.principalX_ = principalX;
392 cd_.principalY_ = principalY;
394 cd_.focallengthDef_ = focallength;
395 cd_.aspectratio_=aspectratio;
397 cd_.cellSizeY_=1/aspectratio;
398 cd_.LensIsSpherical_ =
false;
399 cd_.zoomCamera_=
false;
400 cd_.kc1Def_ = k1; cd_.kc2Def_ = k2; cd_.kc3Def_ = k3; cd_.kc4Def_ = k4;
401 cd_.IlluCorrX_ = IlluCorrX;
402 cd_.IlluCorrY_ = IlluCorrY;
406 cout <<
"Camera Parameters:" << endl;
407 cout <<
"CamModel_ = " << cd_.CamModel_ << endl;
408 cout <<
"CamID_ = " << cd_.CamID_ << endl;
409 cout <<
"LensModel_ = " << cd_.LensModel_ << endl;
410 cout <<
"LensIsSpherical_ = " << cd_.LensIsSpherical_ << endl;
411 cout <<
"zoomCamera_ = " << cd_.zoomCamera_ << endl;
412 cout <<
"width_ = " << cd_.width_ << endl;
413 cout <<
"height_ = " << cd_.height_ << endl;
414 for (
int i=0; i<(int)cd_.knownparams_vect_.size();i++) {
415 cout <<
"knownparams_vect_[" << i <<
"] = " << endl;
417 dp=cd_.knownparams_vect_[i];
418 cout <<
" zoom = " << dp.
zoom << endl;
419 cout <<
" focallength = " << dp.
focallength << endl;
420 cout <<
" kc1 = " << dp.
kc1 << endl;
421 cout <<
" kc2 = " << dp.
kc2 << endl;
422 cout <<
" kc3 = " << dp.
kc3 << endl;
423 cout <<
" kc4 = " << dp.
kc4 << endl;
425 for (
int i=0; i<(int) cd_.AngleCorrX_.size();i++) {
426 cout <<
"AngleCorrX_[" << i <<
"] = " << cd_.AngleCorrX_[i] << endl;
428 for (
int i=0; i<(int) cd_.AngleCorrY_.size();i++) {
429 cout <<
"AngleCorrY_[" << i <<
"] = " << cd_.AngleCorrY_[i] << endl;
431 for (
int i=0; i<(int) cd_.IlluCorrX_.size();i++) {
432 cout <<
"IlluCorrX_[" << i <<
"] = " << cd_.IlluCorrX_[i] << endl;
434 for (
int i=0; i<(int) cd_.IlluCorrY_.size();i++) {
435 cout <<
"IlluCorrY_[" << i <<
"] = " << cd_.IlluCorrY_[i] << endl;
438 cout <<
"aspectratio_ = " << cd_.aspectratio_ << endl;
439 cout <<
"cellSizeX_ = " << cd_.cellSizeX_ << endl;
440 cout <<
"cellSizeY_ = " << cd_.cellSizeY_ << endl;
441 cout <<
"principalX_ = " << cd_.principalX_ << endl;
442 cout <<
"principalY_ = " << cd_.principalY_ << endl;
443 cout <<
"focallengthDef_ = " << cd_.focallengthDef_ << endl;
444 cout <<
"kc1Def_ = " << cd_.kc1Def_ << endl;
445 cout <<
"kc2Def_ = " << cd_.kc2Def_ << endl;
446 cout <<
"kc3Def_ = " << cd_.kc3Def_ << endl;
447 cout <<
"kc4Def_ = " << cd_.kc4Def_ << endl;
448 cout <<
"downsamplingFactor_ = " << downsamplingFactor_ << endl;
449 cout << endl << endl;
491 if (cd_.knownparams_vect_[0].zoom<zoom_){
493 zoom_=cd_.knownparams_vect_[0].zoom;
496 for (i=0;i<cd_.knownparams_vect_.size();i++){
497 if (cd_.knownparams_vect_[i].zoom<=zoom_){
504 focallengthZoom_=cd_.knownparams_vect_[i-1].focallength;
505 return cd_.knownparams_vect_[i-1].focallength;
509 if (cd_.knownparams_vect_[i].zoom==zoom_){
510 return cd_.knownparams_vect_[i].focallength;
512 relnorm=(zoom_ - cd_.knownparams_vect_[i].zoom) /
513 (cd_.knownparams_vect_[i-1].zoom - cd_.knownparams_vect_[i].zoom);
516 absdist=relnorm*(cd_.knownparams_vect_[i].focallength-
517 cd_.knownparams_vect_[i-1].focallength);
519 return (absdist+cd_.knownparams_vect_[i-1].focallength);
531 if (cd_.knownparams_vect_[0].focallength<focallengthZoom_){
532 focallengthZoom_=cd_.knownparams_vect_[0].focallength;
535 for (i=0;i<cd_.knownparams_vect_.size();i++){
536 if (cd_.knownparams_vect_[i].focallength<=focallengthZoom_){
545 if (cd_.knownparams_vect_[i].focallength==focallengthZoom_){
547 return cd_.knownparams_vect_[i].zoom;
550 relnorm=(focallengthZoom_ - cd_.knownparams_vect_[i].focallength) /
551 (cd_.knownparams_vect_[i-1].focallength -
552 cd_.knownparams_vect_[i].focallength);
556 absdist=relnorm*(cd_.knownparams_vect_[i].zoom-
557 cd_.knownparams_vect_[i-1].zoom);
559 return (absdist+cd_.knownparams_vect_[i-1].zoom);
double InterpolateAbsZoom_()
void InitSpherical(const std::string CamModel, const int CamID, const std::string LensModel, const int imgWidth, const int imgHeight, const double principalX, const double principalY, const double radius, const std::vector< double > &AngleCorrX, const std::vector< double > &AngleCorrY, const std::vector< double > &IlluCorrX, const std::vector< double > &IlluCorrY)
static int ReadCameraData(const std::string &Filename, CameraData &cd, const bool silent=false)
Read a camera data parameter file and store the data in (*this)
unsigned int GetHeight() const
get camera image height.
static int WriteCameraData(const std::string &Filename, const CameraData &cd)
Write all data to a camera data parameter file )
double InterpolateFocalLength_()
double GetPrincipalY() const
get principal point, y in pixels relative to top left corner
double downsamplingFactor_
void SetFocalLength(const double f)
Set the current camera focal length, the zoom will be calculated.
int ReadFromEXIF(const std::string &filename)
read jpeg EXIF header and set camera parameter
static int SetFromKMatrix(const BIAS::KMatrix &K, const int w, const int h, CameraData &cd)
pass K and image dims to construct a simple parameter file
static void SetData_EVID31_147094(CameraData &cd)
void SetPrincipal(const double x, const double y)
Set principal point in pixels relative to top left corner.
double GetZoom() const
Set the current camera zoom, the focal length will be calculated.
unsigned int GetWidth() const
get camera image width.
void SetZoom(const double abszoom)
Set the current camera zoom, the focal length will be calculated.
static int ReadFromEXIF(const std::string &filename, CameraData &cd)
read jpeg EXIF header and set camera parameter
bool IsZoomCamera() const
True, if camera has a zoom lens.
enum BIAS::LensModel_e LensModel
double GetFocalLength() const
Get the current camera focal length.
void SetUnzoomed()
Set the zoom and focal length of a zoom camera to the default settings.
void SetData_OMNITECH_ORIFL_190_3()
int ReadCameraData(const std::string &Filename)
Add a camera sub-tree-structure to an allready created XML-tree and write the data from (*this) into ...
BIAS::KMatrix GetKMatrix() const
double GetDownsamplingFactor()
K describes the mapping from world coordinates (wcs) to pixel coordinates (pcs).
void InitPerspective(const std::string CamModel, const int CamID, const std::string LensModel, const int imgWidth, const int imgHeight, const double principalX, const double principalY, const double focallength, const double aspectratio, const double k1, const double k2, const double k3, const double k4, const std::vector< double > &IlluCorrX, const std::vector< double > &IlluCorrY)
const CameraData GetCameraData() const
int WriteCameraData(const std::string &Filename) const
Write all data to a camera data parameter file )
void SetZoomCamera(const bool zoomCam)
Set to 'true', if camera has a zoom lens.
void SetDownsampling(const double factor)
Set downsampling factor - all get functions will return transformed values.
double GetPrincipalX() const
get principal point, x in pixels relative to top left corner
void SetData_EVID31_147094()
Read a camera data form a precreated XML-tree and store the data in (*this) - called from the rig par...
void SetCellSize(const double CellSizeX, const double AspectRatio)
Set CCD cell-size in meter.
static void SetData_OMNITECH_ORIFL_190_3(CameraData &cd)
void SetIdentity()
set the elements of this matrix to the identity matrix (possibly overriding the inherited method) ...