Skip to content

Commit

Permalink
Add OpenExif submodule. And add JPEG Exif data reader openMVG module. o…
Browse files Browse the repository at this point in the history
  • Loading branch information
pmoulon committed Dec 19, 2013
1 parent 60af294 commit 81048bc
Show file tree
Hide file tree
Showing 10 changed files with 550 additions and 3 deletions.
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
[submodule "src/dependencies/glfw"]
path = src/dependencies/glfw
url = git://github.com/elmindreda/glfw.git
[submodule "src/dependencies/OpenExif"]
path = src/dependencies/OpenExif
url = https://github.com/pmoulon/OpenExif.git
25 changes: 22 additions & 3 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,11 @@ PROJECT(openMVG C CXX)
# By default build in Release mode
IF(NOT CMAKE_BUILD_TYPE)
SET(CMAKE_BUILD_TYPE "Release")
ENDIF()
ENDIF(NOT CMAKE_BUILD_TYPE)

#set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -O3 -ffast-math -msse -msse2 -msse3")
IF (WIN32)
ADD_DEFINITIONS(-DNOMINMAX)
ENDIF (WIN32)

# ==============================================================================
# Additional cmake find modules
Expand Down Expand Up @@ -51,13 +53,28 @@ IF (NOT APPLE)
ENDIF (NOT APPLE)

# ==============================================================================
# glfw
# SUBMODULE CONFIGURATION
# ==============================================================================
#- glfw
# ==============================================================================
SET(GLFW_BUILD_EXAMPLES OFF CACHE BOOL "Do not build the GLFW example programs" FORCE)
SET(GLFW_BUILD_TESTS OFF CACHE BOOL "Do not build the GLFW tests programs" FORCE)
ADD_SUBDIRECTORY(dependencies/glfw)
INCLUDE_DIRECTORIES(SYSTEM dependencies/glfw/include)

#- OpenExif
# ==============================================================================
ADD_SUBDIRECTORY(dependencies/OpenExif)

#- EXIV 2
# ==============================================================================
IF (UNIX)
FIND_PACKAGE( Exiv2 QUIET)
IF (EXIV2_FOUND)
ADD_DEFINITIONS(-DUSE_EXIV2)
ENDIF (EXIV2_FOUND)
ENDIF (UNIX)

# ==============================================================================
# Opencv is not used by openMVG but some samples show how to use openCV
# and openMVG simultaneously
Expand All @@ -69,6 +86,8 @@ IF (USE_OPENCV)
SET(OpenCV_DIR "/home/pierre/Documents/Dev_OpenCV/opencv_Build")
ENDIF (USE_OPENCV)



# ==============================================================================
# Enable cmake UNIT TEST framework
# ==============================================================================
Expand Down
1 change: 1 addition & 0 deletions src/dependencies/OpenExif
Submodule OpenExif added at 7f4713
2 changes: 2 additions & 0 deletions src/openMVG/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,5 @@ ADD_SUBDIRECTORY(tracks)

ADD_SUBDIRECTORY(robust_estimation)
ADD_SUBDIRECTORY(bundle_adjustment)

ADD_SUBDIRECTORY(exif_IO)
2 changes: 2 additions & 0 deletions src/openMVG/exif_IO/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
ADD_DEFINITIONS(-DTHIS_SOURCE_DIR="${CMAKE_CURRENT_SOURCE_DIR}")
UNIT_TEST(openMVG exif_IO "${EXIV2_LIBRARIES};OpenExif;stlplus")
32 changes: 32 additions & 0 deletions src/openMVG/exif_IO/exif_IO.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
#ifndef EXIF_IO_HPP
#define EXIF_IO_HPP

#include <string>

class Exif_IO
{
public:
virtual size_t getWidth() const = 0;

virtual size_t getHeight() const = 0;

virtual float getFocal() const = 0;

virtual std::string getBrand() const = 0;

virtual std::string getModel() const = 0;

virtual std::string getLensModel() const = 0;

/** Open the file for checking and parsing */
virtual bool open( const std::string & sFileName ) = 0;

/**Verify if the file has metadata*/
virtual bool doesHaveExifInfo() const = 0;

/** Print all data*/
virtual std::string allExifData() const = 0;

};
#endif //EXIF_IO_HPP

183 changes: 183 additions & 0 deletions src/openMVG/exif_IO/exif_IO_Exiv2.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,183 @@
#ifndef EXIF_IO_EXIV2_HPP
#define EXIF_IO_EXIV2_HPP

#include "exif_IO.hpp"

#include <exiv2/exiv2.hpp>

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

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

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

size_t getWidth() const
{
std::ostringstream oss;
oss << "Exif.Photo.PixelXDimension";
Exiv2::ExifData &exifData = image->exifData();
try
{
std::stringstream ss;
ss << exifData[oss.str()].value().toString();
size_t width;
ss >> width;
return width;
}
catch (Exiv2::AnyError& e)
{
std::cout << "Caught Exiv2 exception '" << e << "'\n";
return -1;
}
}

size_t getHeight() const
{
std::ostringstream oss;
oss << "Exif.Photo.PixelYDimension";
Exiv2::ExifData &exifData = image->exifData();
try
{
std::stringstream ss;
ss << exifData[oss.str()].value().toString();
size_t height;
ss >> height;
return height;
}
catch (Exiv2::AnyError& e)
{
std::cout << "Caught Exiv2 exception '" << e << "'\n";
return -1;
}
}

float getFocal() const
{
std::ostringstream oss;
oss << "Exif.Photo.FocalLength";
Exiv2::ExifData &exifData = image->exifData();
try
{
return exifData[oss.str()].value().toFloat();
}
catch (Exiv2::AnyError& e)
{
std::cout << "Caught Exiv2 exception '" << e << "'\n";
return -1;
}
}

std::string getBrand() const
{
std::ostringstream oss;
oss << "Exif.Image.Make";
Exiv2::ExifData &exifData = image->exifData();
try
{
return exifData[oss.str()].value().toString();
}
catch (Exiv2::AnyError& e)
{
std::cout << "Caught Exiv2 exception '" << e << "'\n";
return "";
}
}

std::string getModel() const
{
std::ostringstream oss;
oss << "Exif.Image.Model";
Exiv2::ExifData &exifData = image->exifData();
try
{
return exifData[oss.str()].value().toString();
}
catch (Exiv2::AnyError& e)
{
std::cout << "Caught Exiv2 exception '" << e << "'\n";
return "";
}
}

std::string getLensModel() const
{
std::ostringstream oss;
oss << "Exif." << getBrand() << ".LensModel";
Exiv2::ExifData &exifData = image->exifData();
try
{
return exifData[oss.str()].value().toString();
}
catch (Exiv2::AnyError& e)
{
std::cout << "Caught Exiv2 exception '" << e << "'\n";
return "";
}
}

/** Open the file for checking and parsing */
bool open( const std::string & sFileName )
{
bool isOpen = false;
image = Exiv2::ImageFactory::open( sFileName.c_str() );
Exiv2::IptcData &iptcData = image->iptcData();
if (!iptcData.empty())
isOpen = true;

image->readMetadata();
return isOpen;
}

/**Verify if the file has metadata*/
bool doesHaveExifInfo() const
{
Exiv2::ExifData &exifData = image->exifData();
return !exifData.empty();
}
/** Print all data*/
std::string allExifData() const
{
try
{
Exiv2::ExifData &exifData = image->exifData();
Exiv2::ExifData::const_iterator end = exifData.end();

std::ostringstream oss;
for (Exiv2::ExifData::const_iterator i = exifData.begin(); i != end; ++i)
{
const char* tn = i->typeName();
oss << std::setw(44) << std::setfill(' ') << std::left
<< i->key() << " "
<< "0x" << std::setw(4) << std::setfill('0') << std::right
<< std::hex << i->tag() << " "
<< std::setw(9) << std::setfill(' ') << std::left
<< (tn ? tn : "Unknown") << " "
<< std::dec << std::setw(3)
<< std::setfill(' ') << std::right
<< i->count() << " "
<< std::dec << i->value()
<< "\n";
}
return oss.str();
}
catch (Exiv2::AnyError& e)
{
std::cout << "Caught Exiv2 exception '" << e << "'\n";
return "";
}
}

private :
Exiv2::Image::AutoPtr image;
};
#endif //EXIF_IO_EXIV2_HPP
Loading

0 comments on commit 81048bc

Please sign in to comment.