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);";
149 std::cerr <<
"Could not create database structure." << std::endl;
205 return cropFactor > 0.1;
266 return projection != -1;
303 bool GetHFOV(
const std::string& lens,
const double focallength, std::vector<HFOVData>&
hfovData)
const
329 bool SaveHFOV(
const std::string& lens,
const double focallength,
const double HFOV,
const int weight = 10)
343 if (
sqlite3_prepare_v2(
m_db,
"INSERT INTO LensHFOVTable(Lens, Focallength, HFOV, Weight) VALUES(?1,?2,?3,?4);", -1, &
statement, &
tail) ==
SQLITE_OK)
356 bool GetLensCrop(
const std::string& lens,
const double focal,
const int width,
const int height, std::vector<CropData> &
cropData)
const
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)
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)
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)
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)
483 bool SaveDistortion(
const std::string& lens,
const double focallength,
const double a,
const double b,
const double c,
const int weight = 10)
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)
508 bool GetVignettingData(
const std::string& lens,
const double focallength,
const double aperture, std::vector<Vignettingdata>&
vigData)
const
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;",
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)
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)
587 bool GetTCAData(
const std::string& lens,
const double focallength, std::vector<TCAdata>&
tcaData)
const
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)
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)
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)
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)
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)
686 const std::string
statement_tca(
"SELECT DISTINCT Lens FROM TCATable");
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;",
796 std::ofstream
output(filename.c_str());
799 output <<
"TABLE=CameraCropTable" << std::endl
800 <<
"COLUMNS=Maker;Model;Cropfactor" << std::endl;
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;
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;
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;
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)
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;
889 std::cout <<
"\tImporting LensHFOVTable..." << std::endl;
893 std::cerr <<
"Error in input file." << std::endl;
901 std::cout <<
"\tImporting LensCropTable..." << std::endl;
905 std::cerr <<
"Error in input file." << std::endl;
913 std::cout <<
"\tImporting DistortionTable..." << std::endl;
917 std::cerr <<
"Error in input file." << std::endl;
925 std::cout <<
"\tImporting VignettingTable..." << std::endl;
929 std::cerr <<
"Error in input file." << std::endl;
937 std::cout <<
"\tImporting TCATable..." << std::endl;
941 std::cerr <<
"Error in input file." << std::endl;
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;
1060 for (
int i = 0;
i < count; ++
i)
1080 if (
s.compare(0, 8,
"COLUMNS=") != 0)
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")
1105 std::cerr <<
"ERROR: Missing column \"Maker\"." << std::endl;
1110 std::cerr <<
"ERROR: Missing column \"Model\"." << std::endl;
1115 std::cerr <<
"ERROR: Missing column \"Cropfactor\"." << std::endl;
1123 while (!
input.eof())
1125 if (
s ==
"ENDTABLE")
1130 if (
items.size() == columns.size())
1149 if (
s.compare(0, 8,
"COLUMNS=") != 0)
1156 for (
size_t i = 0;
i < columns.size(); ++
i)
1158 if (columns[
i] ==
"Lens")
1162 if (columns[
i] ==
"Projection")
1169 std::cerr <<
"ERROR: Missing column \"Lens\"." << std::endl;
1174 std::cerr <<
"ERROR: Missing column \"Projection\"." << std::endl;
1182 while (!
input.eof())
1184 if (
s ==
"ENDTABLE")
1189 if (
items.size() == columns.size())
1208 if (
s.compare(0, 8,
"COLUMNS=") != 0)
1217 for (
size_t i = 0;
i < columns.size(); ++
i)
1219 if (columns[
i] ==
"Lens")
1223 if (columns[
i] ==
"Focallength")
1227 if (columns[
i] ==
"HFOV")
1231 if (columns[
i] ==
"Weight")
1238 std::cerr <<
"ERROR: Missing column \"Lens\"." << std::endl;
1243 std::cerr <<
"ERROR: Missing column \"Focallength\"." << std::endl;
1248 std::cerr <<
"ERROR: Missing column \"HFOV\"." << std::endl;
1253 std::cerr <<
"ERROR: Missing column \"Weight\"." << std::endl;
1261 while (!
input.eof())
1263 if (
s ==
"ENDTABLE")
1268 if (
items.size() == columns.size())
1292 if (
s.compare(0, 8,
"COLUMNS=") != 0)
1305 for (
size_t i = 0;
i < columns.size(); ++
i)
1307 if (columns[
i] ==
"Lens")
1311 if (columns[
i] ==
"Focallength")
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")
1342 std::cerr <<
"ERROR: Missing column \"Lens\"." << std::endl;
1347 std::cerr <<
"ERROR: Missing column \"Focallength\"." << std::endl;
1352 std::cerr <<
"ERROR: Missing column \"Width\"." << std::endl;
1357 std::cerr <<
"ERROR: Missing column \"Height\"." << std::endl;
1362 std::cerr <<
"ERROR: Missing column \"CropLeft\"." << std::endl;
1367 std::cerr <<
"ERROR: Missing column \"CropRight\"." << std::endl;
1372 std::cerr <<
"ERROR: Missing column \"CropTop\"." << std::endl;
1377 std::cerr <<
"ERROR: Missing column \"CropBottom\"." << std::endl;
1385 while (!
input.eof())
1387 if (
s ==
"ENDTABLE")
1392 if (
items.size() == columns.size())
1419 if (
s.compare(0, 8,
"COLUMNS=") != 0)
1430 for (
size_t i = 0;
i < columns.size(); ++
i)
1432 if (columns[
i] ==
"Lens")
1436 if (columns[
i] ==
"Focallength")
1440 if (columns[
i] ==
"a")
1444 if (columns[
i] ==
"b")
1448 if (columns[
i] ==
"c")
1452 if (columns[
i] ==
"Weight")
1459 std::cerr <<
"ERROR: Missing column \"Lens\"." << std::endl;
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;
1484 std::cerr <<
"ERROR: Missing column \"Weight\"." << std::endl;
1492 while (!
input.eof())
1494 if (
s ==
"ENDTABLE")
1499 if (
items.size() == columns.size())
1502 double focallength, a, b, c;
1524 if (
s.compare(0, 8,
"COLUMNS=") != 0)
1537 for (
size_t i = 0;
i < columns.size(); ++
i)
1539 if (columns[
i] ==
"Lens")
1543 if (columns[
i] ==
"Focallength")
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")
1574 std::cerr <<
"ERROR: Missing column \"Lens\"." << std::endl;
1579 std::cerr <<
"ERROR: Missing column \"Focallength\"." << std::endl;
1584 std::cerr <<
"ERROR: Missing column \"Aperture\"." << std::endl;
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;
1609 std::cerr <<
"ERROR: Missing column \"Weight\"." << std::endl;
1617 while (!
input.eof())
1619 if (
s ==
"ENDTABLE")
1624 if (
items.size() == columns.size())
1627 double focallength, aperture, distance, Vb, Vc, Vd;
1651 if (
s.compare(0, 8,
"COLUMNS=") != 0)
1667 for (
size_t i = 0;
i < columns.size(); ++
i)
1669 if (columns[
i] ==
"Lens")
1673 if (columns[
i] ==
"Focallength")
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")
1716 std::cerr <<
"ERROR: Missing column \"Lens\"." << std::endl;
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;
1766 std::cerr <<
"ERROR: Missing column \"Weight\"." << std::endl;
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);
1811 if (
s.compare(0, 8,
"COLUMNS=") != 0)
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")
1866 std::cerr <<
"ERROR: Missing column \"Maker\"." << std::endl;
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;
1906 std::cerr <<
"ERROR: Missing column \"Weight\"." << std::endl;
1914 while (!
input.eof())
1916 if (
s ==
"ENDTABLE")
1921 if (
items.size() == columns.size())
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");
2027 return std::string();
2060 return (a > 0) ? 1 : ((a < 0) ? -1 : 0);
2079 std::vector<Database::CropData>
cropData;
2084 int left, right, top, bottom;
2114 cropRect.setUpperLeft(vigra::Point2D(left, top));
2115 cropRect.setLowerRight(vigra::Point2D(right, bottom));
2125 std::vector<Database::HFOVData>
hfovdata;
2169 std::vector<Database::Distortiondata>
distdata;
2187 std::cout <<
"Invalid focallength" << std::endl;
2212 std::vector<Database::Vignettingdata>
vigdata;
2250 if (
vigdata[0].aperture - 0.3 <= aperture && aperture <=
vigdata[1].aperture + 0.3)
2333 if (
vigdata[0].aperture - 0.3 <= aperture && aperture <=
vigdata[1].aperture + 0.3)
2343 if (
vigdata[2].aperture - 0.3 <= aperture && aperture <=
vigdata[3].aperture + 0.3)
2374 std::vector<Database::TCAdata>
tcadata;
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);
2561 if (
lenses.getLenses().getNumberOfParts() == 1)
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)
2605 const double focal =
img0.getExifFocalLength();
2643 const std::vector<double>
dist =
img0.getRadialDistortion();
2644 if (
dist.size() == 4)
2663 const std::vector<double>
vigParam =
img0.getRadialVigCorrCoeff();
2668 if (sum>0.5 && sum <= 1.01)
class to access Hugins camera and lens database
Somewhere to specify what variables belong to what.
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)
Make an ImageVariableGroup for lenses and other common concepts.
void OutputSQLToStream(const std::string &sqlstatement, std::ostream &stream)
bool SaveCropFactor(const std::string &maker, const std::string &model, const double cropFactor)
bool ImportFromFile(const std::string &filename)
bool ImportVignetting(std::istream &input)
bool GetHFOV(const std::string &lens, const double focallength, std::vector< HFOVData > &hfovData) const
bool ImportHFOV(std::istream &input)
bool ImportTCA(std::istream &input)
bool ImportEMOR(std::istream &input)
bool RemoveLens(const std::string &lensname)
bool ExportToFile(const std::string &filename)
bool GetLensNames(const bool distortion, const bool vignetting, const bool tca, LensList &lensList) const
bool GetLensProjection(const std::string &lens, int &projection) const
bool ImportLensCrop(std::istream &input)
bool ImportProjection(std::istream &input)
bool m_runningTransaction
bool RemoveLensCrop(const std::string &lens, const double focal, const int width, const int height)
std::string GetDBFilename() const
bool GetDistortionData(const std::string &lens, const double focallength, std::vector< Distortiondata > &distData) const
bool RemoveCameraFromTable(const std::string &table, const std::string &maker, const std::string &model)
Database(const std::string &filename)
bool GetTCAData(const std::string &lens, const double focallength, std::vector< TCAdata > &tcaData) const
bool GetCropFactor(const std::string &maker, const std::string &model, double &cropFactor) const
bool SaveLensProjection(const std::string &lens, const int projection)
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)
bool ImportCropFactor(std::istream &input)
bool GetLensCrop(const std::string &lens, const double focal, const int width, const int height, std::vector< CropData > &cropData) const
bool SaveHFOV(const std::string &lens, const double focallength, const double HFOV, const int weight=10)
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)
bool RemoveCamera(const std::string &maker, const std::string &model)
bool SaveDistortion(const std::string &lens, const double focallength, const double a, const double b, const double c, const int weight=10)
bool ImportDistortion(std::istream &input)
bool RemoveLensFromTable(const std::string &table, const std::string &lens)
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 GetVignettingData(const std::string &lens, const double focallength, const double aperture, std::vector< Vignettingdata > &vigData) const
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)
virtual ~LensDB()
destructor
bool CleanUpDatabase()
compress database by remove all entries and insert instead the average values
bool RemoveCamera(const std::string &maker, const std::string &model)
remove all database entry which refers to given camera
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 SaveTCA(const std::string &lens, const double focal, const std::vector< double > &tca_red, const std::vector< double > &tca_blue, const int weight=10)
saves the tca distortion parameters of the lens
bool GetLensNames(const bool distortion, const bool vignetting, const bool tca, LensList &lensList) const
return a vector of lenses with selected database entries
static void Clean()
cleanup the static LensDB instance, must be called at the end of the program
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 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
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
bool GetVignetting(const std::string &lens, const double focal, const double aperture, const double distance, std::vector< double > &vignetting) const
returns the vignetting parameters of the lens
bool GetCrop(const std::string &lens, const double focal, const vigra::Size2D &imageSize, vigra::Rect2D &cropRect) const
returns the crop of the lens the information for landscape and portrait images are stored separately
bool GetTCA(const std::string &lens, const double focal, std::vector< double > &tca_red, std::vector< double > &tca_blue) const
returns the tca distortion parameters of the lens
bool GetDistortion(const std::string &lens, const double focal, std::vector< double > &distortion) const
returns the distortion parameters of the lens
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 SaveCameraCrop(const std::string &maker, const std::string &model, const double cropfactor)
save the camera with the given cropfactor into the database
static LensDB & GetSingleton()
returns the static LensDB instance
bool GetCropFactor(const std::string &maker, const std::string &model, double &cropFactor) const
returns the crop factor for the given camera (maker/model)
bool ImportFromFile(const std::string &filename)
import data from external file
bool SaveLensProjection(const std::string &lens, const BaseSrcPanoImage::Projection projection)
saves the projection for the lens in the database
std::string GetDBFilename() const
returns the filename of the lens database
bool GetFov(const std::string &lens, const double focal, double &fov) const
returns the field of view of the lens the fov is always returned for a landscape image with aspect ra...
static LensDB * m_instance
bool GetProjection(const std::string &lens, BaseSrcPanoImage::Projection &projection) const
returns the projection of the lens
bool RemoveLens(const std::string &lensname)
remove all database entry which refers to given lens
bool ExportToFile(const std::string &filename)
export database to file
const SrcPanoImage & getImage(std::size_t nr) const
get a panorama image, counting starts with 0
std::size_t getNrOfCtrlPoints() const
number of control points
std::size_t getNrOfImages() const
number of images.
All variables of a source image.
static double calcFocalLength(SrcPanoImage::Projection proj, double hfov, double crop, vigra::Size2D imageSize)
calcualte focal length, given crop factor and hfov
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
static double calcCropFactor(SrcPanoImage::Projection proj, double hfov, double focalLength, vigra::Size2D imageSize)
calculate crop factor, given focal length and hfov
double InterpolateValueTriangle(double x, double y, double x1, double y1, double z1, double x2, double y2, double z2, double x3, double y3, double z3)
std::vector< std::string > LensList
vector storing a list of lens names
bool SaveLensDataFromPano(const HuginBase::Panorama &pano)
routine for automatically saving information from pano into database
double InterpolateValue(double x, double x0, double y0, double x1, double y1)
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
mainly consists of wrapper around the pano tools library, to assist in ressource management and to pr...
std::vector< std::string > SplitString(const std::string &s, const std::string &sep)
split string s at given sep, returns vector of strings
std::string GetUserAppDataDir()
returns the directory for user specific Hugin settings, e.g.
bool FileExists(const std::string &filename)
checks if file exists
bool stringToDouble(const STR &str_, double &dest)
convert a string to a double, ignore localisation.
bool stringToInt(const std::string &s, int &val)
convert string to integer value, returns true, if sucessful
std::vector< deghosting::BImagePtr > threshold(const std::vector< deghosting::FImagePtr > &inputImages, const double threshold, const uint16_t flags)
Threshold function used for creating alpha masks for images.