librealsense icon indicating copy to clipboard operation
librealsense copied to clipboard

Align code source

Open Imel23 opened this issue 7 years ago • 3 comments


Required Info
Camera Model D435
Firmware Version (Open RealSense Viewer --> Click info)
Operating System & Version Ubuntu 18
Kernel Version (Linux Only) (e.g. 4.14.13)
Platform PC
SDK Version { legacy / 2.. }
Language C++
Segment {Robot/Smartphone/VR/AR/others }

Issue Description

<Describe your issue / question / feature request / etc..>

Hello everyone,

I'd like to apply alignment function on a png dataset, I'm wondering if it is this function

void align_images(const rs2_intrinsics& depth_intrin, const rs2_extrinsics& depth_to_other,
       const rs2_intrinsics& other_intrin, GET_DEPTH get_depth, TRANSFER_PIXEL transfer_pixel)

who perform alignment between RGB and depth frames. Thank you in advance.

Imel23 avatar Oct 28 '19 15:10 Imel23

@95ImadEL , the function you referred to is used to aligns the images internally. It is a templated function invoked by external code, so I'm not sure that it is advisable to call this function directly. More probably you'd need to "zoom out" into a higher resolution API, like looking into "rs2::align" class can APIs.

For me the fundamental question is that whether you have all the artifacts required for alignment - i.e. the content of PNG files allows to reproduce the original depth and that you also have the corresponding camera's intrinsic/extrinsic data stored. Follow a similar #2231 for details

ev-mp avatar Oct 29 '19 06:10 ev-mp

Thank you @ev-mp for your reply. In fact, I have depth images 16-bits PNG format with a resolution of 640x480, and camera's intrinsic/extrinsic. I 'd like to get the depth value for an RGB pixel. I found also this function.

static void rs2_project_color_pixel_to_depth_pixel(float to_pixel[2],
    const uint16_t* data, float depth_scale,
    float depth_min, float depth_max,
    const struct rs2_intrinsics* depth_intrin,
    const struct rs2_intrinsics* color_intrin,
    const struct rs2_extrinsics* color_to_depth,
    const struct rs2_extrinsics* depth_to_color,
    const float from_pixel[2])
{

I was wondering if I can use it to align the whole image. Thank you

Imel23 avatar Oct 29 '19 08:10 Imel23

@95ImadEL , The function rs2_project_color_pixel_to_depth_pixel runs CPU-intensive algorithm behind the scenes, so it should be used with prudence, mostly in cases where you need to align only a few points. If you need more than that then I'd recommend to use rs2::align class for that task. The way to do it is to convert the PNG datasets back to SDK's frames using software_device class, then you can use the align class to perform the task for whole frames.

You can lookup relevant discussions for bits of code and samples e.g. #4930, #4740 .

ev-mp avatar Oct 29 '19 16:10 ev-mp