anti
anti

Reputation: 3135

Convert a cv::Mat to a pangolin::Image?

I have an application that takes in pangolin::Image format rgbd images. I would like to send in a cv::Mat. How can I convert a cv::Mat to a pangolin::Image?

(pangolin: https://github.com/stevenlovegrove/Pangolin)

Image header:

https://github.com/stevenlovegrove/Pangolin/blob/master/include/pangolin/image/image.h

currently the format is:

pangolin::ManagedImage<unsigned short> firstData(640, 480);

    pangolin::Image<unsigned short> firstRaw(firstData.w, firstData.h, firstData.pitch, (unsigned short*)firstData.ptr);

where firstRaw is then sent through the application.

If I now have:

cv::Mat frame = cv::imread(filepath,0);

What is the conversion from frame to firstRaw?

I start like this:

int loadDepthFromMat(cv::Mat filepath, pangolin::Image<unsigned short> & depth)
{
    int width = filepath.cols;
    int height = filepath.rows;

    pangolin::ManagedImage<unsigned short> depthRaw(width, height);

    pangolin::Image<unsigned short> depthRaw16((unsigned short*)depthRaw.ptr, depthRaw.w, depthRaw.h, depthRaw.w * sizeof(unsigned short));


//copy data 

}

Thank you.

Upvotes: 1

Views: 772

Answers (1)

Scott Mudge
Scott Mudge

Reputation: 977

So, assuming you have converted your cv::Mat to unsigned short format with the correct pitch (or channels, in OpenCV), you just use memcpy.

(I've renamed your cv::Mat from filepath to mat (why is it called filepath?)):

memcpy((void*)depthRaw16.begin(), (void*)mat.data, mat.total() * mat.elemSize());

Again, be sure your pangolin image has identical dimensions and be sure the cv::Mat is converted to unsigned short.

Upvotes: 3

Related Questions