From: Pablo d'A. <da...@us...> - 2005-01-17 23:33:30
|
Update of /cvsroot/hugin/hugin/src/Panorama In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv10390/src/Panorama Modified Files: PanoramaMemento.cpp Panorama.cpp Log Message: compilation fixes for gcc, previous checkin was only tested with MSVC. Index: Panorama.cpp =================================================================== RCS file: /cvsroot/hugin/hugin/src/Panorama/Panorama.cpp,v retrieving revision 1.79 retrieving revision 1.80 diff -u -d -r1.79 -r1.80 --- Panorama.cpp 17 Jan 2005 01:29:38 -0000 1.79 +++ Panorama.cpp 17 Jan 2005 23:32:57 -0000 1.80 @@ -1138,7 +1138,6 @@ } -#if 0 int Panorama::addImageAndLens(const std::string & filename, double HFOV) { // load image @@ -1146,25 +1145,11 @@ // FIXME.. check for grayscale / color Lens lens; + lens.setImageSize(vigra::Size2D(img.width(), img.height())); map_get(lens.variables,"v").setValue(HFOV); - lens.isLandscape = (img.width() > img.height()); - if (lens.isLandscape) { - lens.setRatio(((double)img.width())/img.height()); - } else { - lens.setRatio(((double)img.height())/img.width()); - } - - std::string::size_type idx = filename.rfind('.'); - if (idx == std::string::npos) { - DEBUG_DEBUG("could not find extension in filename"); - } - std::string ext = filename.substr( idx+1 ); - - if (utils::tolower(ext) == "jpg") { - // try to read exif data from jpeg files. - lens.readEXIF(filename); - } + double cropFactor = 0; + lens.initFromFile(filename, cropFactor); int matchingLensNr=-1; // FIXME: check if the exif information @@ -1175,9 +1160,9 @@ // use a lens if hfov and ratio are the same // should add a check for exif camera information as // well. - if ((l.getRatio() == lens.getRatio()) && - (l.isLandscape == lens.isLandscape) && - (const_map_get(l.variables,"v").getValue() == const_map_get(lens.variables,"v").getValue()) ) + if ((l.getAspectRatio() == lens.getAspectRatio()) && + (const_map_get(l.variables,"v").getValue() == const_map_get(lens.variables,"v").getValue()) && + (l.getSensorSize() == lens.getSensorSize())); { matchingLensNr= lnr; } @@ -1194,7 +1179,6 @@ PanoImage pimg(filename, img.width(), img.height(), (unsigned int) matchingLensNr); return addImage(pimg, vars); } -#endif void Panorama::addObserver(PanoramaObserver * o) Index: PanoramaMemento.cpp =================================================================== RCS file: /cvsroot/hugin/hugin/src/Panorama/PanoramaMemento.cpp,v retrieving revision 1.50 retrieving revision 1.51 diff -u -d -r1.50 -r1.51 --- PanoramaMemento.cpp 17 Jan 2005 01:29:38 -0000 1.50 +++ PanoramaMemento.cpp 17 Jan 2005 23:32:55 -0000 1.51 @@ -37,6 +37,8 @@ #include <PT/Panorama.h> +#include <vigra/impex.hxx> + using namespace PT; using namespace std; using namespace utils; @@ -144,11 +146,11 @@ switch (m_projectionFormat) { - case LensProjectionFormat::RECTILINEAR: - return (ssize.x/2.0) / tan(HFOV/180.0*M_PI/2); + case RECTILINEAR: + return (ssize.x/2.0) / tan(HFOV/180.0*M_PI/2); break; - case LensProjectionFormat::CIRCULAR_FISHEYE: - case LensProjectionFormat::FULL_FRAME_FISHEYE: + case CIRCULAR_FISHEYE: + case FULL_FRAME_FISHEYE: // same projection, equal area projection return ssize.x / (HFOV/180*M_PI); break; @@ -172,11 +174,11 @@ double hfov=map_get(variables, "v").getValue(); switch (m_projectionFormat) { - case LensProjectionFormat::RECTILINEAR: + case RECTILINEAR: hfov = 2*atan((ssize.x/2.0)/fl) * 180.0/M_PI; break; - case LensProjectionFormat::CIRCULAR_FISHEYE: - case LensProjectionFormat::FULL_FRAME_FISHEYE: + case CIRCULAR_FISHEYE: + case FULL_FRAME_FISHEYE: hfov = ssize.x / fl * 180/M_PI; default: // TODO: add formulas for other projections @@ -208,6 +210,97 @@ m_sensorSize = size; } + +bool Lens::initFromFile(const std::string & filename, double &cropFactor) +{ + std::string ext = utils::getExtension(filename); + std::transform(ext.begin(), ext.end(), ext.begin(), (int(*)(int)) toupper); + + int width; + int height; + try { + vigra::ImageImportInfo info(filename.c_str()); + width = info.width(); + height = info.height(); + } catch(vigra::PreconditionViolation & e) { + return false; + } + setImageSize(vigra::Size2D(width, height)); + + if (ext != "JPG" && ext != "JPEG") { + return false; + } + + ImageInfo_t exif; + ResetJpgfile(); + // Start with an empty image information structure. + + memset(&exif, 0, sizeof(exif)); + exif.FlashUsed = -1; + exif.MeteringMode = -1; + + if (!ReadJpegFile(exif,filename.c_str(), READ_EXIF)){ + DEBUG_DEBUG("Could not read jpg info"); + return false; + } + +#ifdef DEBUG + ShowImageInfo(exif); +#endif + + DEBUG_DEBUG("exif dimensions: " << exif.Width << "x" << exif.Height); + + // calc sensor dimensions if not set and 35mm focal length is available + FDiff2D sensorSize; + double focalLength = 0; + + if (exif.FocalLength > 0 && exif.CCDHeight > 0 && exif.CCDWidth > 0) { + // read sensor size directly. + sensorSize.x = exif.CCDWidth; + sensorSize.y = exif.CCDHeight; + if (strcmp(exif.CameraModel, "Canon EOS 20D") == 0) { + // special case for buggy 20D camera + sensorSize.x = 22.5; + sensorSize.y = 15; + } + cropFactor = sqrt(36.0*36.0+24.0*24)/sqrt(sensorSize.x*sensorSize.x + sensorSize.y*sensorSize.y); + focalLength = exif.FocalLength; + } else if (exif.FocalLength35mm > 0 && exif.FocalLength > 0) { + cropFactor = exif.FocalLength35mm / exif.FocalLength; + focalLength = exif.FocalLength; + } else if (exif.FocalLength > 0 || exif.FocalLength35mm > 0 ) { + // no complete specification found.. ask the user for sensor/chip size, or crop factor + if (cropFactor > 0) { + // crop factor was provided by user + } else { + // need to redo, this time with crop + cropFactor = -1; + return false; + } + if (exif.FocalLength > 0 ) { + focalLength = exif.FocalLength; + } else if (exif.FocalLength35mm) { + focalLength = exif.FocalLength35mm * cropFactor; + } + } + + if (sensorSize.x > 0) { + setSensorSize(sensorSize); + } else if (cropFactor > 0) { + setCropFactor(cropFactor); + } else { + return false; + } + + if (focalLength > 0) { + setFocalLength(focalLength); + } else { + return false; + } + + return true; +} + //========================================================================= //========================================================================= @@ -426,7 +519,7 @@ bool skipNextLine = false; bool PTGUIScriptFile = false; - + // PTGui lens line detected bool PTGUILensLine = false; |