Software Archive
Read-only legacy content
17061 Discussions

RealSense R200 testing in Linux attempting to use librealsense and opencv

Lesly_Z_
Beginner
723 Views

hey everyone!

I am new to RealSense tech and I am working now with the R200 in Ubuntu. I had already tested the examples from librealsense but now I want to use the data obtained by the camera and process it using opencv. I found a tutorial about translating from realsense to opencv, but it uses :

PXCImage *pxcImg
PXCImage::ImageData data;
PXCImage::ImageInfo imgInfo
PXCSenseManager *psm

which seem not to be recognized by "librealsense" for Linux.

I would appreciate your collaboration/ideas/clues for this.

 

Thanks!

0 Kudos
5 Replies
samontab
Valued Contributor II
723 Views

You only need to get the raw data from the frame, then you can just create an OpenCV mat object with it.

This should get you started:

First get the raw data

const uint8_t * infrared_frame = reinterpret_cast<const uint8_t *>(dev->get_frame_data(rs::stream::infrared));

And now you can create an OpenCV image with it:

cv::Mat infrared = cv::Mat(480, 640, CV_8UC1, (void*)infrared_frame);

 

0 Kudos
Lesly_Z_
Beginner
723 Views

@samontab thanks for the reply!

 

I also found another example with:

cv::Mat rgb(480, 640, CV_8UC3, (uchar *) dev->get_frame_data(rs::stream::color));

cv::Mat depth16(480, 640, CV_16UC1, (uchar *) dev->get_frame_data(rs::stream::depth));

which seems to work pretty well, but I am a bit surprised for the image quality I got with RGB and DEPTH.  Any way to improve it?

 

Thanks!

0 Kudos
samontab
Valued Contributor II
723 Views

No worries.

Depending on the format and the stream you want to convert, you shall use the corresponding OpenCV mat parameters.

What do you mean by being surprised by the image quality?, is it not being correctly converted? If that's the case, consider also including the image step in the OpenCV mat constructor. Image step is called pitch in RealSense jargon by the way.

If on the other hand, the image is converted correctly, but it looks bad, like grainy, etc, then there are just a few things you could do as the RGB sensor is not stellar in these cameras.

First, make sure that you have enough light in the scene. This is the most important factor. Then, make sure that the exposure is set correctly to have a nice exposed frame. You could try improving image quality by doing HDR, basically merging different exposure levels into a single image. Finally, make sure that the IR emmiter is sending just enough light to properly expose the objects.

0 Kudos
Lesly_Z_
Beginner
723 Views

thanks again @samontab !!!

I will give a check to OpenCV mat parameters.

About the image quality... yup, it looks a bit grainy and unclear. Thanks for the advice I will check about improving it by doing HDR and also checking the IR emmiter.

 

 

0 Kudos
Lesly_Z_
Beginner
723 Views

hi @samontab !

I checked that my best option for I want to test is : rs::stream::color_aligned_to_depth

but I am still looking forward how to save all that data into a cv:Mat ! thanks for any hint!

0 Kudos
Reply