Project

General

Profile

RE: Opening an OpenCV cv::Mat image using open(buff,lengt... ยป geotag2.cpp

Yogesh Khedar, 09 Jan 2017 09:59

 
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
    // Create a new buffer for jpeg encoded image.
18
    std::vector<uchar> cvbuff;
19
    cv::imencode(".jpg",cvImage,cvbuff, std::vector<int>());
20

    
21
    Exiv2::Image::AutoPtr image = Exiv2::ImageFactory::open(&cvbuff[0], cvbuff.size());
22
    image->readMetadata();
23
    Exiv2::ExifData &exifData = image->exifData();
24
    exifData["Exif.Image.Model"] = "A long model name to make the Exif metadata grow";
25
    image->writeMetadata();
26
    
27
    // 1. Writing to disk
28
    // Create a new file for writing.
29
    FILE * file1 = ::fopen("mm2.jpg", "w");
30
    ::fclose(file1);
31
    // Now open using FileIo for writing.
32
    Exiv2::FileIo file("mm2.jpg");
33
    file.open();
34
    file.write(image->io());
35

    
36
    // 2. Writing to disk
37
    // This works but does not write metatags.
38
    // FILE * file = ::fopen("mm.jpg", "w"); 
39
    //::fwrite(&cvbuff[0], image->io().size(), 1, file); 
40
    //::fclose(file); 
41

    
42
    return 0;
43
}
44
catch (Exiv2::Error& e) {
45
    std::cout << "Caught Exiv2 exception '" << e.what() << "'\n";
46
    return -1;
47
}
48

    
    (1-1/1)