Items with no label
3335 Discussions

How to convert cv::Mat to rs2::frame ?

ywei11
Beginner
3,304 Views

How to convert cv::Mat to rs2::frame ?

0 Kudos
8 Replies
idata
Employee
1,600 Views

Hello yaowei,

 

 

Thank you for your interest in the Intel RealSense Technology.

 

 

Could you please provide us more details about your project and what you are trying to accomplish? Also, what is the RealSense camera/module that you are using?

 

 

Looking forward to your reply!

 

 

Best regards,

 

Eliza

 

 

ywei11
Beginner
1,600 Views

Thank you for your reply!

I'm using d435 camera in the project.I want to denoise the pointcloud of it,and try to use the post-processing example of realsense sdk filter the depth image which type is cv::Mat .Thank you!

0 Kudos
idata
Employee
1,600 Views

Hello yaowei,

 

 

Thank you for the clarifications!

 

 

Could you please let us know how did you get the pointcloud converted as cv::Mat? The format should be rs2:frame so you shouldn't have this issue working with the post-processing program.

 

 

Looking forward to your reply!

 

 

Best regards,

 

Eliza
0 Kudos
ywei11
Beginner
1,600 Views

Thank you for your replay!

The pointcloud is converted from depth image which get with the ros wrapper which in https://github.com/intel-ros/realsense https://github.com/intel-ros/realsense

0 Kudos
ywei11
Beginner
1,600 Views

In other words, how to use post-processing program in ros?

0 Kudos
idata
Employee
1,600 Views

Hello yaowei,

 

 

Unfortunately, the post-processing wrapper for ROS has not yet been implemented.

 

 

I found a code online that might help you out: https://github.com/johannesburg/uw-realsense

 

Here, 3 out of the 4 filters used on the post-processing application are integrated (temporal, spatial, and hole filling filter). You can use it as a starting point for your project.

 

 

I hope that this information helps you!

 

 

Thank you and best regards,

 

Eliza
0 Kudos
ywei11
Beginner
1,600 Views

There are exampe for the conversion from rs2::frame to cv::Mat, so i think it's possible to convert cv::Mat to rs2::frame

rs2::frameset data = pipe.wait_for_frames();

rs2::frame depth = color_map(data.get_depth_frame());

const int w = depth.as().get_width();

const int h = depth.as().get_height();

cv::Mat image(Size(w, h), CV_8UC3, (void*)depth.get_data(), cv::Mat::AUTO_STEP);

0 Kudos
idata
Employee
1,600 Views

Hello yaowei,

 

 

Thank you for your patience.

 

 

The memory in rs2::frame may be reused by librealsense/UVC. Converting from cv::Mat to rs2::frame (copy pixel array to a object of rs2::frame) is not a good idea.

 

 

Note that when the camera captures images, the uvcvideo driver writes the frame information into the rs2::frame.

 

 

Thank you,

 

Eliza
0 Kudos
Reply