Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

cv::Mat imread to unsigned short*?

I am trying to replace the following function with opencv: (from: https://github.com/stevenlovegrove/Pangolin)

  uint64_t loadDepthFromPath(std::string filepath, pangolin::Image<unsigned short> & depth)
    {

        pangolin::TypedImage depthRaw = pangolin::LoadImage(filepath, pangolin::ImageFileTypePng);

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

        for (unsigned int i = 0; i < 480; i++)
        {
            for (unsigned int j = 0; j < 640; j++)
            {
                depth.RowPtr(i)[j] = depthRaw16(j, i) / 5;
            }
        }

        uint64_t time = getCurrTime();
        return time;
    }

This returns a pangolin::Image<unsigned short>, that is then passed to a function:

initModel(depth.ptr);

where depth.ptr is unsigned short *

I am trying to remove pangolin from this, and use opencv instead.

So I load the same image:

     std::string frame1 = "rgbd_dataset_freiburg1_desk/depth/1305031453.374112.png";

Mat img1;
img1 = imread(frame1, 0);

convert it to unsigned short:

    cv::Mat mat_ushort1(img1.cols,img1.rows, CV_16UC1);
img1.convertTo(mat_ushort1, CV_16UC1);

Then use the pointer to the data to pass to the function:

initModel((unsigned short*)mat_ushort1.data);

The problem is, I see a very different result when I use this method. Where am i going wrong here? How can I replicate the pangolin function with openCv?

thank you.