9 enum class LCPCorrectionMode
16 enum class LCPReadingState
19 FillCommonAndCameraSettings,
23 FillChromaticGreenModel,
24 FillChromaticBlueGreenModel,
25 FillChromaticRedGreenModel,
29 inline std::ostream& operator<<(std::ostream& os,
const LCPReadingState& state)
31 if (state == LCPReadingState::WaitSequence)
33 else if (state == LCPReadingState::FillCommonAndCameraSettings)
34 os <<
"FillCommonAndCameraSettings";
35 else if (state == LCPReadingState::FillCameraSettings)
36 os <<
"FillCameraSettings";
37 else if (state == LCPReadingState::FillGeometryModel)
38 os <<
"FillGeometryModel";
39 else if (state == LCPReadingState::FillVignetteModel)
40 os <<
"FillVignetteModel";
41 else if (state == LCPReadingState::FillChromaticGreenModel)
42 os <<
"FillChromaticGreenModel";
43 else if (state == LCPReadingState::FillChromaticBlueGreenModel)
44 os <<
"FillChromaticBlueGreenModel";
45 else if (state == LCPReadingState::FillChromaticRedGreenModel)
46 os <<
"FillChromaticRedGreenModel";
47 else if (state == LCPReadingState::WaitNewModel)
55 float FocalLength = 0.f;
56 float FocusDistance = 0.f;
57 float ApertureValue = 0.f;
75 float FocalLengthX = 0.f;
76 float FocalLengthY = 0.f;
77 float ImageXCenter = 0.5f;
78 float ImageYCenter = 0.5f;
79 float ResidualMeanError = 0.f;
80 float ResidualStandardDeviation = 0.f;
81 float RadialDistortParam1 = 0.f;
82 float RadialDistortParam2 = 0.f;
83 float RadialDistortParam3 = 0.f;
84 float TangentialDistortParam1 = 0.f;
85 float TangentialDistortParam2 = 0.f;
86 float ScaleFactor = 1.f;
91 void distort(
const float x,
const float y,
float& x_d,
float& y_d)
93 const float rr = x * x + y * y;
94 const float p1 = 1.f + rr * (RadialDistortParam1 + rr * (RadialDistortParam2 + rr * RadialDistortParam3));
95 const float p2 = TangentialDistortParam1 * y + TangentialDistortParam2 * x;
96 x_d = ScaleFactor * (p1 * x + 2 * p2 * x + TangentialDistortParam2 * rr);
97 y_d = ScaleFactor * (p1 * y + 2 * p2 * y + TangentialDistortParam1 * rr);
100 bool init3(
const std::vector<float>& params)
102 if (params.size() < 7)
107 FocalLengthX = params[0];
108 FocalLengthY = params[1];
109 ImageXCenter = params[2];
110 ImageYCenter = params[3];
111 RadialDistortParam1 = params[4];
112 RadialDistortParam2 = params[5];
113 RadialDistortParam3 = params[6];
114 ScaleFactor = (params.size() >= 8) ? params[7] : 1.0;
119 bool init5(
const std::vector<float>& params)
121 if (params.size() < 9)
127 TangentialDistortParam1 = params[7];
128 TangentialDistortParam2 = params[8];
129 ScaleFactor = (params.size() >= 10) ? params[9] : 1.0;
135 inline std::ostream& operator<<(std::ostream& os,
const RectilinearModel& model)
143 os <<
"Focal: (" << model.FocalLengthX <<
", " << model.FocalLengthY <<
")" << std::endl;
144 os <<
"Center: (" << model.ImageXCenter <<
", " << model.ImageYCenter <<
")" << std::endl;
145 os <<
"Radial: (" << model.RadialDistortParam1 <<
", " << model.RadialDistortParam2 <<
", " << model.RadialDistortParam3 <<
")" << std::endl;
146 os <<
"Tangential: (" << model.TangentialDistortParam1 <<
", " << model.TangentialDistortParam2 <<
")" << std::endl;
147 os <<
"scale: " << model.ScaleFactor;
159 float FocalLengthX = 0.f;
160 float FocalLengthY = 0.f;
161 float ImageXCenter = 0.5f;
162 float ImageYCenter = 0.5f;
163 float VignetteModelParam1 = 0.f;
164 float VignetteModelParam2 = 0.f;
165 float VignetteModelParam3 = 0.f;
179 float FocalLengthX = 0.f;
180 float FocalLengthY = 0.f;
181 float ImageXCenter = 0.5f;
182 float ImageYCenter = 0.5f;
183 float ResidualMeanError = 0.f;
184 float ResidualStandardDeviation = 0.f;
185 float RadialDistortParam1 = 0.f;
186 float RadialDistortParam2 = 0.f;
283 bool _isFisheye =
false;
284 bool _hasVignetteParams =
false;
285 bool _hasChromaticParams =
false;
305 LCPinfo(
const std::string& filename,
bool fullParsing =
true);
313 void load(
const std::string& filename,
bool fullParsing =
true);
343 inline bool isEmpty()
const {
return v_lensParams.empty(); }
349 inline const std::string&
getAuthor()
const {
return Author; }
391 inline const std::string&
getLensInfo()
const {
return LensInfo; }
397 inline void getLensIDs(std::vector<int>& lensIDs)
const { lensIDs = LensID; }
403 inline void getLensModels(std::vector<std::string>& lensModels)
const { lensModels = Lens; }
439 inline void setAuthor(
const std::string& str) { Author = str; }
486 inline void setLensInfo(
const std::string& str) { LensInfo = str; }
492 inline void addLensID(
int lensID) { LensID.push_back(lensID); }
498 inline void addLensModel(std::string lensModel) { Lens.push_back(lensModel); }
526 static void XmlStartHandler(
void* pLCPinfo,
const char* el,
const char** attr);
527 static void XmlEndHandler(
void* pLCPinfo,
const char* el);
528 static void XmlStartHandlerCommonOnly(
void* pLCPinfo,
const char* el,
const char** attr);
529 static void XmlEndHandlerCommonOnly(
void* pLCPinfo,
const char* el);
530 static void XmlTextHandler(
void* pLCPinfo,
const char* s,
int len);
533 inline bool isSeqOpened() {
return _isSeqOpened; }
534 inline void openSequence() { _isSeqOpened =
true; }
535 inline void closeSequence() { _isSeqOpened =
false; }
537 inline bool isCommonOK() {
return _isCommonOK; }
538 inline void setCommonOK() { _isCommonOK =
true; }
539 inline void unsetCommonOK() { _isCommonOK =
false; }
541 inline bool isCamDataOK() {
return _isCamDataOK; }
542 inline void setCamDataOK() { _isCamDataOK =
true; }
543 inline void unsetCamDataOK() { _isCamDataOK =
false; }
545 inline bool isAlternateLensIDsOpened() {
return _inAlternateLensIDs; }
546 inline void openAlternateLensIDs() { _inAlternateLensIDs =
true; }
547 inline void closeAlternateLensIDs() { _inAlternateLensIDs =
false; }
549 inline bool isAlternateLensNamesOpened() {
return _inAlternateLensNames; }
550 inline void openAlternateLensNames() { _inAlternateLensNames =
true; }
551 inline void closeAlternateLensNames() { _inAlternateLensNames =
false; }
553 inline bool isWaitPerspModeldescription() {
return _waitPerspModeldescription; }
554 inline void setWaitPerspModeldescription() { _waitPerspModeldescription =
true; }
555 inline void unsetWaitPerspModeldescription() { _waitPerspModeldescription =
false; }
557 inline bool isGetText() {
return _getText; }
558 inline void setGetText() { _getText =
true; }
559 inline void unsetGetText() { _getText =
false; }
561 inline int getModelCount() {
return _modelCount; }
562 inline void increaseModelCount() { _modelCount++; }
564 inline void storeCurrParams() { v_lensParams.push_back(currLensParam); }
568 bool search(
settingsInfo& settings, LCPCorrectionMode mode,
int& iLow,
int& iHigh,
float& weightLow);
569 void combine(
size_t iLow,
size_t iHigh,
float weightLow, LCPCorrectionMode mode,
LensParam& pOut);
572 bool _isSeqOpened =
false;
573 bool _isCommonOK =
false;
574 bool _isCamDataOK =
false;
575 bool _inAlternateLensIDs =
false;
576 bool _inAlternateLensNames =
false;
577 bool _waitPerspModeldescription =
false;
578 bool _getText =
false;
581 LCPReadingState _currReadingState = LCPReadingState::WaitSequence;
582 std::string _currText =
"";
585 std::vector<LensParam> v_lensParams;
588 std::string Author =
"";
589 std::string Make =
"";
590 std::string Model =
"";
591 std::string UniqueCameraModel =
"";
592 bool CameraRawProfile;
593 std::vector<int> LensID;
594 std::vector<std::string> Lens;
595 std::string LensInfo =
"";
596 std::string CameraPrettyName =
"";
597 std::string LensPrettyName =
"";
598 std::string ProfileName =
"";
599 float SensorFormatFactor = 1.f;
602 float XResolution = 0.f;
603 float YResolution = 0.f;
605 void setCommonSettings(
const std::string& name);
606 void setCameraSettings(
const std::string& name);
608 void setFisheyeModel(
const std::string& name);
609 void setVignetteModel(
const std::string& name);
612 std::string reduceString(
const std::string& str);
613 std::vector<std::string> reduceStrings(
const std::vector<std::string>& v_str);
626 LCPdatabase(
const std::string& folder,
bool omitCameraModel =
false)
627 : _omitCameraModel(omitCameraModel)
629 loadDirectory(folder);
633 bool empty()
const {
return _lcpFilepaths.empty(); }
635 size_t size()
const {
return _lcpFilepaths.size(); }
637 void loadDirectory(
const std::filesystem::path& p);
639 LCPinfo* retrieveLCP() {
return retrieveLCP(_lcpFilepaths.begin()->path.string()); }
644 LCPinfo* retrieveLCP(
const std::string& p);
661 LCPinfo*
findLCP(
const std::string& cameraMake,
const std::string& cameraModel,
const std::string& lensModel,
const int lensID,
int rawMode);
666 LcpPath(
const std::filesystem::path& p)
668 reducedPath(reduceString(p.string()))
670 std::filesystem::path path;
671 std::string reducedPath;
675 std::vector<LcpPath> _lcpFilepaths;
677 std::map<std::string, LCPinfo> _lcpHeaderCache;
679 std::map<std::string, LCPinfo> _lcpCache;
681 std::map<std::string, std::string> _lcpCameraMappingCache;
684 bool _omitCameraModel =
false;