asmaloney/libE57Format

Writting Images from openCV Mat [SOLVED]

dagata-mining opened this issue · 2 comments

Hi,
So I was trying write cv:Mat image to the .e57 format. I'm posting this so if you guys come across that, you'll have a way out. Don't know if its the best possible way but it worked.

Here's the Solution:

   //Create Writer Object
    e57::Writer eWriter((e57::ustring(filePath)));
    // Get Your Image
    cv::Mat MyImage;
    
    // Write it to a std::vector buffer
    std::vector<uchar> buf;
    cv::imencode(".jpg",image, buf);
    
    // Get Buffer length
    size_t length= buf.length;
    
    // Prepare your header
    e57::Image2D imageHeader;
    imageHeader.name = "myImage";
    imageHeader.pinholeRepresentation.jpegImageSize = length;
    // and more...
    
    // Creating the index header
    int64_t imageIndexHeader;
    imageIndexHeader = eWriter.NewImage2D(imageHeader);
    
    // Transform to a buffer
    char * imgBuffer = new char[length];
    for (size_t j = 0; j < length; j++)
    {
        imgBuffer[j] = buf[j];
    }
    
    // Write2DImage - !! If you were previously writing 3DScanData in the same Writer object
    //                !!  make sure that you .close() the  CompressedVectorWriter object before  
    eWriter.WriteImage2DData(imageIndexHeader, e57::E57_JPEG_IMAGE, e57::E57_PINHOLE,imgBuffer, 0, length);
    
    // Cleanup
    delete[]  imgBuffer;
    buf.clear();
    eWriter.Close()

Thanks Alexandre.

To add cpp code to markdown, instead of single backquotes, use ```cpp & close with three backquotes like this:

```cpp
[code]
```

This will add syntax highlighting and make it easier to read.