40 LensDB* LensDB::m_instance=NULL;
83 std::cerr <<
"Can't open database: " << sqlite3_errmsg(
m_db) << std::endl;
119 const char* createDB =
"PRAGMA user_version=1;"
120 "CREATE TABLE CameraCropTable (Maker TEXT, Model TEXT, Cropfactor REAL, PRIMARY KEY (Maker, Model));"
121 "CREATE TABLE LensProjectionTable (Lens TEXT PRIMARY KEY, Projection INTEGER);"
122 "CREATE TABLE LensHFOVTable (Lens TEXT, Focallength REAL, HFOV REAL, Weight INTEGER);"
123 "CREATE INDEX HFOV_IndexLens ON LensHFOVTable (Lens);"
124 "CREATE INDEX HFOV_IndexLens2 ON LensHFOVTable (Lens, Focallength);"
125 "CREATE TABLE LensCropTable (Lens TEXT, Focallength REAL, Width INTEGER, Height INTEGER, CropLeft INTEGER, CropRight INTEGER, CropTop INTEGER, CropBottom INTEGER, PRIMARY KEY (Lens, Focallength, Width, Height));"
126 "CREATE TABLE DistortionTable(Lens TEXT, Focallength REAL, a REAL, b REAL, c REAL, Weight INTEGER);"
127 "CREATE INDEX Dist_IndexLens ON DistortionTable (Lens);"
128 "CREATE INDEX Dist_IndexLensFocal ON DistortionTable (Lens, Focallength);"
129 "CREATE TABLE VignettingTable (Lens TEXT, Focallength REAL, Aperture REAL, Distance REAL, Vb REAL, Vc REAL, Vd REAL, Weight INTEGER);"
130 "CREATE INDEX Vig_IndexLens ON VignettingTable (Lens);"
131 "CREATE INDEX Vig_IndexLensFocal ON VignettingTable (Lens, Focallength);"
132 "CREATE INDEX Vig_IndexLensFocalApertureDistance ON VignettingTable (Lens, Focallength, Aperture, Distance);"
133 "CREATE TABLE TCATable (Lens TEXT, Focallength REAL, ra REAL, rb REAL, rc REAL, rd REAL, ba REAL, bb REAL, bc REAL, bd REAL, Weight INTEGER);"
134 "CREATE INDEX TCA_IndexLens ON TCATable (Lens);"
135 "CREATE INDEX TCA_IndexLensFocal ON TCATable (Lens, Focallength);"
136 "CREATE TABLE EMORTable (Maker TEXT, Model TEXT, ISO INTEGER, Ra REAL, Rb REAL, Rc REAL, Rd REAL, Re REAL, Weight INTEGER);"
137 "CREATE INDEX EMOR_Index_Cam ON EMORTable (Maker, Model);"
138 "CREATE INDEX EMOR_Index_CamISO ON EMORTable (Maker, Model, ISO);";
143 if (sqlite3_exec(
m_db, createDB, NULL, NULL, NULL) == SQLITE_OK)
149 std::cerr <<
"Could not create database structure." << std::endl;
162 sqlite3_stmt *statement;
165 if (sqlite3_prepare_v2(
m_db,
"PRAGMA user_version;", -1, &statement, &tail) == SQLITE_OK)
167 if (sqlite3_step(statement) == SQLITE_ROW)
169 version = sqlite3_column_int(statement, 0);
172 sqlite3_finalize(statement);
182 bool GetCropFactor(
const std::string& maker,
const std::string& model,
double &cropFactor)
const
189 sqlite3_stmt *statement;
191 if (sqlite3_prepare_v2(
m_db,
"SELECT Cropfactor FROM CameraCropTable WHERE Maker=?1 AND Model=?2;", -1, &statement, &tail) == SQLITE_OK)
193 sqlite3_bind_text(statement, 1, maker.c_str(), -1, NULL);
194 sqlite3_bind_text(statement, 2, model.c_str(), -1, NULL);
195 if (sqlite3_step(statement) == SQLITE_ROW)
197 cropFactor = sqlite3_column_double(statement, 0);
200 sqlite3_finalize(statement);
201 if (cropFactor < 0.1 || cropFactor>100)
205 return cropFactor > 0.1;
209 bool SaveCropFactor(
const std::string& maker,
const std::string& model,
const double cropFactor)
216 if (cropFactor < 0.1 || cropFactor > 100)
220 sqlite3_stmt *statement;
224 if (sqlite3_prepare_v2(
m_db,
"INSERT OR FAIL INTO CameraCropTable (Maker, Model, Cropfactor) VALUES(?1,?2,?3);", -1, &statement, &tail) == SQLITE_OK)
226 sqlite3_bind_text(statement, 1, maker.c_str(), -1, NULL);
227 sqlite3_bind_text(statement, 2, model.c_str(), -1, NULL);
228 sqlite3_bind_double(statement, 3, cropFactor);
229 returnValue = sqlite3_step(statement);
230 if (returnValue == SQLITE_CONSTRAINT)
232 sqlite3_finalize(statement);
233 if (sqlite3_prepare_v2(
m_db,
"UPDATE CameraCropTable SET Cropfactor=?3 WHERE Maker=?1 AND Model=?2;", -1, &statement, &tail) == SQLITE_OK)
235 sqlite3_bind_text(statement, 1, maker.c_str(), -1, NULL);
236 sqlite3_bind_text(statement, 2, model.c_str(), -1, NULL);
237 sqlite3_bind_double(statement, 3, cropFactor);
238 returnValue = sqlite3_step(statement);
242 sqlite3_finalize(statement);
244 return returnValue == SQLITE_DONE;
255 sqlite3_stmt *statement;
257 if (sqlite3_prepare_v2(
m_db,
"SELECT Projection FROM LensProjectionTable WHERE Lens=?1;", -1, &statement, &tail) == SQLITE_OK)
259 sqlite3_bind_text(statement, 1, lens.c_str(), -1, NULL);
260 if (sqlite3_step(statement) == SQLITE_ROW)
262 projection = sqlite3_column_int(statement, 0);
265 sqlite3_finalize(statement);
266 return projection != -1;
276 sqlite3_stmt *statement;
280 if (sqlite3_prepare_v2(
m_db,
"INSERT OR FAIL INTO LensProjectionTable (Lens, Projection) VALUES(?1,?2);", -1, &statement, &tail) == SQLITE_OK)
282 sqlite3_bind_text(statement, 1, lens.c_str(), -1, NULL);
283 sqlite3_bind_int(statement, 2, projection);
284 returnValue = sqlite3_step(statement);
285 if (returnValue == SQLITE_CONSTRAINT)
287 sqlite3_finalize(statement);
288 if (sqlite3_prepare_v2(
m_db,
"UPDATE LensProjectionTable SET Projection=?2 WHERE Lens=?1;", -1, &statement, &tail) == SQLITE_OK)
290 sqlite3_bind_text(statement, 1, lens.c_str(), -1, NULL);
291 sqlite3_bind_int(statement, 2, projection);
292 returnValue = sqlite3_step(statement);
296 sqlite3_finalize(statement);
298 return returnValue == SQLITE_DONE;
303 bool GetHFOV(
const std::string& lens,
const double focallength, std::vector<HFOVData>& hfovData)
const
310 sqlite3_stmt *statement;
312 if (sqlite3_prepare_v2(
m_db,
"SELECT Focallength, SUM(HFOV*Weight)/SUM(Weight) FROM LensHFOVTable WHERE Lens=?1 GROUP BY Focallength ORDER BY ABS(Focallength-?2) ASC LIMIT 2;", -1, &statement, &tail) == SQLITE_OK)
314 sqlite3_bind_text(statement, 1, lens.c_str(), -1, NULL);
315 sqlite3_bind_double(statement, 2, focallength);
316 while (sqlite3_step(statement) == SQLITE_ROW)
319 newhfovData.
focallength = sqlite3_column_double(statement, 0);
320 newhfovData.
HFOV = sqlite3_column_double(statement, 1);
321 hfovData.push_back(newhfovData);
324 sqlite3_finalize(statement);
325 return !hfovData.empty();
329 bool SaveHFOV(
const std::string& lens,
const double focallength,
const double HFOV,
const int weight = 10)
336 if (HFOV < 0.1 || HFOV>360)
340 sqlite3_stmt *statement;
343 if (sqlite3_prepare_v2(
m_db,
"INSERT INTO LensHFOVTable(Lens, Focallength, HFOV, Weight) VALUES(?1,?2,?3,?4);", -1, &statement, &tail) == SQLITE_OK)
345 sqlite3_bind_text(statement, 1, lens.c_str(), -1, NULL);
346 sqlite3_bind_double(statement, 2, focallength);
347 sqlite3_bind_double(statement, 3, HFOV);
348 sqlite3_bind_int(statement, 4, weight);
349 returnValue = sqlite3_step(statement);
351 sqlite3_finalize(statement);
352 return returnValue == SQLITE_DONE;
356 bool GetLensCrop(
const std::string& lens,
const double focal,
const int width,
const int height, std::vector<CropData> &cropData)
const
363 sqlite3_stmt *statement;
365 if (sqlite3_prepare_v2(
m_db,
"SELECT Focallength, CropLeft, CropRight, CropTop, CropBottom FROM LensCropTable WHERE Lens=?1 AND Width=?2 AND Height=?3 ORDER BY ABS(Focallength-?4) ASC LIMIT 2;", -1, &statement, &tail) == SQLITE_OK)
367 sqlite3_bind_text(statement, 1, lens.c_str(), -1, NULL);
368 sqlite3_bind_int(statement, 2, width);
369 sqlite3_bind_int(statement, 3, height);
370 sqlite3_bind_double(statement, 4, focal);
371 while (sqlite3_step(statement) == SQLITE_ROW)
374 newCropData.
focallength = sqlite3_column_double(statement, 0);
375 newCropData.
left = sqlite3_column_int(statement, 1);
376 newCropData.
right = sqlite3_column_int(statement, 2);
377 newCropData.
top = sqlite3_column_int(statement, 3);
378 newCropData.
bottom = sqlite3_column_int(statement, 4);
379 cropData.push_back(newCropData);
382 sqlite3_finalize(statement);
383 return !cropData.empty();
387 bool SaveLensCrop(
const std::string& lens,
const double focal,
const int width,
const int height,
const int left,
const int right,
const int top,
const int bottom)
393 sqlite3_stmt *statement;
397 if (sqlite3_prepare_v2(
m_db,
"INSERT OR FAIL INTO LensCropTable (Lens, Focallength, Width, Height, CropLeft, CropRight, CropTop, CropBottom) VALUES(?1,?2,?3,?4,?5,?6,?7,?8);", -1, &statement, &tail) == SQLITE_OK)
399 sqlite3_bind_text(statement, 1, lens.c_str(), -1, NULL);
400 sqlite3_bind_double(statement, 2, focal);
401 sqlite3_bind_int(statement, 3, width);
402 sqlite3_bind_int(statement, 4, height);
403 sqlite3_bind_int(statement, 5, left);
404 sqlite3_bind_int(statement, 6, right);
405 sqlite3_bind_int(statement, 7, top);
406 sqlite3_bind_int(statement, 8, bottom);
407 returnValue = sqlite3_step(statement);
408 if (returnValue == SQLITE_CONSTRAINT)
410 sqlite3_finalize(statement);
411 if (sqlite3_prepare_v2(
m_db,
"UPDATE LensCropTable SET CropLeft=?5, CropRight=?6, CropTop=?7, CropBottom=?8 WHERE Lens=?1 AND Focallength=?2 AND Width=?3 AND Height=?4;", -1, &statement, &tail) == SQLITE_OK)
413 sqlite3_bind_text(statement, 1, lens.c_str(), -1, NULL);
414 sqlite3_bind_double(statement, 2, focal);
415 sqlite3_bind_int(statement, 3, width);
416 sqlite3_bind_int(statement, 4, height);
417 sqlite3_bind_int(statement, 5, left);
418 sqlite3_bind_int(statement, 6, right);
419 sqlite3_bind_int(statement, 7, top);
420 sqlite3_bind_int(statement, 8, bottom);
421 returnValue = sqlite3_step(statement);
425 sqlite3_finalize(statement);
427 return returnValue == SQLITE_DONE;
430 bool RemoveLensCrop(
const std::string& lens,
const double focal,
const int width,
const int height)
436 sqlite3_stmt *statement;
439 if (sqlite3_prepare_v2(
m_db,
"DELETE FROM LensCropTable WHERE Lens=?1 AND Focallength=?2 AND Width=?3 AND Height=?4;", -1, &statement, &tail) == SQLITE_OK)
441 sqlite3_bind_text(statement, 1, lens.c_str(), -1, NULL);
442 sqlite3_bind_double(statement, 2, focal);
443 sqlite3_bind_int(statement, 3, width);
444 sqlite3_bind_int(statement, 4, height);
445 returnValue = sqlite3_step(statement);
447 sqlite3_finalize(statement);
449 return returnValue == SQLITE_DONE;
455 bool GetDistortionData(
const std::string& lens,
const double focallength, std::vector<Distortiondata>& distData)
const
462 sqlite3_stmt *statement;
464 if (sqlite3_prepare_v2(
m_db,
"SELECT Focallength, SUM(a*Weight)/SUM(Weight), SUM(b*Weight)/SUM(Weight), SUM(c*Weight)/SUM(Weight) FROM DistortionTable WHERE Lens=?1 GROUP BY Focallength ORDER BY ABS(Focallength-?2) ASC LIMIT 2;", -1, &statement, &tail) == SQLITE_OK)
466 sqlite3_bind_text(statement, 1, lens.c_str(), -1, NULL);
467 sqlite3_bind_double(statement, 2, focallength);
468 while (sqlite3_step(statement) == SQLITE_ROW)
471 newDistData.
focallength = sqlite3_column_double(statement, 0);
472 newDistData.
a = sqlite3_column_double(statement, 1);
473 newDistData.
b = sqlite3_column_double(statement, 2);
474 newDistData.
c = sqlite3_column_double(statement, 3);
475 distData.push_back(newDistData);
478 sqlite3_finalize(statement);
479 return !distData.empty();
483 bool SaveDistortion(
const std::string& lens,
const double focallength,
const double a,
const double b,
const double c,
const int weight = 10)
489 sqlite3_stmt *statement;
492 if (sqlite3_prepare_v2(
m_db,
"INSERT INTO DistortionTable(Lens, Focallength, a, b, c, Weight) VALUES(?1,?2,?3,?4,?5,?6);", -1, &statement, &tail) == SQLITE_OK)
494 sqlite3_bind_text(statement, 1, lens.c_str(), -1, NULL);
495 sqlite3_bind_double(statement, 2, focallength);
496 sqlite3_bind_double(statement, 3, a);
497 sqlite3_bind_double(statement, 4, b);
498 sqlite3_bind_double(statement, 5, c);
499 sqlite3_bind_int(statement, 6, weight);
500 returnValue = sqlite3_step(statement);
502 sqlite3_finalize(statement);
503 return returnValue == SQLITE_DONE;
508 bool GetVignettingData(
const std::string& lens,
const double focallength,
const double aperture, std::vector<Vignettingdata>& vigData)
const
515 sqlite3_stmt *statement;
517 if (sqlite3_prepare_v2(
m_db,
518 "SELECT Focallength, Aperture, SUM(Vb*Weight)/SUM(Weight), SUM(Vc*Weight)/SUM(Weight), SUM(Vd*Weight)/SUM(Weight) FROM VignettingTable "
519 "WHERE Lens = ?1 AND ("
522 "(SELECT Focallength FROM VignettingTable WHERE Lens=?1 GROUP BY Focallength ORDER BY ABS(Focallength-?2) LIMIT 1) "
524 "(SELECT Aperture FROM VignettingTable WHERE Lens=?1 AND "
526 "(SELECT Focallength from VignettingTable WHERE Lens=?1 GROUP BY Focallength ORDER BY ABS(Focallength-?2) LIMIT 1) "
527 "GROUP BY Aperture ORDER BY ABS(Aperture-?3) LIMIT 2)"
530 "(SELECT Focallength FROM VignettingTable WHERE Lens=?1 GROUP BY Focallength ORDER BY ABS(Focallength-?2) LIMIT 1 OFFSET 1) "
532 "(SELECT Aperture FROM VignettingTable WHERE Lens=?1 AND "
534 "(SELECT Focallength FROM VignettingTable WHERE Lens=?1 GROUP BY Focallength ORDER BY ABS(Focallength-?2) LIMIT 1 OFFSET 1) "
535 "GROUP BY Aperture ORDER BY ABS(Aperture-?3) LIMIT 2)"
538 "GROUP BY Focallength, Aperture ORDER BY Focallength, Aperture;",
539 -1, &statement, &tail) == SQLITE_OK)
541 sqlite3_bind_text(statement, 1, lens.c_str(), -1, NULL);
542 sqlite3_bind_double(statement, 2, focallength);
543 sqlite3_bind_double(statement, 3, aperture);
544 while (sqlite3_step(statement) == SQLITE_ROW)
547 newVigData.
focallength = sqlite3_column_double(statement, 0);
548 newVigData.
aperture = sqlite3_column_double(statement, 1);
549 newVigData.
Vb = sqlite3_column_double(statement, 2);
550 newVigData.
Vc = sqlite3_column_double(statement, 3);
551 newVigData.
Vd = sqlite3_column_double(statement, 4);
552 vigData.push_back(newVigData);
555 sqlite3_finalize(statement);
556 return !vigData.empty();
560 bool SaveVignetting(
const std::string& lens,
const double focallength,
const double aperture,
const double distance,
const double Vb,
const double Vc,
const double Vd,
const int weight = 10)
566 sqlite3_stmt *statement;
569 if (sqlite3_prepare_v2(
m_db,
"INSERT INTO VignettingTable(Lens, Focallength, Aperture, Distance, Vb, Vc, Vd, Weight) VALUES(?1,?2,?3,?4,?5,?6,?7,?8);", -1, &statement, &tail) == SQLITE_OK)
571 sqlite3_bind_text(statement, 1, lens.c_str(), -1, NULL);
572 sqlite3_bind_double(statement, 2, focallength);
573 sqlite3_bind_double(statement, 3, aperture);
574 sqlite3_bind_double(statement, 4, distance);
575 sqlite3_bind_double(statement, 5, Vb);
576 sqlite3_bind_double(statement, 6, Vc);
577 sqlite3_bind_double(statement, 7, Vd);
578 sqlite3_bind_int(statement, 8, weight);
579 returnValue = sqlite3_step(statement);
581 sqlite3_finalize(statement);
582 return returnValue == SQLITE_DONE;
587 bool GetTCAData(
const std::string& lens,
const double focallength, std::vector<TCAdata>& tcaData)
const
594 sqlite3_stmt *statement;
596 if (sqlite3_prepare_v2(
m_db,
"SELECT Focallength, SUM(ra*Weight)/SUM(Weight), SUM(rb*Weight)/SUM(Weight), SUM(rc*Weight)/SUM(Weight), SUM(rd*Weight)/SUM(Weight), SUM(ba*Weight)/SUM(Weight), SUM(bb*Weight)/SUM(Weight), SUM(bc*Weight)/SUM(Weight), SUM(bd*Weight)/SUM(Weight) FROM TCATable WHERE Lens=?1 GROUP BY Focallength ORDER BY ABS(Focallength-?2) ASC LIMIT 2;", -1, &statement, &tail) == SQLITE_OK)
598 sqlite3_bind_text(statement, 1, lens.c_str(), -1, NULL);
599 sqlite3_bind_double(statement, 2, focallength);
600 while (sqlite3_step(statement) == SQLITE_ROW)
603 newTCAData.
focallength = sqlite3_column_double(statement, 0);
604 newTCAData.
ra = sqlite3_column_double(statement, 1);
605 newTCAData.
rb = sqlite3_column_double(statement, 2);
606 newTCAData.
rc = sqlite3_column_double(statement, 3);
607 newTCAData.
rd = sqlite3_column_double(statement, 4);
608 newTCAData.
ba = sqlite3_column_double(statement, 5);
609 newTCAData.
bb = sqlite3_column_double(statement, 6);
610 newTCAData.
bc = sqlite3_column_double(statement, 7);
611 newTCAData.
bd = sqlite3_column_double(statement, 8);
612 tcaData.push_back(newTCAData);
615 sqlite3_finalize(statement);
616 return !tcaData.empty();
620 bool SaveTCAData(
const std::string& lens,
const double focallength,
const double ra,
const double rb,
const double rc,
const double rd,
621 const double ba,
const double bb,
const double bc,
const double bd,
const int weight = 10)
627 sqlite3_stmt *statement;
630 if (sqlite3_prepare_v2(
m_db,
"INSERT INTO TCATable(Lens, Focallength, ra, rb, rc, rd, ba, bb, bc, bd, Weight) VALUES(?1,?2,?3,?4,?5,?6,?7,?8,?9,?10,?11);", -1, &statement, &tail) == SQLITE_OK)
632 sqlite3_bind_text(statement, 1, lens.c_str(), -1, NULL);
633 sqlite3_bind_double(statement, 2, focallength);
634 sqlite3_bind_double(statement, 3, ra);
635 sqlite3_bind_double(statement, 4, rb);
636 sqlite3_bind_double(statement, 5, rc);
637 sqlite3_bind_double(statement, 6, rd);
638 sqlite3_bind_double(statement, 7, ba);
639 sqlite3_bind_double(statement, 8, bb);
640 sqlite3_bind_double(statement, 9, bc);
641 sqlite3_bind_double(statement, 10, bd);
642 sqlite3_bind_int(statement, 11, weight);
643 returnValue = sqlite3_step(statement);
645 sqlite3_finalize(statement);
646 return returnValue == SQLITE_DONE;
650 bool SaveEMoR(
const std::string& maker,
const std::string& model,
const int iso,
const double Ra,
const double Rb,
const double Rc,
const double Rd,
const double Re,
const int weight = 10)
656 sqlite3_stmt *statement;
659 if (sqlite3_prepare_v2(
m_db,
"INSERT INTO EMORTable(Maker, Model, ISO, Ra, Rb, Rc, Rd, Re, Weight) VALUES(?1,?2,?3,?4,?5,?6,?7,?8,?9);", -1, &statement, &tail) == SQLITE_OK)
661 sqlite3_bind_text(statement, 1, maker.c_str(), -1, NULL);
662 sqlite3_bind_text(statement, 2, model.c_str(), -1, NULL);
663 sqlite3_bind_int(statement, 3, iso);
664 sqlite3_bind_double(statement, 4, Ra);
665 sqlite3_bind_double(statement, 5, Rb);
666 sqlite3_bind_double(statement, 6, Rc);
667 sqlite3_bind_double(statement, 7, Rd);
668 sqlite3_bind_double(statement, 8, Re);
669 sqlite3_bind_int(statement, 9, weight);
670 returnValue = sqlite3_step(statement);
672 sqlite3_finalize(statement);
673 return returnValue == SQLITE_DONE;
683 sqlite3_stmt *statement;
684 const std::string statement_distortion(
"SELECT DISTINCT Lens FROM DistortionTable");
685 const std::string statement_vignetting(
"SELECT DISTINCT Lens FROM VignettingTable");
686 const std::string statement_tca(
"SELECT DISTINCT Lens FROM TCATable");
687 std::string statementString;
690 statementString = statement_distortion;
694 if (!statementString.empty())
696 statementString.append(
" UNION ");
698 statementString.append(statement_vignetting);
702 if (!statementString.empty())
704 statementString.append(
" UNION ");
706 statementString.append(statement_tca);
708 if (statementString.empty())
713 if (sqlite3_prepare_v2(
m_db, statementString.c_str(), -1, &statement, &tail) == SQLITE_OK)
715 while (sqlite3_step(statement) == SQLITE_ROW)
717 std::stringstream stream;
718 stream << sqlite3_column_text(statement, 0);
719 lensList.push_back(stream.str());
722 sqlite3_finalize(statement);
723 return !lensList.empty();
734 "INSERT INTO DistortionTable(Lens, Focallength, a, b, c, Weight) "
735 "SELECT Lens, Focallength, SUM(a*Weight)/SUM(Weight), SUM(b*Weight)/SUM(Weight), SUM(c*Weight)/SUM(Weight), SUM(Weight*Weight)/SUM(Weight)*-1 FROM DistortionTable GROUP By Lens, Focallength;"
736 "DELETE FROM DistortionTable WHERE Weight>=0;"
737 "UPDATE DistortionTable SET Weight=-Weight WHERE Weight<0;"
738 "INSERT INTO LensHFOVTable(Lens, Focallength, HFOV, Weight) "
739 "SELECT Lens, Focallength, SUM(HFOV*Weight)/SUM(Weight), SUM(Weight*Weight)/SUM(Weight)*-1 FROM LensHFOVTable GROUP By Lens, Focallength;"
740 "DELETE FROM LensHFOVTable WHERE Weight>=0;"
741 "UPDATE LensHFOVTable SET Weight=-Weight WHERE Weight<0;"
742 "INSERT INTO TCATable(Lens, Focallength, ra, rb, rc, rd, ba, bb, bc, bd, Weight) "
743 "SELECT Lens, Focallength, SUM(ra*Weight)/SUM(Weight), SUM(rb*Weight)/SUM(Weight), SUM(rc*Weight)/SUM(Weight), SUM(rd*Weight)/SUM(Weight), SUM(ba*Weight)/SUM(Weight), SUM(bb*Weight)/SUM(Weight), SUM(bc*Weight)/SUM(Weight), SUM(bd*Weight)/SUM(Weight), SUM(Weight*Weight)/SUM(Weight)*-1 FROM TCATable GROUP By Lens, Focallength;"
744 "DELETE FROM TCATable WHERE Weight>=0;"
745 "UPDATE TCATable SET Weight=-Weight WHERE Weight<0;"
746 "INSERT INTO VignettingTable(Lens, Focallength, Aperture, Distance, Vb, Vc, Vd, Weight) "
747 "SELECT Lens, Focallength, Aperture, Distance, SUM(Vb*Weight)/SUM(Weight), SUM(Vc*Weight)/SUM(Weight), SUM(Vd*Weight)/SUM(Weight), SUM(Weight*Weight)/SUM(Weight)*-1 FROM VignettingTable GROUP By Lens, Focallength, Aperture, Distance;"
748 "DELETE FROM VignettingTable WHERE Weight>=0;"
749 "UPDATE VignettingTable SET Weight=-Weight WHERE Weight<0;"
750 "INSERT INTO EMORTable(Maker, Model, ISO, Ra, Rb, Rc, Rd, Re, Weight) "
751 "SELECT Maker, Model, ISO, SUM(Ra*Weight)/SUM(Weight), SUM(Rb*Weight)/SUM(Weight), SUM(Rc*Weight)/SUM(Weight), SUM(Rd*Weight)/SUM(Weight), SUM(Re*Weight)/SUM(Weight), SUM(Weight*Weight)/SUM(Weight)*-1 FROM EMORTable GROUP By Maker, Model, ISO;"
752 "DELETE FROM EMORTable WHERE Weight>=0;"
753 "UPDATE EMORTable SET Weight=-Weight WHERE Weight<0;",
756 return sqlite3_exec(
m_db,
"VACUUM;", NULL, NULL, NULL) == SQLITE_OK;
796 std::ofstream output(filename.c_str());
797 if (output.is_open())
799 output <<
"TABLE=CameraCropTable" << std::endl
800 <<
"COLUMNS=Maker;Model;Cropfactor" << std::endl;
801 OutputSQLToStream(
"SELECT Maker, Model, Cropfactor FROM CameraCropTable;", output);
802 output <<
"ENDTABLE" << std::endl
803 <<
"TABLE=LensProjectionTable" << std::endl
804 <<
"COLUMNS=Lens;Projection" << std::endl;
806 output <<
"ENDTABLE" << std::endl
807 <<
"TABLE=LensHFOVTable" << std::endl
808 <<
"COLUMNS=Lens;Focallength;HFOV;Weight" << std::endl;
809 OutputSQLToStream(
"SELECT Lens, Focallength, HFOV, Weight FROM LensHFOVTable;", output);
810 output <<
"ENDTABLE" << std::endl
811 <<
"TABLE=LensCropTable" << std::endl
812 <<
"COLUMNS=Lens;Focallength;Width;Height;CropLeft;CropRight;CropTop;CropBottom" << std::endl;
813 OutputSQLToStream(
"SELECT Lens, Focallength, Width, Height, CropLeft, CropRight, CropTop, CropBottom FROM TABLE LensCropTable;", output);
814 output <<
"ENDTABLE" << std::endl
815 <<
"TABLE=DistortionTable" << std::endl
816 <<
"COLUMNS=Lens;Focallength;a;b;c;Weight" << std::endl;
817 OutputSQLToStream(
"SELECT Lens, Focallength, a, b, c, Weight FROM DistortionTable;", output);
818 output <<
"ENDTABLE" << std::endl
819 <<
"TABLE=VignettingTable" << std::endl
820 <<
"COLUMNS=Lens;Focallength;Aperture;Distance;Vb;Vc;Vd;Weight" << std::endl;
821 OutputSQLToStream(
"SELECT Lens, Focallength, Aperture, Distance, Vb, Vc, Vd, Weight FROM VignettingTable;", output);
822 output <<
"ENDTABLE" << std::endl
823 <<
"TABLE=TCATable" << std::endl
824 <<
"COLUMNS=Lens;Focallength;ra;rb;rc;rd;ba;bb;bc;bd;Weight" << std::endl;
825 OutputSQLToStream(
"SELECT Lens, Focallength, ra, rb, rc, rd, ba, bb, bc, bd, Weight FROM TCATable;", output);
826 output <<
"ENDTABLE" << std::endl
827 <<
"TABLE=EMORTable" << std::endl
828 <<
"COLUMNS=Maker;Model;ISO;Ra;Rb;Rc;Rd;Re;Weight" << std::endl;
829 OutputSQLToStream(
"SELECT Maker, Model, ISO, Ra, Rb, Rc, Rd, Re, Weight FROM EMORTable;", output);
830 output <<
"ENDTABLE" << std::endl;
836 std::cerr <<
"Could not open file \"" << filename <<
"\"." << std::endl;
847 std::ifstream input(filename);
853 std::getline(input, line);
858 if (line.compare(0, 6,
"TABLE=") == 0)
861 if (substring.size() == 2)
863 if (substring[1] ==
"CameraCropTable")
865 std::cout <<
"\tImporting CameraCropTable..." << std::endl;
869 std::cerr <<
"Error in input file." << std::endl;
875 if (substring[1] ==
"LensProjectionTable")
877 std::cout <<
"\tImporting LensProjectionTable..." << std::endl;
881 std::cerr <<
"Error in input file." << std::endl;
887 if (substring[1] ==
"LensHFOVTable")
889 std::cout <<
"\tImporting LensHFOVTable..." << std::endl;
893 std::cerr <<
"Error in input file." << std::endl;
899 if (substring[1] ==
"LensCropTable")
901 std::cout <<
"\tImporting LensCropTable..." << std::endl;
905 std::cerr <<
"Error in input file." << std::endl;
911 if (substring[1] ==
"DistortionTable")
913 std::cout <<
"\tImporting DistortionTable..." << std::endl;
917 std::cerr <<
"Error in input file." << std::endl;
923 if (substring[1] ==
"VignettingTable")
925 std::cout <<
"\tImporting VignettingTable..." << std::endl;
929 std::cerr <<
"Error in input file." << std::endl;
935 if (substring[1] ==
"TCATable")
937 std::cout <<
"\tImporting TCATable..." << std::endl;
941 std::cerr <<
"Error in input file." << std::endl;
947 if (substring[1] ==
"EMORTable")
949 std::cout <<
"\tImporting EMORTable..." << std::endl;
953 std::cerr <<
"Error in input file." << std::endl;
960 std::cerr <<
"Error in input file (Unknown table \"" << substring[1] <<
"\")." << std::endl;
973 std::cerr <<
"Error in input file (Could not parse table name)." << std::endl;
980 std::cerr <<
"Error in input file (Could not find TABLE section)." << std::endl;
991 std::cerr <<
"Could not open file \"" << filename <<
"\"." << std::endl;
1008 sqlite3_exec(
m_db,
"COMMIT TRANSACTION;", NULL, NULL, NULL);
1016 sqlite3_stmt *statement;
1018 int returnValue = 0;
1019 std::string sqlStatement(
"DELETE FROM ");
1020 sqlStatement.append(table);
1021 sqlStatement.append(
" WHERE Lens=?;");
1022 if (sqlite3_prepare_v2(
m_db, sqlStatement.c_str(), -1, &statement, &tail) == SQLITE_OK)
1024 sqlite3_bind_text(statement, 1, lens.c_str(), -1, NULL);
1025 returnValue = sqlite3_step(statement);
1027 sqlite3_finalize(statement);
1028 return returnValue == SQLITE_DONE;
1033 sqlite3_stmt *statement;
1035 int returnValue = 0;
1036 std::string sqlStatement(
"DELETE FROM ");
1037 sqlStatement.append(table);
1038 sqlStatement.append(
" WHERE Maker=?1 AND Model=?2;");
1039 if (sqlite3_prepare_v2(
m_db, sqlStatement.c_str(), -1, &statement, &tail) == SQLITE_OK)
1041 sqlite3_bind_text(statement, 1, maker.c_str(), -1, NULL);
1042 sqlite3_bind_text(statement, 2, model.c_str(), -1, NULL);
1043 returnValue = sqlite3_step(statement);
1045 sqlite3_finalize(statement);
1046 return returnValue == SQLITE_DONE;
1051 sqlite3_stmt *statement;
1053 if (sqlite3_prepare_v2(
m_db, sqlstatement.c_str(), -1, &statement, &tail) == SQLITE_OK)
1055 while (sqlite3_step(statement) == SQLITE_ROW)
1057 const int count = sqlite3_column_count(statement);
1060 for (
int i = 0; i < count; ++i)
1062 stream << sqlite3_column_text(statement, i);
1069 stream << std::endl;
1072 sqlite3_finalize(statement);
1078 std::getline(input, s);
1080 if (s.compare(0, 8,
"COLUMNS=") != 0)
1085 int indexMaker = -1;
1086 int indexModel = -1;
1087 int indexCropfactor = -1;
1088 for (
size_t i = 0; i < columns.size(); ++i)
1090 if (columns[i] ==
"Maker")
1094 if (columns[i] ==
"Model")
1098 if (columns[i] ==
"Cropfactor")
1100 indexCropfactor = i;
1103 if (indexMaker == -1)
1105 std::cerr <<
"ERROR: Missing column \"Maker\"." << std::endl;
1108 if (indexModel == -1)
1110 std::cerr <<
"ERROR: Missing column \"Model\"." << std::endl;
1113 if (indexCropfactor == -1)
1115 std::cerr <<
"ERROR: Missing column \"Cropfactor\"." << std::endl;
1122 std::getline(input, s);
1123 while (!input.eof())
1125 if (s ==
"ENDTABLE")
1130 if (items.size() == columns.size())
1136 SaveCropFactor(items[indexMaker], items[indexModel], cropfactor);
1139 std::getline(input, s);
1147 std::getline(input, s);
1149 if (s.compare(0, 8,
"COLUMNS=") != 0)
1155 int indexProjection = -1;
1156 for (
size_t i = 0; i < columns.size(); ++i)
1158 if (columns[i] ==
"Lens")
1162 if (columns[i] ==
"Projection")
1164 indexProjection = i;
1167 if (indexLens == -1)
1169 std::cerr <<
"ERROR: Missing column \"Lens\"." << std::endl;
1172 if (indexProjection == -1)
1174 std::cerr <<
"ERROR: Missing column \"Projection\"." << std::endl;
1181 std::getline(input, s);
1182 while (!input.eof())
1184 if (s ==
"ENDTABLE")
1189 if (items.size() == columns.size())
1198 std::getline(input, s);
1206 std::getline(input, s);
1208 if (s.compare(0, 8,
"COLUMNS=") != 0)
1214 int indexFocallength = -1;
1216 int indexWeight = -1;
1217 for (
size_t i = 0; i < columns.size(); ++i)
1219 if (columns[i] ==
"Lens")
1223 if (columns[i] ==
"Focallength")
1225 indexFocallength = i;
1227 if (columns[i] ==
"HFOV")
1231 if (columns[i] ==
"Weight")
1236 if (indexLens == -1)
1238 std::cerr <<
"ERROR: Missing column \"Lens\"." << std::endl;
1241 if (indexFocallength == -1)
1243 std::cerr <<
"ERROR: Missing column \"Focallength\"." << std::endl;
1246 if (indexHFOV == -1)
1248 std::cerr <<
"ERROR: Missing column \"HFOV\"." << std::endl;
1251 if (indexWeight == -1)
1253 std::cerr <<
"ERROR: Missing column \"Weight\"." << std::endl;
1260 std::getline(input, s);
1261 while (!input.eof())
1263 if (s ==
"ENDTABLE")
1268 if (items.size() == columns.size())
1279 SaveHFOV(items[indexLens], focallength, hfov, weight);
1282 std::getline(input, s);
1290 std::getline(input, s);
1292 if (s.compare(0, 8,
"COLUMNS=") != 0)
1298 int indexFocallength = -1;
1299 int indexWidth = -1;
1300 int indexHeight = -1;
1301 int indexCropLeft = -1;
1302 int indexCropRight = -1;
1303 int indexCropTop = -1;
1304 int indexCropBottom = -1;
1305 for (
size_t i = 0; i < columns.size(); ++i)
1307 if (columns[i] ==
"Lens")
1311 if (columns[i] ==
"Focallength")
1313 indexFocallength = i;
1315 if (columns[i] ==
"Width")
1319 if (columns[i] ==
"Height")
1323 if (columns[i] ==
"CropLeft")
1327 if (columns[i] ==
"CropRight")
1331 if (columns[i] ==
"CropTop")
1335 if (columns[i] ==
"CropBottom")
1337 indexCropBottom = i;
1340 if (indexLens == -1)
1342 std::cerr <<
"ERROR: Missing column \"Lens\"." << std::endl;
1345 if (indexFocallength == -1)
1347 std::cerr <<
"ERROR: Missing column \"Focallength\"." << std::endl;
1350 if (indexWidth == -1)
1352 std::cerr <<
"ERROR: Missing column \"Width\"." << std::endl;
1355 if (indexHeight == -1)
1357 std::cerr <<
"ERROR: Missing column \"Height\"." << std::endl;
1360 if (indexCropLeft == -1)
1362 std::cerr <<
"ERROR: Missing column \"CropLeft\"." << std::endl;
1365 if (indexCropRight == -1)
1367 std::cerr <<
"ERROR: Missing column \"CropRight\"." << std::endl;
1370 if (indexCropTop == -1)
1372 std::cerr <<
"ERROR: Missing column \"CropTop\"." << std::endl;
1375 if (indexCropBottom == -1)
1377 std::cerr <<
"ERROR: Missing column \"CropBottom\"." << std::endl;
1384 std::getline(input, s);
1385 while (!input.eof())
1387 if (s ==
"ENDTABLE")
1392 if (items.size() == columns.size())
1396 int width, height, cropLeft, cropRight, cropTop, cropBottom;
1406 SaveLensCrop(items[indexLens], focallength, width, height, cropLeft, cropRight, cropTop, cropBottom);
1409 std::getline(input, s);
1417 std::getline(input, s);
1419 if (s.compare(0, 8,
"COLUMNS=") != 0)
1425 int indexFocallength = -1;
1429 int indexWeight = -1;
1430 for (
size_t i = 0; i < columns.size(); ++i)
1432 if (columns[i] ==
"Lens")
1436 if (columns[i] ==
"Focallength")
1438 indexFocallength = i;
1440 if (columns[i] ==
"a")
1444 if (columns[i] ==
"b")
1448 if (columns[i] ==
"c")
1452 if (columns[i] ==
"Weight")
1457 if (indexLens == -1)
1459 std::cerr <<
"ERROR: Missing column \"Lens\"." << std::endl;
1462 if (indexFocallength == -1)
1464 std::cerr <<
"ERROR: Missing column \"Focallength\"." << std::endl;
1469 std::cerr <<
"ERROR: Missing column \"a\"." << std::endl;
1474 std::cerr <<
"ERROR: Missing column \"b\"." << std::endl;
1479 std::cerr <<
"ERROR: Missing column \"c\"." << std::endl;
1482 if (indexWeight == -1)
1484 std::cerr <<
"ERROR: Missing column \"Weight\"." << std::endl;
1491 std::getline(input, s);
1492 while (!input.eof())
1494 if (s ==
"ENDTABLE")
1499 if (items.size() == columns.size())
1502 double focallength, a, b, c;
1514 std::getline(input, s);
1522 std::getline(input, s);
1524 if (s.compare(0, 8,
"COLUMNS=") != 0)
1530 int indexFocallength = -1;
1531 int indexAperture = -1;
1532 int indexDistance = -1;
1536 int indexWeight = -1;
1537 for (
size_t i = 0; i < columns.size(); ++i)
1539 if (columns[i] ==
"Lens")
1543 if (columns[i] ==
"Focallength")
1545 indexFocallength = i;
1547 if (columns[i] ==
"Aperture")
1551 if (columns[i] ==
"Distance")
1555 if (columns[i] ==
"Vb")
1559 if (columns[i] ==
"Vc")
1563 if (columns[i] ==
"Vd")
1567 if (columns[i] ==
"Weight")
1572 if (indexLens == -1)
1574 std::cerr <<
"ERROR: Missing column \"Lens\"." << std::endl;
1577 if (indexFocallength == -1)
1579 std::cerr <<
"ERROR: Missing column \"Focallength\"." << std::endl;
1582 if (indexAperture == -1)
1584 std::cerr <<
"ERROR: Missing column \"Aperture\"." << std::endl;
1587 if (indexDistance == -1)
1589 std::cerr <<
"ERROR: Missing column \"Distance\"." << std::endl;
1594 std::cerr <<
"ERROR: Missing column \"Vb\"." << std::endl;
1599 std::cerr <<
"ERROR: Missing column \"Vc\"." << std::endl;
1604 std::cerr <<
"ERROR: Missing column \"Vd\"." << std::endl;
1607 if (indexWeight == -1)
1609 std::cerr <<
"ERROR: Missing column \"Weight\"." << std::endl;
1616 std::getline(input, s);
1617 while (!input.eof())
1619 if (s ==
"ENDTABLE")
1624 if (items.size() == columns.size())
1627 double focallength, aperture, distance, Vb, Vc, Vd;
1638 SaveVignetting(items[indexLens], focallength, aperture, distance, Vb, Vc, Vd, weight);
1641 std::getline(input, s);
1649 std::getline(input, s);
1651 if (s.compare(0, 8,
"COLUMNS=") != 0)
1657 int indexFocallength = -1;
1666 int indexWeight = -1;
1667 for (
size_t i = 0; i < columns.size(); ++i)
1669 if (columns[i] ==
"Lens")
1673 if (columns[i] ==
"Focallength")
1675 indexFocallength = i;
1677 if (columns[i] ==
"ra")
1681 if (columns[i] ==
"rb")
1685 if (columns[i] ==
"rc")
1689 if (columns[i] ==
"rd")
1693 if (columns[i] ==
"ba")
1697 if (columns[i] ==
"bb")
1701 if (columns[i] ==
"bc")
1705 if (columns[i] ==
"bd")
1709 if (columns[i] ==
"Weight")
1714 if (indexLens == -1)
1716 std::cerr <<
"ERROR: Missing column \"Lens\"." << std::endl;
1719 if (indexFocallength == -1)
1721 std::cerr <<
"ERROR: Missing column \"Focallength\"." << std::endl;
1726 std::cerr <<
"ERROR: Missing column \"ra\"." << std::endl;
1731 std::cerr <<
"ERROR: Missing column \"rb\"." << std::endl;
1736 std::cerr <<
"ERROR: Missing column \"rc\"." << std::endl;
1741 std::cerr <<
"ERROR: Missing column \"rd\"." << std::endl;
1746 std::cerr <<
"ERROR: Missing column \"ba\"." << std::endl;
1751 std::cerr <<
"ERROR: Missing column \"bb\"." << std::endl;
1756 std::cerr <<
"ERROR: Missing column \"bc\"." << std::endl;
1761 std::cerr <<
"ERROR: Missing column \"bd\"." << std::endl;
1764 if (indexWeight == -1)
1766 std::cerr <<
"ERROR: Missing column \"Weight\"." << std::endl;
1773 std::getline(input, s);
1774 while (!input.eof())
1776 if (s ==
"ENDTABLE")
1781 if (items.size() == columns.size())
1784 double focallength, ra, rb, rc, rd, ba, bb, bc, bd;
1798 SaveTCAData(items[indexLens], focallength, ra, rb, rc, rd, ba, bb, bc, bd, weight);
1801 std::getline(input, s);
1809 std::getline(input, s);
1811 if (s.compare(0, 8,
"COLUMNS=") != 0)
1816 int indexMaker = -1;
1817 int indexModel = -1;
1824 int indexWeight = -1;
1825 for (
size_t i = 0; i < columns.size(); ++i)
1827 if (columns[i] ==
"Maker")
1831 if (columns[i] ==
"Model")
1835 if (columns[i] ==
"ISO")
1839 if (columns[i] ==
"Ra")
1843 if (columns[i] ==
"Rb")
1847 if (columns[i] ==
"Rc")
1851 if (columns[i] ==
"Rd")
1855 if (columns[i] ==
"Re")
1859 if (columns[i] ==
"Weight")
1864 if (indexMaker == -1)
1866 std::cerr <<
"ERROR: Missing column \"Maker\"." << std::endl;
1869 if (indexModel == -1)
1871 std::cerr <<
"ERROR: Missing column \"Model\"." << std::endl;
1876 std::cerr <<
"ERROR: Missing column \"ISO\"." << std::endl;
1881 std::cerr <<
"ERROR: Missing column \"Ra\"." << std::endl;
1886 std::cerr <<
"ERROR: Missing column \"Rb\"." << std::endl;
1891 std::cerr <<
"ERROR: Missing column \"Rc\"." << std::endl;
1896 std::cerr <<
"ERROR: Missing column \"Rd\"." << std::endl;
1901 std::cerr <<
"ERROR: Missing column \"Re\"." << std::endl;
1904 if (indexWeight == -1)
1906 std::cerr <<
"ERROR: Missing column \"Weight\"." << std::endl;
1913 std::getline(input, s);
1914 while (!input.eof())
1916 if (s ==
"ENDTABLE")
1921 if (items.size() == columns.size())
1924 double Ra, Rb, Rc, Rd, Re;
1935 SaveEMoR(items[indexMaker], items[indexModel], iso, Ra, Rb, Rc, Rd, Re, weight);
1938 std::getline(input, s);
1950 if (fabs(x1 - x0) < 1e-4)
1955 return y0 + (y1 - y0) * (x - x0) / (x1 - x0);
1959 double x1,
double y1,
double z1,
1960 double x2,
double y2,
double z2,
1961 double x3,
double y3,
double z3)
1963 const double a = (x2 - x1) * (y3 - y1) - (x3 - x1) * (y2 - y1);
1969 return z1 + ((x - x1) * ((z2 - z1) * (y3 - y1) - (y2 - y1) * (z3 - z1)) + (y - y1) * ((x2 - x1) * (z3 - z1) - (z2 - z1) * (x3 - x1))) / a;
1975 if (filename.length() == 0)
1982 filename.append(
"\\");
1984 filename.append(
"/");
1986 filename.append(
"camlens.db");
2010 void LensDB::Clean()
2019 std::string LensDB::GetDBFilename()
const
2027 return std::string();
2031 bool LensDB::GetCropFactor(
const std::string& maker,
const std::string& model,
double& cropFactor)
const
2060 return (a > 0) ? 1 : ((a < 0) ? -1 : 0);
2066 if (
fsign(focal - limit1) !=
fsign(focal - limit2))
2070 return fabs(focal - limit1) < tol * focal;
2073 bool LensDB::GetCrop(
const std::string& lens,
const double focal,
const vigra::Size2D& imageSize, vigra::Rect2D& cropRect)
const
2079 std::vector<Database::CropData> cropData;
2080 if (!
m_db->
GetLensCrop(lens, focal, imageSize.width() , imageSize.height(), cropData))
2084 int left, right, top, bottom;
2085 if (cropData.size() == 1)
2089 if (fabs(cropData[0].focallength - focal) < 0.075f * focal)
2092 left = cropData[0].left;
2093 right = cropData[0].right;
2094 top = cropData[0].top;
2095 bottom = cropData[0].bottom;
2114 cropRect.setUpperLeft(vigra::Point2D(left, top));
2115 cropRect.setLowerRight(vigra::Point2D(right, bottom));
2119 bool LensDB::GetFov(
const std::string& lens,
const double focal,
double& fov)
const
2125 std::vector<Database::HFOVData> hfovdata;
2131 if (hfovdata.size() == 1)
2135 if (fabs(hfovdata[0].focallength - focal) <= 0.075f * focal)
2138 fov = hfovdata[0].HFOV;
2153 fov =
InterpolateValue(focal, hfovdata[0].focallength, hfovdata[0].
HFOV, hfovdata[1].focallength, hfovdata[1].HFOV);
2162 bool LensDB::GetDistortion(
const std::string& lens,
const double focal, std::vector<double>& distortion)
const
2169 std::vector<Database::Distortiondata> distdata;
2174 if (distdata.size() == 1)
2178 if (fabs(distdata[0].focallength - focal) <= 0.075f * focal)
2180 distortion.push_back(distdata[0].a);
2181 distortion.push_back(distdata[0].b);
2182 distortion.push_back(distdata[0].c);
2187 std::cout <<
"Invalid focallength" << std::endl;
2198 distortion.push_back(
InterpolateValue(focal, distdata[0].focallength, distdata[0].a, distdata[1].focallength, distdata[1].a));
2199 distortion.push_back(
InterpolateValue(focal, distdata[0].focallength, distdata[0].b, distdata[1].focallength, distdata[1].b));
2200 distortion.push_back(
InterpolateValue(focal, distdata[0].focallength, distdata[0].c, distdata[1].focallength, distdata[1].c));
2205 bool LensDB::GetVignetting(
const std::string& lens,
const double focal,
const double aperture,
const double distance, std::vector<double>& vignetting)
const
2212 std::vector<Database::Vignettingdata> vigdata;
2217 const bool unknownAperture = (fabs(aperture) < 0.001f);
2218 if (vigdata.size() == 1)
2220 if ((fabs(vigdata[0].focallength - focal) <= 0.075f * focal) && (unknownAperture || fabs(vigdata[0].aperture - aperture) < 0.3f))
2222 vignetting.push_back(1.0);
2223 vignetting.push_back(vigdata[0].Vb);
2224 vignetting.push_back(vigdata[0].Vc);
2225 vignetting.push_back(vigdata[0].Vd);
2235 if (vigdata.size() == 2)
2237 if (fabs(vigdata[0].focallength - vigdata[1].focallength) < 0.001f)
2240 if (unknownAperture)
2242 vignetting.push_back(1.0);
2243 vignetting.push_back(vigdata[0].Vb);
2244 vignetting.push_back(vigdata[0].Vc);
2245 vignetting.push_back(vigdata[0].Vd);
2250 if (vigdata[0].aperture - 0.3 <= aperture && aperture <= vigdata[1].aperture + 0.3)
2252 vignetting.push_back(1.0);
2253 vignetting.push_back(
InterpolateValue(aperture, vigdata[0].aperture, vigdata[0].Vb, vigdata[1].aperture, vigdata[1].Vb));
2254 vignetting.push_back(
InterpolateValue(aperture, vigdata[0].aperture, vigdata[0].Vc, vigdata[1].aperture, vigdata[1].Vc));
2255 vignetting.push_back(
InterpolateValue(aperture, vigdata[0].aperture, vigdata[0].Vd, vigdata[1].aperture, vigdata[1].Vd));
2271 const double interpolatedAperture =
InterpolateValue(focal, vigdata[0].focallength, vigdata[0].aperture, vigdata[1].focallength, vigdata[1].aperture);
2272 if (fabs(interpolatedAperture - aperture) < 0.3f || unknownAperture)
2275 vignetting.push_back(1.0);
2276 vignetting.push_back(
InterpolateValue(focal, vigdata[0].focallength, vigdata[0].Vb, vigdata[1].focallength, vigdata[1].Vb));
2277 vignetting.push_back(
InterpolateValue(focal, vigdata[0].focallength, vigdata[0].Vc, vigdata[1].focallength, vigdata[1].Vc));
2278 vignetting.push_back(
InterpolateValue(focal, vigdata[0].focallength, vigdata[0].Vd, vigdata[1].focallength, vigdata[1].Vd));
2289 if (vigdata.size() == 3)
2295 vignetting.push_back(1.0);
2297 vigdata[0].focallength, vigdata[0].aperture, vigdata[0].Vb,
2298 vigdata[1].focallength, vigdata[1].aperture, vigdata[1].Vb,
2299 vigdata[2].focallength, vigdata[2].aperture, vigdata[2].Vb
2302 vigdata[0].focallength, vigdata[0].aperture, vigdata[0].Vc,
2303 vigdata[1].focallength, vigdata[1].aperture, vigdata[1].Vc,
2304 vigdata[2].focallength, vigdata[2].aperture, vigdata[2].Vc
2307 vigdata[0].focallength, vigdata[0].aperture, vigdata[0].Vd,
2308 vigdata[1].focallength, vigdata[1].aperture, vigdata[1].Vd,
2309 vigdata[2].focallength, vigdata[2].aperture, vigdata[2].Vd
2320 if (unknownAperture)
2323 vignetting.push_back(1.0);
2324 vignetting.push_back(
InterpolateValue(focal, vigdata[0].focallength, vigdata[0].Vb, vigdata[2].focallength, vigdata[2].Vb));
2325 vignetting.push_back(
InterpolateValue(focal, vigdata[0].focallength, vigdata[0].Vc, vigdata[2].focallength, vigdata[2].Vc));
2326 vignetting.push_back(
InterpolateValue(focal, vigdata[0].focallength, vigdata[0].Vd, vigdata[2].focallength, vigdata[2].Vd));
2332 double Vb1, Vc1, Vd1, Vb2, Vc2, Vd2;
2333 if (vigdata[0].aperture - 0.3 <= aperture && aperture <= vigdata[1].aperture + 0.3)
2335 Vb1 =
InterpolateValue(aperture, vigdata[0].aperture, vigdata[0].Vb, vigdata[1].aperture, vigdata[1].Vb);
2336 Vc1 =
InterpolateValue(aperture, vigdata[0].aperture, vigdata[0].Vc, vigdata[1].aperture, vigdata[1].Vc);
2337 Vd1 =
InterpolateValue(aperture, vigdata[0].aperture, vigdata[0].Vd, vigdata[1].aperture, vigdata[1].Vd);
2343 if (vigdata[2].aperture - 0.3 <= aperture && aperture <= vigdata[3].aperture + 0.3)
2345 Vb2 =
InterpolateValue(aperture, vigdata[2].aperture, vigdata[2].Vb, vigdata[3].aperture, vigdata[3].Vb);
2346 Vc2 =
InterpolateValue(aperture, vigdata[2].aperture, vigdata[2].Vc, vigdata[3].aperture, vigdata[3].Vc);
2347 Vd2 =
InterpolateValue(aperture, vigdata[2].aperture, vigdata[2].Vd, vigdata[3].aperture, vigdata[3].Vd);
2355 vignetting.push_back(1.0);
2356 vignetting.push_back(
InterpolateValue(focal, vigdata[0].focallength, Vb1, vigdata[2].focallength, Vb2));
2357 vignetting.push_back(
InterpolateValue(focal, vigdata[0].focallength, Vc1, vigdata[2].focallength, Vc2));
2358 vignetting.push_back(
InterpolateValue(focal, vigdata[0].focallength, Vd1, vigdata[2].focallength, Vd2));
2366 bool LensDB::GetTCA(
const std::string& lens,
const double focal, std::vector<double>& tca_red, std::vector<double>& tca_blue)
const
2374 std::vector<Database::TCAdata> tcadata;
2379 if (tcadata.size() == 1)
2383 if (fabs(tcadata[0].focallength - focal) <= 0.075f * focal)
2385 tca_red.push_back(tcadata[0].ra);
2386 tca_red.push_back(tcadata[0].rb);
2387 tca_red.push_back(tcadata[0].rc);
2388 tca_red.push_back(tcadata[0].rd);
2389 tca_blue.push_back(tcadata[0].ba);
2390 tca_blue.push_back(tcadata[0].bb);
2391 tca_blue.push_back(tcadata[0].bc);
2392 tca_blue.push_back(tcadata[0].bd);
2407 tca_red.push_back(
InterpolateValue(focal, tcadata[0].focallength, tcadata[0].ra, tcadata[1].focallength, tcadata[1].ra));
2408 tca_red.push_back(
InterpolateValue(focal, tcadata[0].focallength, tcadata[0].rb, tcadata[1].focallength, tcadata[1].rb));
2409 tca_red.push_back(
InterpolateValue(focal, tcadata[0].focallength, tcadata[0].rc, tcadata[1].focallength, tcadata[1].rc));
2410 tca_red.push_back(
InterpolateValue(focal, tcadata[0].focallength, tcadata[0].rd, tcadata[1].focallength, tcadata[1].rd));
2411 tca_blue.push_back(
InterpolateValue(focal, tcadata[0].focallength, tcadata[0].ba, tcadata[1].focallength, tcadata[1].ba));
2412 tca_blue.push_back(
InterpolateValue(focal, tcadata[0].focallength, tcadata[0].bb, tcadata[1].focallength, tcadata[1].bb));
2413 tca_blue.push_back(
InterpolateValue(focal, tcadata[0].focallength, tcadata[0].bc, tcadata[1].focallength, tcadata[1].bc));
2414 tca_blue.push_back(
InterpolateValue(focal, tcadata[0].focallength, tcadata[0].bd, tcadata[1].focallength, tcadata[1].bd));
2419 bool LensDB::GetLensNames(
const bool distortion,
const bool vignetting,
const bool tca,
LensList& lensList)
const
2429 bool LensDB::SaveCameraCrop(
const std::string& maker,
const std::string& model,
const double cropfactor)
2438 bool LensDB::SaveEMoR(
const std::string& maker,
const std::string& model,
const int iso,
const std::vector<float>& emor,
const int weight)
2440 if (
m_db == NULL || emor.size() != 5)
2444 return m_db->
SaveEMoR(maker, model, iso, emor[0], emor[1], emor[2], emor[3], emor[4], weight);
2456 bool LensDB::SaveLensCrop(
const std::string& lens,
const double focal,
const vigra::Size2D& imageSize,
const vigra::Rect2D& cropRect)
2462 if (cropRect.isEmpty())
2468 return m_db->
SaveLensCrop(lens, focal, imageSize.width(), imageSize.height(), cropRect.left(), cropRect.right(), cropRect.top(), cropRect.bottom());
2472 bool LensDB::SaveLensFov(
const std::string& lens,
const double focal,
const double fov,
const int weight)
2481 bool LensDB::SaveDistortion(
const std::string& lens,
const double focal,
const std::vector<double>& distortion,
const int weight)
2483 if (
m_db == NULL || distortion.size()!=4)
2487 return m_db->
SaveDistortion(lens, focal, distortion[0], distortion[1], distortion[2], weight);
2490 bool LensDB::SaveVignetting(
const std::string& lens,
const double focal,
const double aperture,
const double distance,
const std::vector<double>& vignetting,
const int weight)
2492 if (
m_db == NULL || vignetting.size()!=4)
2496 return m_db->
SaveVignetting(lens, focal, aperture, distance, vignetting[1], vignetting[2], vignetting[3], weight);
2499 bool LensDB::SaveTCA(
const std::string& lens,
const double focal,
const std::vector<double>& tca_red,
const std::vector<double>& tca_blue,
const int weight)
2501 if (
m_db == NULL || tca_red.size()!=4 || tca_blue.size()!=4)
2505 return m_db->
SaveTCAData(lens, focal, tca_red[0], tca_red[1], tca_red[2], tca_red[3], tca_blue[0], tca_blue[1], tca_blue[2], tca_blue[3], weight);
2508 bool LensDB::CleanUpDatabase()
2517 bool LensDB::RemoveLens(
const std::string& lensname)
2526 bool LensDB::RemoveCamera(
const std::string& maker,
const std::string& model)
2535 bool LensDB::ExportToFile(
const std::string& filename)
2544 bool LensDB::ImportFromFile(
const std::string& filename)
2569 LensDB& lensDB = LensDB::GetSingleton();
2570 const std::string camMaker = img0.getExifMake();
2571 const std::string camModel = img0.getExifModel();
2572 if (!camMaker.empty() && !camModel.empty())
2574 if (img0.getExifCropFactor() < 0.1f)
2576 double cropFactor = img0.getCropFactor();
2577 if (cropFactor == 1 && img0.getExifFocalLength() > 0)
2582 if (std::abs(cropFactor - 1) < 0.1)
2590 const std::vector<float> emor=img0.getEMoRParams();
2591 if (emor.size() == 5)
2594 for (
size_t i = 0; i < 5; ++i)
2596 sum += fabs(emor[i]);
2600 lensDB.
SaveEMoR(camMaker, camModel, img0.getExifISO(), emor);
2605 const double focal = img0.getExifFocalLength();
2606 if (!lensname.empty() && focal > 0)
2612 success = success | lensDB.
SaveLensCrop(lensname, focal, img0.getSize(), vigra::Rect2D(0, 0, 0, 0));
2617 const vigra::Rect2D cropRect = img0.getCropRect();
2618 bool sameCrop =
true;
2619 for (
size_t i = 1; i < pano.
getNrOfImages() && sameCrop; ++i)
2622 sameCrop = (img.getCropMode() == cropMode) && (img.getCropRect() == cropRect);
2626 success = success | lensDB.
SaveLensCrop(lensname, focal, img0.getSize(), cropRect);
2641 const double newHFOV =
SrcPanoImage::calcHFOV(img0.getProjection(), newFocallength, img0.getCropFactor(), vigra::Size2D(3000, 2000));
2642 success = success | lensDB.
SaveLensFov(lensname, focal, newHFOV);
2643 const std::vector<double> dist = img0.getRadialDistortion();
2644 if (dist.size() == 4)
2647 if (fabs(dist[0]) + fabs(dist[1]) + fabs(dist[2])>0.001 &&
2648 fabs(dist[0] + dist[1] + dist[2]) < 0.1)
2650 success = success | lensDB.
SaveDistortion(lensname, focal, dist);
2655 bool sameAperture =
true;
2656 for (
size_t i = 1; i < pano.
getNrOfImages() && sameAperture; ++i)
2658 sameAperture = fabs(pano.
getImage(i).getExifAperture() - img0.getExifAperture()) < 0.05;
2663 const std::vector<double> vigParam = img0.getRadialVigCorrCoeff();
2664 if (vigParam.size() == 4)
2667 const double sum = vigParam[0] + vigParam[1] + vigParam[2] + vigParam[3];
2668 if (sum>0.5 && sum <= 1.01)
2670 success = success | lensDB.
SaveVignetting(lensname, focal, img0.getExifAperture(), img0.getExifDistance(), vigParam);
bool GetLensProjection(const std::string &lens, int &projection) const
bool GetCropFactor(const std::string &maker, const std::string &model, double &cropFactor) const
bool RemoveLensFromTable(const std::string &table, const std::string &lens)
bool ImportHFOV(std::istream &input)
bool FileExists(const std::string &filename)
checks if file exists
bool SaveEMoR(const std::string &maker, const std::string &model, const int iso, const std::vector< float > &emor, const int weight=10)
save the camera with the given EMoR parameters into the database
bool SaveVignetting(const std::string &lens, const double focal, const double aperture, const double distance, const std::vector< double > &vignetting, const int weight=10)
saves the vignetting parameters of the lens
static LensDB * m_instance
bool SaveHFOV(const std::string &lens, const double focallength, const double HFOV, const int weight=10)
bool RemoveLensCrop(const std::string &lens, const double focal, const int width, const int height)
bool ImportVignetting(std::istream &input)
bool ExportToFile(const std::string &filename)
bool GetVignettingData(const std::string &lens, const double focallength, const double aperture, std::vector< Vignettingdata > &vigData) const
static double calcCropFactor(SrcPanoImage::Projection proj, double hfov, double focalLength, vigra::Size2D imageSize)
calculate crop factor, given focal length and hfov
std::string getDBLensName() const
constructs the lens name for the database it is the lensname if known, for compact cameras it is cons...
Somewhere to specify what variables belong to what.
bool m_runningTransaction
static void calcCtrlPntsErrorStats(const PanoramaData &pano, double &min, double &max, double &mean, double &var, const int &imgNr=-1, const bool onlyActive=false, const bool ignoreLineCp=false)
void OutputSQLToStream(const std::string &sqlstatement, std::ostream &stream)
bool SaveLensCrop(const std::string &lens, const double focal, const int width, const int height, const int left, const int right, const int top, const int bottom)
std::size_t getNrOfCtrlPoints() const
number of control points
bool SaveLensDataFromPano(const HuginBase::Panorama &pano)
routine for automatically saving information from pano into database
std::string GetDBFilename() const
bool ImportDistortion(std::istream &input)
bool SaveLensCrop(const std::string &lens, const double focal, const vigra::Size2D &imageSize, const vigra::Rect2D &cropRect)
saves the crop information of the lens in the database the information for landscape and portrait ima...
bool SaveDistortion(const std::string &lens, const double focallength, const double a, const double b, const double c, const int weight=10)
bool ImportEMOR(std::istream &input)
bool SaveCameraCrop(const std::string &maker, const std::string &model, const double cropfactor)
save the camera with the given cropfactor into the database
class to access Hugins camera and lens database
ConstImageVariableGroup & getLenses()
Get the ImageVariableGroup representing the group of lens variables.
std::size_t getNrOfImages() const
number of images.
bool SaveLensProjection(const std::string &lens, const BaseSrcPanoImage::Projection projection)
saves the projection for the lens in the database
bool ImportFromFile(const std::string &filename)
bool ImportLensCrop(std::istream &input)
Make an ImageVariableGroup for lenses and other common concepts.
double InterpolateValueTriangle(double x, double y, double x1, double y1, double z1, double x2, double y2, double z2, double x3, double y3, double z3)
bool stringToInt(const std::string &s, int &val)
convert string to integer value, returns true, if sucessful
static double calcFocalLength(SrcPanoImage::Projection proj, double hfov, double crop, vigra::Size2D imageSize)
calcualte focal length, given crop factor and hfov
bool stringToDouble(const STR &str_, double &dest)
convert a string to a double, ignore localisation.
bool GetLensCrop(const std::string &lens, const double focal, const int width, const int height, std::vector< CropData > &cropData) const
double InterpolateValue(double x, double x0, double y0, double x1, double y1)
bool ImportTCA(std::istream &input)
bool GetLensNames(const bool distortion, const bool vignetting, const bool tca, LensList &lensList) const
bool RemoveCameraFromTable(const std::string &table, const std::string &maker, const std::string &model)
Database(const std::string &filename)
bool SaveLensProjection(const std::string &lens, const int projection)
bool SaveVignetting(const std::string &lens, const double focallength, const double aperture, const double distance, const double Vb, const double Vc, const double Vd, const int weight=10)
bool IsFocallengthNearRange(const double focal, const double limit1, const double limit2, const double tol)
check if value is inside limit1...limit2 or it is nearer to limit1 than value*tol ...
bool SaveDistortion(const std::string &lens, const double focal, const std::vector< double > &distortion, const int weight=10)
saves the distortion parameters of the lens in the database
std::string GetUserAppDataDir()
returns the directory for user specific Hugin settings, e.g.
std::vector< std::string > LensList
vector storing a list of lens names
static double calcHFOV(SrcPanoImage::Projection proj, double fl, double crop, vigra::Size2D imageSize)
calculate hfov of an image given focal length, image size and crop factor
bool GetTCAData(const std::string &lens, const double focallength, std::vector< TCAdata > &tcaData) const
bool GetDistortionData(const std::string &lens, const double focallength, std::vector< Distortiondata > &distData) const
const SrcPanoImage & getImage(std::size_t nr) const
get a panorama image, counting starts with 0
bool GetHFOV(const std::string &lens, const double focallength, std::vector< HFOVData > &hfovData) const
bool ImportCropFactor(std::istream &input)
std::vector< std::string > SplitString(const std::string &s, const std::string &sep)
split string s at given sep, returns vector of strings
bool ImportProjection(std::istream &input)
std::size_t getNumberOfParts() const
get the number of parts.
All variables of a source image.
bool RemoveLens(const std::string &lensname)
bool SaveLensFov(const std::string &lens, const double focal, const double fov, const int weight=10)
saves the field of view of the lens the fov should always calculated for a landscape image with aspec...
bool SaveEMoR(const std::string &maker, const std::string &model, const int iso, const double Ra, const double Rb, const double Rc, const double Rd, const double Re, const int weight=10)
bool SaveCropFactor(const std::string &maker, const std::string &model, const double cropFactor)
bool RemoveCamera(const std::string &maker, const std::string &model)
bool SaveTCAData(const std::string &lens, const double focallength, const double ra, const double rb, const double rc, const double rd, const double ba, const double bb, const double bc, const double bd, const int weight=10)