0

I'm working on the Intel's RealSense SDK and I have to convert it into an OpenCV format.

I saw this solution in the forum (Convert a PXCImage into an OpenCV Mat) but for the "PIXEL_FORMAT_YUY2" type doesn't work that code.

Anyone knows how to change it?

Thanks in advance

Community
  • 1
  • 1

1 Answers1

0

I don't know the Intel RealSense SDK as I have only used the librealsense API.

The documentation for the Intel RealSense SDK shoud be here.

I don't know how it works with the SDK but with librealsense you can select directly the appropriate color format (for OpenCV mat it should be bgr8).

If you don't have this option with the SDK, you can see here how librealsense unpack yuy2 format.

Or maybe you can try to copy the data directly to a mat (you will have to figure out the good value for cvDataType and the good value for cvDataWidth) and then use cvtColor() with the appropriate conversion if you want to be able to access to the pixel values as a RGB triplet?

Hope it helps.

Catree
  • 2,477
  • 1
  • 17
  • 24
  • Thanks a lot! Maybe it's a silly question, but I don't know exactly how to install librealsense... I seen some commands for Ubuntu, but I didn't see any tutorial step by step for windows. Could you help me? Thanks in advance! – user7563946 Feb 21 '17 at 10:52
  • `librealsense` is the alternative for platforms other than Windows. For Windows, I think that Intel recommends to use the SDK. You can still build from source `librealsense` with CMake and Visual Studio. You should check the default color format you get with the SDK, maybe it is a format different than `yuy2` and you should be able to convert to `mat bgr` easily. – Catree Feb 21 '17 at 12:29
  • In the Intel SDK de format is PIXEL_FORMAT_YUY2, but I don't know how to do this conversion. I did this: `colorIm->AcquireAccess(PXCImage::ACCESS_READ, PXCImage::PIXEL_FORMAT_YUY2, &frmData);` `image_openCV = Mat(Size(640, 480), CV_8UC3, frmData.planes[0]);` But it doesn't work well, the image is not sort correctly. – user7563946 Feb 21 '17 at 15:06
  • [Here](https://software.intel.com/sites/landingpage/realsense/camera-sdk/v1.1/documentation/html/index.html?acquireaccess_pxcimage.html) you have an example and [here](https://software.intel.com/sites/landingpage/realsense/camera-sdk/v1.1/documentation/html/pixelformat_pxcimage.html) the list of image formats. With `PIXEL_FORMAT_RGB24`, you should be able to get a `mat` image. You will need to swap the red with the blue channel as a `mat` image is in `BGR` format (see `cvtColor` in OpenCV). – Catree Feb 21 '17 at 17:18
  • Thanks a lot! It works for the RGB image! Now I'm trying to do the same thing but with the depth image. I think I've prove all the possible format combinations, but I'm not be able to replicate it. Do you know how to do it? – user7563946 Feb 22 '17 at 10:07
  • Not sure to understand. Maybe this? `sm->EnableStream(PXCCapture::STREAM_TYPE_DEPTH,640,480);` and after `PIXEL_FORMAT_DEPTH` or `PIXEL_FORMAT_DEPTH_RAW`? Anyway, I don't have a Windows platform. – Catree Feb 22 '17 at 10:57