代码内容:
# include <iostream>
# include <exiv2/exiv2.hpp>
# include <boost/filesystem.hpp>
std:: string FindXmpKey ( Exiv2:: XmpData & xmpData, const std:: string & key) {
if ( xmpData. findKey ( Exiv2 :: XmpKey ( key) ) != xmpData. end ( ) )
return xmpData[ key] . toString ( ) ;
else
return "" ;
}
void readFilenamesBoost ( std:: vector< std:: string> & filenames, const std:: string & folder) {
boost:: filesystem:: path directory ( folder) ;
boost:: filesystem:: directory_iterator itr ( directory) , end_itr;
std:: string current_file = itr-> path ( ) . string ( ) ;
for ( ; itr != end_itr; ++ itr) {
if ( boost:: filesystem:: is_regular_file ( itr-> path ( ) ) ) {
std:: string filename = itr-> path ( ) . filename ( ) . string ( ) ;
filenames. push_back ( filename) ;
}
}
}
int main ( ) {
std:: string folder = "/home/wanghui/Datasets/edm_big_overlap_50p/" ;
std:: vector< std:: string> filenames;
readFilenamesBoost ( filenames, folder) ;
std:: sort ( filenames. begin ( ) , filenames. end ( ) ) ;
for ( auto & filename: filenames) {
auto image = Exiv2:: ImageFactory :: open ( folder + filename) ;
image-> readMetadata ( ) ;
Exiv2:: ExifData & exifData = image-> exifData ( ) ;
Exiv2:: XmpData & xmp_data = image-> xmpData ( ) ;
std:: cout << "File: " << filename << ", " ;
std:: cout << "REALM.Heading: " << FindXmpKey ( xmp_data, "Xmp.exif.REALM.Heading" ) << std:: endl;
}
}
CMakelists.txt
cmake_minimum_required ( VERSION 3.28 )
project ( readexiv2)
set ( CMAKE_CXX_STANDARD 17 )
list ( APPEND CMAKE_MODULE_PATH ${
CMAKE_CURRENT_SOURCE_DIR} )
find_package ( Boost REQUIRED)
find_package ( Exiv2 REQUIRED)
include_directories ( ${
Exiv2_INCLUDE_DIRS} )
add_executable ( readexiv2 main. cpp)
target_link_libraries ( readexiv2 ${
Exiv2_LIBRARIES} - lboost_system - lboost_filesystem)
FindExiv2.cmake
# - Find the native exiv2 includes and library
#
# This module defines
# EXIV2_INCLUDE_DIR, where to find png. h, etc.
# EXIV2_LIBRARIES, the libraries to link against to use exiv2
# EXIV2_FOUND, If false , do not try to use exiv2
# also defined, but not for general use are
# EXIV2_LIBRARY, where to find the exiv2 library
#== == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == == =&#