Skip to content

Commit

Permalink
Add easyexif library and unit test. openMVG#134
Browse files Browse the repository at this point in the history
  • Loading branch information
pmoulon committed May 28, 2014
1 parent 2ed318a commit 7504ee3
Show file tree
Hide file tree
Showing 11 changed files with 909 additions and 4 deletions.
2 changes: 1 addition & 1 deletion src/openMVG/exif_IO/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
ADD_DEFINITIONS(-DTHIS_SOURCE_DIR="${CMAKE_CURRENT_SOURCE_DIR}")
UNIT_TEST(openMVG exif_IO "${EXIV2_LIBRARIES};OpenExif;stlplus")
UNIT_TEST(openMVG exif_IO "${EXIV2_LIBRARIES};OpenExif;easyexif;stlplus")
140 changes: 140 additions & 0 deletions src/openMVG/exif_IO/exif_IO_EasyExif.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,140 @@
#ifndef EXIF_IO_EASYEXIF_HPP
#define EXIF_IO_EASYEXIF_HPP

#include "exif_IO.hpp"
#include "third_party/easyexif/exif.h"

#include <fstream>
#include <string>
#include <sstream>

class Exif_IO_EasyExif : public Exif_IO
{
public:
Exif_IO_EasyExif()
{
}

Exif_IO_EasyExif( const std::string & sFileName )
{
open(sFileName);
}

bool open( const std::string & sFileName )
{
// Read the file into a buffer
FILE *fp = fopen(sFileName.c_str(), "rb");
if (!fp) {
return false;
}
fseek(fp, 0, SEEK_END);
unsigned long fsize = ftell(fp);
rewind(fp);
std::vector<unsigned char> buf(fsize);
if (fread(&buf[0], 1, fsize, fp) != fsize) {
return false;
}
fclose(fp);

// Parse EXIF
int code = exifInfo_.parseFrom(&buf[0], fsize);
if (code)
bHaveExifInfo_ = false;
else
bHaveExifInfo_ = true;

return bHaveExifInfo_;
}

size_t getWidth() const
{
return exifInfo_.ImageWidth;
}

size_t getHeight() const
{
return exifInfo_.ImageHeight;
}

float getFocal() const
{
return static_cast<float>(exifInfo_.FocalLength);
}

std::string getBrand() const
{
std::string sbrand = exifInfo_.Make;
// remove leading and trailing spaces
sbrand.erase(0, sbrand.find_first_not_of(' '));
sbrand.erase(sbrand.find_last_not_of(' '));
return sbrand;
}

std::string getModel() const
{
std::string smodel = exifInfo_.Model;
// remove leading and trailing spaces
smodel.erase(0, smodel.find_first_not_of(' '));
smodel.erase(smodel.find_last_not_of(' '));
return smodel;
}

std::string getLensModel() const
{
return "";
}

/**Verify if the file has metadata*/
bool doesHaveExifInfo() const
{
return bHaveExifInfo_;
}

/** Print all data*/
std::string allExifData() const
{
std::ostringstream os;
os
<< "Camera make : " << exifInfo_.Make
<< "Camera model : " << exifInfo_.Model
<< "Software : " << exifInfo_.Software
<< "Bits per sample : " << exifInfo_.BitsPerSample
<< "Image width : " << exifInfo_.ImageWidth
<< "Image height : " << exifInfo_.ImageHeight
<< "Image description : " << exifInfo_.ImageDescription
<< "Image orientation : " << exifInfo_.Orientation
<< "Image copyright : " << exifInfo_.Copyright
<< "Image date/time : " << exifInfo_.DateTime
<< "Original date/time: " << exifInfo_.DateTimeOriginal
<< "Digitize date/time: " << exifInfo_.DateTimeDigitized
<< "Subsecond time : " << exifInfo_.SubSecTimeOriginal
<< "Exposure time : 1/time " << (unsigned) (1.0/exifInfo_.ExposureTime)
<< "F-stop : " << exifInfo_.FNumber
<< "ISO speed : " << exifInfo_.ISOSpeedRatings
<< "Subject distance : " << exifInfo_.SubjectDistance
<< "Exposure bias : EV" << exifInfo_.ExposureBiasValue
<< "Flash used? : " << exifInfo_.Flash
<< "Metering mode : " << exifInfo_.MeteringMode
<< "Lens focal length : mm\n" << exifInfo_.FocalLength
<< "35mm focal length : mm\n" << exifInfo_.FocalLengthIn35mm
<< "GPS Latitude : deg ( deg, min, sec )\n" << "("
<< exifInfo_.GeoLocation.Latitude << ", "
<< exifInfo_.GeoLocation.LatComponents.degrees << ", "
<< exifInfo_.GeoLocation.LatComponents.minutes << ", "
<< exifInfo_.GeoLocation.LatComponents.seconds << ", "
<< exifInfo_.GeoLocation.LatComponents.direction << ")"
<< "GPS Longitude : deg ( deg, min, sec )\n" << "("
<< exifInfo_.GeoLocation.Longitude << ", "
<< exifInfo_.GeoLocation.LonComponents.degrees << ", "
<< exifInfo_.GeoLocation.LonComponents.minutes << ", "
<< exifInfo_.GeoLocation.LonComponents.seconds << ", "
<< exifInfo_.GeoLocation.LonComponents.direction << ")"
<< "GPS Altitude : m" << exifInfo_.GeoLocation.Altitude;
return os.str();
}

private:
EXIFInfo exifInfo_;
bool bHaveExifInfo_;
};
#endif //EXIF_IO_EASYEXIF_HPP
2 changes: 1 addition & 1 deletion src/openMVG/exif_IO/exif_IO_Exiv2.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ class Exif_IO_Exiv2 : public Exif_IO
image = Exiv2::ImageFactory::open( sFileName.c_str() );
Exiv2::IptcData &iptcData = image->iptcData();
if (!iptcData.empty())
isOpen = true;
isOpen = true;

image->readMetadata();
return isOpen;
Expand Down
21 changes: 19 additions & 2 deletions src/openMVG/exif_IO/exif_IO_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#include "exif_IO_Exiv2.hpp"
#endif
#include "exif_IO_openExif.hpp"
#include "exif_IO_EasyExif.hpp"

#include "testing/testing.h"
#include "third_party/stlplus3/filesystemSimplified/file_system.hpp"
Expand All @@ -19,7 +20,7 @@ const std::string sImg =
+ "/openMVG_Samples/imageData/Exif_Test/100_7100.JPG";

#ifdef USE_EXIV2
TEST(Matching, Exif_IO_Exiv2_ReadDatas)
TEST(Matching, Exif_IO_Exiv2_ReadData)
{
std::auto_ptr<Exif_IO> exif_io (new Exif_IO_Exiv2( sImg ) );

Expand All @@ -37,7 +38,7 @@ TEST(Matching, Exif_IO_Exiv2_ReadDatas)
#endif


TEST(Matching, Exif_IO_openExif_ReadDatas)
TEST(Matching, Exif_IO_openExif_ReadData)
{
std::auto_ptr<Exif_IO> exif_io ( new Exif_IO_OpenExif( sImg ) );

Expand All @@ -53,6 +54,22 @@ TEST(Matching, Exif_IO_openExif_ReadDatas)
EXPECT_EQ( "", exif_io->getLensModel());
}

TEST(Matching, Exif_IO_easyexif_ReadData)
{
std::auto_ptr<Exif_IO> exif_io ( new Exif_IO_EasyExif( sImg ) );

EXPECT_TRUE( exif_io->doesHaveExifInfo());

EXPECT_EQ( "EASTMAN KODAK COMPANY", exif_io->getBrand());
EXPECT_EQ( "KODAK Z612 ZOOM DIGITAL CAMERA", exif_io->getModel());

EXPECT_EQ( 2832, exif_io->getWidth());
EXPECT_EQ( 2128, exif_io->getHeight());
EXPECT_NEAR( 5.85, exif_io->getFocal(), 1e-2);

EXPECT_EQ( "", exif_io->getLensModel());
}

/* ************************************************************************* */
int main() { TestResult tr; return TestRegistry::runAllTests(tr);}
/* ************************************************************************* */
Expand Down
3 changes: 3 additions & 0 deletions src/third_party/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -40,3 +40,6 @@ ADD_SUBDIRECTORY(ceres-solver)
# Add an Approximate Nearest Neighbor library
ADD_SUBDIRECTORY(flann)

# Exif data parsing
ADD_SUBDIRECTORY(easyexif)

5 changes: 5 additions & 0 deletions src/third_party/easyexif/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
PROJECT (easyexif CXX)

CMAKE_MINIMUM_REQUIRED(VERSION 2.8)

ADD_LIBRARY (easyexif exif.h exif.cpp)
9 changes: 9 additions & 0 deletions src/third_party/easyexif/CONTRIBUTORS
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
The following people have contributed patches or issues to EasyEXIF:

Seth Fowler
Val Malykh
Carlos Apablaza Brito
Simon Fuhrmann
Toshiaki Ohkuma
pet.b.hunt
Jason Moey
24 changes: 24 additions & 0 deletions src/third_party/easyexif/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
Copyright (c) 2010 Mayank Lahiri
[email protected]
All rights reserved.

Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:

-- Redistributions of source code must retain the above copyright notice,
this list of conditions and the following disclaimer.
-- Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ``AS IS'' AND ANY EXPRESS
OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN
NO EVENT SHALL THE FREEBSD PROJECT OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

5 changes: 5 additions & 0 deletions src/third_party/easyexif/README.openMVG
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Project: easyexif
URL: https://code.google.com/p/easyexif/
License: New BSD License
Upstream version: version 2.1 https://code.google.com/p/easyexif/source/browse/trunk/

Loading

0 comments on commit 7504ee3

Please sign in to comment.