Community
cancel
Showing results for 
Search instead for 
Did you mean: 
Highlighted
Beginner
10 Views

converting PXCImage to Mat format

Jump to solution

 

   Greeting,

 

 I am working on obstacle detection using realsense, R200 camera and I am having a difficulty of converting PXCImage to a Mat format (OpenCV for further image processing). I used IplImage as an intermediate but i am loosing a lot of information when converting it to mat. i saw this effect (discontinuity on depth image) when i extracted the edge of depth image. what should i do? please anyone, I need help on this issue.

 

 thank you in advance 

0 Kudos

Accepted Solutions
Highlighted
Valued Contributor II
10 Views

Have a look at this video that explains how to get the raw data from an F200, and convert the images into an OpenCV Mat object:

https://www.youtube.com/watch?v=wIkIdjN6Oyw

And here is the conversion shown in the video:

cv::Mat PXCImage2CVMat(PXCImage *pxcImage, PXCImage::PixelFormat format)
{
    PXCImage::ImageData data;
    pxcImage->AcquireAccess(PXCImage::ACCESS_READ, format, &data);

    int width = pxcImage->QueryInfo().width;
    int height = pxcImage->QueryInfo().height;

    if(!format)
        format = pxcImage->QueryInfo().format;

    int type;
    if(format == PXCImage::PIXEL_FORMAT_Y8)
        type = CV_8UC1;
    else if(format == PXCImage::PIXEL_FORMAT_RGB24)
        type = CV_8UC3;
    else if(format == PXCImage::PIXEL_FORMAT_DEPTH_F32)
        type = CV_32FC1;

    cv::Mat ocvImage = cv::Mat(cv::Size(width, height), type, data.planes[0]);

    pxcImage->ReleaseAccess(&data);
    return ocvImage;
}

 

View solution in original post

0 Kudos
3 Replies
Highlighted
Valued Contributor II
11 Views

Have a look at this video that explains how to get the raw data from an F200, and convert the images into an OpenCV Mat object:

https://www.youtube.com/watch?v=wIkIdjN6Oyw

And here is the conversion shown in the video:

cv::Mat PXCImage2CVMat(PXCImage *pxcImage, PXCImage::PixelFormat format)
{
    PXCImage::ImageData data;
    pxcImage->AcquireAccess(PXCImage::ACCESS_READ, format, &data);

    int width = pxcImage->QueryInfo().width;
    int height = pxcImage->QueryInfo().height;

    if(!format)
        format = pxcImage->QueryInfo().format;

    int type;
    if(format == PXCImage::PIXEL_FORMAT_Y8)
        type = CV_8UC1;
    else if(format == PXCImage::PIXEL_FORMAT_RGB24)
        type = CV_8UC3;
    else if(format == PXCImage::PIXEL_FORMAT_DEPTH_F32)
        type = CV_32FC1;

    cv::Mat ocvImage = cv::Mat(cv::Size(width, height), type, data.planes[0]);

    pxcImage->ReleaseAccess(&data);
    return ocvImage;
}

 

View solution in original post

0 Kudos
Highlighted
Beginner
10 Views

 

 i found it very useful.........thanks samontab

0 Kudos
Highlighted
Beginner
10 Views

  

   Greeting,

 i could not visualize how a realsense camera allocate memory to grab an image of PXCImage format. I was wondering if anyone can tell me  about this two things

   1. colorData.pitches[0]

   2. data.planes[0];

 thank you

 

 

  

0 Kudos