1
|
|
2
|
#include <exiv2/exiv2.hpp>
|
3
|
#include <iostream>
|
4
|
#include <cassert>
|
5
|
#include <opencv2/highgui/highgui.hpp>
|
6
|
#include <opencv2/imgproc/imgproc.hpp>
|
7
|
|
8
|
|
9
|
int main(int argc, char* const argv[])
|
10
|
try {
|
11
|
|
12
|
if (argc != 2) {
|
13
|
std::cout << "Usage: " << argv[0] << " file\n";
|
14
|
return 1;
|
15
|
}
|
16
|
cv::Mat cvImage = cv::imread(argv[1], CV_LOAD_IMAGE_COLOR);
|
17
|
//cv::cvtColor(cvImage, cvImage, CV_BGR2RGB);
|
18
|
|
19
|
//Exiv2::DataBuf buf = Exiv2::readFile(argv[1]);
|
20
|
//Exiv2::Image::AutoPtr image = Exiv2::ImageFactory::open(buf.pData_, buf.size_);
|
21
|
Exiv2::byte * buf = reinterpret_cast<Exiv2::byte *> (cvImage.ptr());
|
22
|
//std::cout << static_cast<void *> (cvImage.ptr()) << std::endl;
|
23
|
//std::cout << static_cast<void *> (buf) << std::endl;
|
24
|
|
25
|
//Exiv2::MemIo memIo(buf, 3921722);
|
26
|
//std::cout << "Image Type is:" << Exiv2::ImageFactory::getType(buf, 3921722) << std::endl;
|
27
|
//std::cout << "Image Type is:" << Exiv2::ImageFactory::getType(argv[1]) << std::endl;
|
28
|
|
29
|
|
30
|
Exiv2::Image::AutoPtr image = Exiv2::ImageFactory::open(buf, 3921722);
|
31
|
image->readMetadata();
|
32
|
Exiv2::ExifData &exifData = image->exifData();
|
33
|
exifData["Exif.Image.Model"] = "A long model name to make the Exif metadata grow";
|
34
|
image->writeMetadata();
|
35
|
Exiv2::FileIo file(argv[1]);
|
36
|
file.open();
|
37
|
file.write(image->io());
|
38
|
|
39
|
return 0;
|
40
|
}
|
41
|
catch (Exiv2::Error& e) {
|
42
|
std::cout << "Caught Exiv2 exception '" << e.what() << "'\n";
|
43
|
return -1;
|
44
|
}
|