前一段时间要做基于flicker提供的带有exif信息的照片库给无地理信息的photos进行定位。
大部分exif的库都不是很好用,exiv2 (http://www.exiv2.org) 挺不错。但在windows下编译很烦。
//need Qt4/Qt5 support
#include
#include
#include
using namespace std;
using namespace Exiv2;
QStringList loadFromFile(const char* sfilename)
{
QStringList slist;
slist.clear();
QFile _file(sfilename);
if (!_file.open(QIODevice::ReadOnly))
{
cout<<"open file failed. error."<return slist;
}
QTextStream _in(&_file);
while(!_in.atEnd())
{
QString str = _in.readLine().trimmed();
if(str.isEmpty()) continue;
slist.append(str);
}
cout<<"slist size = "<return slist;
}
int main()
{
Image::AutoPtr image = ImageFactory::open("/Users/Yaoyao/Desktop/IMG_2428.JPG");
if(image.get() == 0)
{
cout<<"read file error."<return -1;
}
image->readMetadata();
ExifData ed = image->exifData();
if(ed.empty())
{
cout<<"ed empty error!"<return -2;
}
//some tag location
cout<"Exif.Image.GPSTag"]<cout<"Exif.GPSInfo.GPSLatitudeRef"]<cout<"Exif.GPSInfo.GPSLatitude"]<cout<"Exif.GPSInfo.GPSLongitudeRef"]<cout<"Exif.GPSInfo.GPSLongitude"]<cout<"Exif.GPSInfo.GPSAltitudeRef"]<cout<"Exif.GPSInfo.GPSAltitude"]<cout<"Exif.GPSInfo.GPSDateStamp"]<//test
QStringList slist = loadFromFile("/Users/Yaoyao/Documents/Code/ReadPhotoExif/ReadPhotoExif/exif_tags.txt");
if(slist.size() == 0)
return -1;
foreach(QString str, slist)
{
try
{
cout<": "<catch (...)
{
//cout<<"[ EXCEPTION !!! ]"<
continue;
}
}
image->clearExifData();
return 1;
}
其中tag标签支持:
http://www.exiv2.org/tags.html
Exif.Image.ProcessingSoftware
Exif.Image.NewSubfileType
Exif.Image.SubfileType
Exif.Image.ImageWidth
Exif.Image.ImageLength
Exif.Image.BitsPerSample
Exif.Image.Compression
Exif.Image.PhotometricInterpretation
Exif.Image.Thresholding
Exif.Image.CellWidth
Exif.Image.CellLength
Exif.Image.FillOrder
Exif.Image.DocumentName
Exif.Image.ImageDescription
Exif.Image.Make
Exif.Image.Model
Exif.Image.StripOffsets
Exif.Image.Orientation
Exif.Image.SamplesPerPixel
Exif.Image.RowsPerStrip
Exif.Image.StripByteCounts
Exif.Image.XResolution
Exif.Image.YResolution
Exif.Image.PlanarConfiguration
Exif.Image.GrayResponseUnit
Exif.Image.GrayResponseCurve
Exif.Image.T4Options
Exif.Image.T6Options
Exif.Image.ResolutionUnit
Exif.Image.PageNumber
Exif.Image.TransferFunction
Exif.Image.Software
Exif.Image.DateTime
Exif.Image.Artist
Exif.Image.HostComputer
Exif.Image.Predictor
Exif.Image.WhitePoint
Exif.Image.PrimaryChromaticities
Exif.Image.ColorMap
Exif.Image.HalftoneHints
Exif.Image.TileWidth
Exif.Image.TileLength
Exif.Image.TileOffsets
Exif.Image.TileByteCounts
Exif.Image.SubIFDs
Exif.Image.InkSet
Exif.Image.InkNames
Exif.Image.NumberOfInks
Exif.Image.DotRange
Exif.Image.TargetPrinter
Exif.Image.ExtraSamples
Exif.Image.SampleFormat
Exif.Image.SMinSampleValue
Exif.Image.SMaxSampleValue
Exif.Image.TransferRange
Exif.Image.ClipPath
Exif.Image.XClipPathUnits
Exif.Image.YClipPathUnits
Exif.Image.Indexed
Exif.Image.JPEGTables
Exif.Image.OPIProxy
Exif.Image.JPEGProc
Exif.Image.JPEGInterchangeFormat
Exif.Image.JPEGInterchangeFormatLength
Exif.Image.JPEGRestartInterval
Exif.Image.JPEGLosslessPredictors
Exif.Image.JPEGPointTransforms
Exif.Image.JPEGQTables
Exif.Image.JPEGDCTables
Exif.Image.JPEGACTables
Exif.Image.YCbCrCoefficients
Exif.Image.YCbCrSubSampling
Exif.Image.YCbCrPositioning
Exif.Image.ReferenceBlackWhite
Exif.Image.XMLPacket
Exif.Image.Rating
Exif.Image.RatingPercent
Exif.Image.ImageID
Exif.Image.CFARepeatPatternDim
Exif.Image.CFAPattern
Exif.Image.BatteryLevel
Exif.Image.Copyright
Exif.Image.ExposureTime
Exif.Image.FNumber
Exif.Image.IPTCNAA
Exif.Image.ImageResources
Exif.Image.ExifTag
Exif.Image.InterColorProfile
Exif.Image.ExposureProgram
Exif.Image.SpectralSensitivity
Exif.Image.GPSTag
Exif.Image.ISOSpeedRatings
Exif.Image.OECF
Exif.Image.Interlace
Exif.Image.TimeZoneOffset
Exif.Image.SelfTimerMode
Exif.Image.DateTimeOriginal
Exif.Image.CompressedBitsPerPixel
Exif.Image.ShutterSpeedValue
Exif.Image.ApertureValue
Exif.Image.BrightnessValue
Exif.Image.ExposureBiasValue
Exif.Image.MaxApertureValue
Exif.Image.SubjectDistance
Exif.Image.MeteringMode
Exif.Image.LightSource
Exif.Image.Flash
Exif.Image.FocalLength
Exif.Image.FlashEnergy
Exif.Image.SpatialFrequencyResponse
Exif.Image.Noise
Exif.Image.FocalPlaneXResolution
Exif.Image.FocalPlaneYResolution
Exif.Image.FocalPlaneResolutionUnit
Exif.Image.ImageNumber
Exif.Image.SecurityClassification
Exif.Image.ImageHistory
Exif.Image.SubjectLocation
Exif.Image.ExposureIndex
Exif.Image.TIFFEPStandardID
Exif.Image.SensingMethod
Exif.Image.XPTitle
Exif.Image.XPComment
Exif.Image.XPAuthor
Exif.Image.XPKeywords
Exif.Image.XPSubject
Exif.Image.PrintImageMatching
Exif.Image.DNGVersion
Exif.Image.DNGBackwardVersion
Exif.Image.UniqueCameraModel
Exif.Image.LocalizedCameraModel
Exif.Image.CFAPlaneColor
Exif.Image.CFALayout
Exif.Image.LinearizationTable
Exif.Image.BlackLevelRepeatDim
Exif.Image.BlackLevel
Exif.Image.BlackLevelDeltaH
Exif.Image.BlackLevelDeltaV
Exif.Image.WhiteLevel
Exif.Image.DefaultScale
Exif.Image.DefaultCropOrigin
Exif.Image.DefaultCropSize
Exif.Image.ColorMatrix1
Exif.Image.ColorMatrix2
Exif.Image.CameraCalibration1
Exif.Image.CameraCalibration2
Exif.Image.ReductionMatrix1
Exif.Image.ReductionMatrix2
Exif.Image.AnalogBalance
Exif.Image.AsShotNeutral
Exif.Image.AsShotWhiteXY
Exif.Image.BaselineExposure
Exif.Image.BaselineNoise
Exif.Image.BaselineSharpness
Exif.Image.BayerGreenSplit
Exif.Image.LinearResponseLimit
Exif.Image.CameraSerialNumber
Exif.Image.LensInfo
Exif.Image.ChromaBlurRadius
Exif.Image.AntiAliasStrength
Exif.Image.ShadowScale
Exif.Image.DNGPrivateData
Exif.Image.MakerNoteSafety
Exif.Image.CalibrationIlluminant1
Exif.Image.CalibrationIlluminant2
Exif.Image.BestQualityScale
Exif.Image.RawDataUniqueID
Exif.Image.OriginalRawFileName
Exif.Image.OriginalRawFileData
Exif.Image.ActiveArea
Exif.Image.MaskedAreas
Exif.Image.AsShotICCProfile
Exif.Image.AsShotPreProfileMatrix
Exif.Image.CurrentICCProfile
Exif.Image.CurrentPreProfileMatrix
Exif.Image.ColorimetricReference
Exif.Image.CameraCalibrationSignature
Exif.Image.ProfileCalibrationSignature
Exif.Image.AsShotProfileName
Exif.Image.NoiseReductionApplied
Exif.Image.ProfileName
Exif.Image.ProfileHueSatMapDims
Exif.Image.ProfileHueSatMapData1
Exif.Image.ProfileHueSatMapData2
Exif.Image.ProfileToneCurve
Exif.Image.ProfileEmbedPolicy
Exif.Image.ProfileCopyright
Exif.Image.ForwardMatrix1
Exif.Image.ForwardMatrix2
Exif.Image.PreviewApplicationName
Exif.Image.PreviewApplicationVersion
Exif.Image.PreviewSettingsName
Exif.Image.PreviewSettingsDigest
Exif.Image.PreviewColorSpace
Exif.Image.PreviewDateTime
Exif.Image.RawImageDigest
Exif.Image.OriginalRawFileDigest
Exif.Image.SubTileBlockSize
Exif.Image.RowInterleaveFactor
Exif.Image.ProfileLookTableDims
Exif.Image.ProfileLookTableData
Exif.Image.OpcodeList1
Exif.Image.OpcodeList2
Exif.Image.OpcodeList3
Exif.Image.NoiseProfile
Exif.Photo.ExposureTime
Exif.Photo.FNumber
Exif.Photo.ExposureProgram
Exif.Photo.SpectralSensitivity
Exif.Photo.ISOSpeedRatings
Exif.Photo.OECF
Exif.Photo.SensitivityType
Exif.Photo.StandardOutputSensitivity
Exif.Photo.RecommendedExposureIndex
Exif.Photo.ISOSpeed
Exif.Photo.ISOSpeedLatitudeyyy
Exif.Photo.ISOSpeedLatitudezzz
Exif.Photo.ExifVersion
Exif.Photo.DateTimeOriginal
Exif.Photo.DateTimeDigitized
Exif.Photo.ComponentsConfiguration
Exif.Photo.CompressedBitsPerPixel
Exif.Photo.ShutterSpeedValue
Exif.Photo.ApertureValue
Exif.Photo.BrightnessValue
Exif.Photo.ExposureBiasValue
Exif.Photo.MaxApertureValue
Exif.Photo.SubjectDistance
Exif.Photo.MeteringMode
Exif.Photo.LightSource
Exif.Photo.Flash
Exif.Photo.FocalLength
Exif.Photo.SubjectArea
Exif.Photo.MakerNote
Exif.Photo.UserComment
Exif.Photo.SubSecTime
Exif.Photo.SubSecTimeOriginal
Exif.Photo.SubSecTimeDigitized
Exif.Photo.FlashpixVersion
Exif.Photo.ColorSpace
Exif.Photo.PixelXDimension
Exif.Photo.PixelYDimension
Exif.Photo.RelatedSoundFile
Exif.Photo.InteroperabilityTag
Exif.Photo.FlashEnergy
Exif.Photo.SpatialFrequencyResponse
Exif.Photo.FocalPlaneXResolution
Exif.Photo.FocalPlaneYResolution
Exif.Photo.FocalPlaneResolutionUnit
Exif.Photo.SubjectLocation
Exif.Photo.ExposureIndex
Exif.Photo.SensingMethod
Exif.Photo.FileSource
Exif.Photo.SceneType
Exif.Photo.CFAPattern
Exif.Photo.CustomRendered
Exif.Photo.ExposureMode
Exif.Photo.WhiteBalance
Exif.Photo.DigitalZoomRatio
Exif.Photo.FocalLengthIn35mmFilm
Exif.Photo.SceneCaptureType
Exif.Photo.GainControl
Exif.Photo.Contrast
Exif.Photo.Saturation
Exif.Photo.Sharpness
Exif.Photo.DeviceSettingDescription
Exif.Photo.SubjectDistanceRange
Exif.Photo.ImageUniqueID
Exif.Photo.CameraOwnerName
Exif.Photo.BodySerialNumber
Exif.Photo.LensSpecification
Exif.Photo.LensMake
Exif.Photo.LensModel
Exif.Photo.LensSerialNumber
Exif.Iop.InteroperabilityIndex
Exif.Iop.InteroperabilityVersion
Exif.Iop.RelatedImageFileFormat
Exif.Iop.RelatedImageWidth
Exif.Iop.RelatedImageLength
Exif.GPSInfo.GPSVersionID
Exif.GPSInfo.GPSLatitudeRef
Exif.GPSInfo.GPSLatitude
Exif.GPSInfo.GPSLongitudeRef
Exif.GPSInfo.GPSLongitude
Exif.GPSInfo.GPSAltitudeRef
Exif.GPSInfo.GPSAltitude
Exif.GPSInfo.GPSTimeStamp
Exif.GPSInfo.GPSSatellites
Exif.GPSInfo.GPSStatus
Exif.GPSInfo.GPSMeasureMode
Exif.GPSInfo.GPSDOP
Exif.GPSInfo.GPSSpeedRef
Exif.GPSInfo.GPSSpeed
Exif.GPSInfo.GPSTrackRef
Exif.GPSInfo.GPSTrack
Exif.GPSInfo.GPSImgDirectionRef
Exif.GPSInfo.GPSImgDirection
Exif.GPSInfo.GPSMapDatum
Exif.GPSInfo.GPSDestLatitudeRef
Exif.GPSInfo.GPSDestLatitude
Exif.GPSInfo.GPSDestLongitudeRef
Exif.GPSInfo.GPSDestLongitude
Exif.GPSInfo.GPSDestBearingRef
Exif.GPSInfo.GPSDestBearing
Exif.GPSInfo.GPSDestDistanceRef
Exif.GPSInfo.GPSDestDistance
Exif.GPSInfo.GPSProcessingMethod
Exif.GPSInfo.GPSAreaInformation
Exif.GPSInfo.GPSDateStamp
Exif.GPSInfo.GPSDifferential