40#include <vigra/diff2d.hxx>
41#include <vigra/imageinfo.hxx>
43#include <exiv2/exiv2.hpp>
48#define log2(x) (log(x) / M_LN2)
132 if (m_HFOV.getData() == 360)
return true;
156 if (0 > p.x || 0 > p.y || p.x >=
m_Size.getData().x || p.y >=
m_Size.getData().y) {
230 m_##name.getData() ==
other.m_##name.getData() &&
242#define image_variable( name, type, default_value ) \
243 if (PTOVariableConverterFor##name::checkApplicability(code)) \
244 return PTOVariableConverterFor##name::getValueFromVariable(code, m_##name );\
258#define image_variable( name, type, default_value ) \
259 if (PTOVariableConverterFor##name::checkApplicability(code)) \
260 {PTOVariableConverterFor##name::setValueFromVariable(code, m_##name, val);}\
278#define image_variable( name, type, default_value ) \
279 PTOVariableConverterFor##name::addToVariableMap(m_##name, vars);
292 vigra::ImageImportInfo info(getFilename().
c_str());
295 const std::string
pixeltype(info.getPixelType());
300 catch(std::exception & )
311 std::string filename = getFilename();
340 metaData[
"projection"] =
"equirectangular";
345#if defined EXIV2_VERSION && EXIV2_TEST_VERSION(0,27,99)
346 Exiv2::Image::UniquePtr image;
348 Exiv2::Image::AutoPtr image;
351 image = Exiv2::ImageFactory::open(filename.c_str());
353 catch (
const Exiv2::Error& e)
355 std::cerr <<
"Exiv2: Error reading metadata (" << e.what() <<
")" << std::endl;
361 image->readMetadata();
363 catch (
const Exiv2::Error& e)
365 std::cerr <<
"Caught Exiv2 exception '" << e.what() <<
"' for file " << filename << std::endl;
370 Exiv2::XmpData&
xmpData = image->xmpData();
376 Exiv2::XmpData::iterator
pos =
xmpData.findKey(Exiv2::XmpKey(
"Xmp.GPano.ProjectionType"));
384 pos =
xmpData.findKey(Exiv2::XmpKey(
"Xmp.GPano.CroppedAreaImageWidthPixels"));
387#if defined EXIV2_VERSION && EXIV2_TEST_VERSION(0,28,0)
396 throw std::logic_error(
"Required tag CroppedAreaImageWidthPixels missing");
398 pos =
xmpData.findKey(Exiv2::XmpKey(
"Xmp.GPano.CroppedAreaImageHeightPixels"));
401#if defined EXIV2_VERSION && EXIV2_TEST_VERSION(0,28,0)
410 throw std::logic_error(
"Required tag CroppedAreaImageHeightPixels missing");
415 pos =
xmpData.findKey(Exiv2::XmpKey(
"Xmp.GPano.FullPanoWidthPixels"));
419#if defined EXIV2_VERSION && EXIV2_TEST_VERSION(0,28,0)
428 throw std::logic_error(
"Required tag FullPanoWidthPixels missing");
431 pos =
xmpData.findKey(Exiv2::XmpKey(
"Xmp.GPano.FullPanoHeightPixels"));
434#if defined EXIV2_VERSION && EXIV2_TEST_VERSION(0,28,0)
443 throw std::logic_error(
"Required tag FullPanoHeightPixels missing");
446 pos =
xmpData.findKey(Exiv2::XmpKey(
"Xmp.GPano.CroppedAreaTopPixels"));
449#if defined EXIV2_VERSION && EXIV2_TEST_VERSION(0,28,0)
458 throw std::logic_error(
"Required tag CroppedAreaTopPixels missing");
462 metaData[
"projection"] =
"equirectangular";
470 catch (std::exception& e)
473 std::cerr <<
"Error reading GPano tags from " << filename <<
"(" << e.what() <<
")" << std::endl;
477 Exiv2::ExifData &
exifData = image->exifData();
479 std::cerr <<
"Unable to read EXIF data from opened file:" << filename << std::endl;
533 double cropFactor = 0;
572 if (cropFactor < 0.1)
639 FileMetaData::const_iterator
pos =
metaData.find(
"projection");
642 if (
pos->second ==
"equirectangular")
673 setCropFactor(cropFactor);
727 return std::string();
781 std::vector<double>
dist;
784 if (
dist.size() == 3)
810 metaData[
"readProjectionFromDB"] =
"true";
824 std::vector<double>
dist;
845 std::vector<double>
vig;
861 double d =
sqrt(36.0*36.0 + 24.0*24.0) / crop;
862 double r = (
double)imageSize.x / imageSize.y;
904 DEBUG_WARN(
"Focal length calculations only supported with rectilinear and fisheye images");
912 double d =
sqrt(36.0*36.0 + 24.0*24.0) / crop;
913 double r = (
double)imageSize.x / imageSize.y;
949 DEBUG_WARN(
"Focal length calculations only supported with rectilinear and fisheye images");
957 double r = (
double)imageSize.x / imageSize.y;
979 DEBUG_WARN(
"Focal length calculations only supported with rectilinear and fisheye images");
984 return sqrt(36.0*36.0 + 24.0*24.0) /
diag;
1051 return !
m_Masks.getData().empty();
1059 for(
unsigned int i=0;
i<masks.size();
i++)
1061 if(masks[
i].isPositive())
1077 if(!
m_Masks.getData().empty())
1078 for(
unsigned int i=0;
i<
m_Masks.getData().size();
i++)
1084 if(index<
m_Masks.getData().size())
1094 if(index<
m_Masks.getData().size())
options getSize().area()) int wxCALLBACK SortFieldOfViewAscending(wxIntPtr item1
helper functions to work with Exif data via the exiv2 library
Convenience functions for SrcPanoImage to use on the image variables.
class to access Hugins camera and lens database
Base class containing all the variables, but missing some of the other important functions and with s...
bool operator==(const BaseSrcPanoImage &other) const
Check that the variables match.
static LensDB & GetSingleton()
returns the static LensDB instance
base class, which stores one mask polygon
MaskType
enumeration with type of possible masks
void changeMaskType(unsigned int index, HuginBase::MaskPolygon::MaskType newType)
changes type of mask with index to given newType
bool applyEXIFValues(bool applyEVValue=true)
apply values found in EXIF data to SrcPanoImage class, call readEXIF() before to initialize some valu...
bool checkImageSizeKnown()
check if the image size is known, if try to load the information from the file
bool readDistortionFromDB()
tries to read distortion data from lens database you need to call SrcPanoImage::readEXIF before to fi...
void addMask(MaskPolygon newMask)
add newMask to list of masks
static double calcFocalLength(SrcPanoImage::Projection proj, double hfov, double crop, vigra::Size2D imageSize)
calcualte focal length, given crop factor and hfov
bool hasPositiveMasks() const
returns true, if image has positive masks
hugin_utils::FDiff2D getRadialVigCorrCenter() const
double getVar(const std::string &name) const
bool readVignettingFromDB()
tries to read vignetting data from lens database you need to call SrcPanoImage::readEXIF before to fi...
std::string getDBLensName() const
constructs the lens name for the database it is the lensname if known, for compact cameras it is cons...
void setVar(const std::string &name, double val)
bool getCorrectTCA() const
bool isCircularCrop() const
returns true, if projection requires cicular crop
double calcExifExposureValue()
calculate exposure value
const int getExifDateTime(struct tm *datetime) const
try to convert Exif date time string to struct tm
bool readCropfactorFromDB()
tries to read cropfactor from lens database you need to call SrcPanoImage::readEXIF before to fill so...
int getWidth() const
Get the width of the image in pixels.
hugin_utils::FDiff2D getRadialDistortionCenter() const
bool horizontalWarpNeeded()
bool trustExivOrientation()
Check if Exiv orientation tag can be trusted.
void setSize(vigra::Size2D val)
Set the image size in pixels.
bool hasMasks() const
returns true, if image has masks associated
bool isInside(vigra::Point2D p, bool ignoreMasks=false) const
check if a coordinate is inside the source image
void clearActiveMasks()
clears list of active masks
double getExposure() const
void setCropMode(CropMode val)
Set the crop mode.
void updateFocalLength(double newFocalLength)
updates the focal length, changes the hfov to reflect thew newFocalLength
int getHeight() const
Get the height of the image in pixels.
void setExposure(const double &val)
void updateCropFactor(double focalLength, double newCropFactor)
updates the crop factor, the hfov is calculates so that focal length remains the same
VariableMap getVariableMap() const
Return all the image variables in a variable map.
void addActiveMask(MaskPolygon newMask)
add newMask to list of active masks
void resize(const vigra::Size2D &size, VariableMap *potentialLinkedVars)
"resize" image, adjusts all distortion coefficients for usage with a source image of size size potent...
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 readProjectionFromDB(const bool ignoreFovRectilinear=true)
tries to read projection and crop area from lens database you need to call SrcPanoImage::readEXIF bef...
bool hasActiveMasks() const
returns true, if image has active masks
bool readEXIF()
try to fill out information about the image, by examining the exif data
static double calcCropFactor(SrcPanoImage::Projection proj, double hfov, double focalLength, vigra::Size2D imageSize)
calculate crop factor, given focal length and hfov
void deleteAllMasks()
delete all masks
void printMaskLines(std::ostream &o, unsigned int newImgNr) const
writes all mask lines to stream, using given image number
bool isInsideMasks(vigra::Point2D p) const
returns true, if point p is inside of one mask polygon
void deleteMask(unsigned int index)
delete mask at index
a variable has a value and a name.
This file specifies what image variables SrcPanoImg should have.
const std::string getExiv2ValueString(Exiv2::ExifData &exifData, Exiv2::ExifData::const_iterator it)
bool getExiv2GPSLongitude(Exiv2::ExifData &exifData, double &longitude)
const double getCropFactor(Exiv2::ExifData &exifData, long width, long height)
bool getExiv2GPSLatitude(Exiv2::ExifData &exifData, double &latitude)
const double getExiv2ValueDouble(Exiv2::ExifData &exifData, Exiv2::ExifData::const_iterator it)
const long getExiv2ValueLong(Exiv2::ExifData &exifData, Exiv2::ExifData::const_iterator it)
const std::string getLensName(Exiv2::ExifData &exifData)
bool readRedBlueBalance(Exiv2::ExifData &exifData, double &redBalance, double &blueBalance)
mainly consists of wrapper around the pano tools library, to assist in ressource management and to pr...
std::vector< MaskPolygon > MaskPolygonVector
bool isFisheye(const BaseSrcPanoImage::Projection &proj)
std::map< std::string, Variable > VariableMap
std::map< std::string, std::string > FileMetaData
typedef for general map for storing metadata in files
bool StringContainsCaseInsensitive(const std::string &s1, const std::string &s2)
check if s1 contains s2 using case insensitive comparison
TDiff2D< double > FDiff2D
std::string doubleToString(double d, int digits)
convert a double to a string, suitable for display within a GUI.
std::string tolower(const std::string &s)
convert a string to lowercase
bool stringToDouble(const STR &str_, double &dest)
convert a string to a double, ignore localisation.
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.