void remove_background(rs2::video_frame& other_frame, const rs2::depth_frame& depth_frame, float depth_scale, float clipping_dist) { const uint16_t* p_depth_frame = reinterpret_cast<const uint16_t*>(depth_frame.get_data()); uint8_t* p_other_frame = reinterpret_cast<uint8_t*>(const_cast<void*>(other_frame.get_data())); int width = other_frame.get_width(); int height = other_frame.get_height(); int other_bpp = other_frame.get_bytes_per_pixel(); #pragma omp parallel for schedule(dynamic) //Using OpenMP to try to parallelise the loop for (int y = 0; y < height; y++) { auto depth_pixel_index = y * width; for (int x = 0; x < width; x++, ++depth_pixel_index) { // Get the depth value of the current pixel auto pixels_distance = depth_scale * p_depth_frame[depth_pixel_index]; // Check if the depth value is invalid (<=0) or greater than the threashold if (pixels_distance <= 0.f || pixels_distance > clipping_dist) { // Calculate the offset in other frame's buffer to current pixel auto offset = depth_pixel_index * other_bpp; // Set pixel to "background" color (0x999999) std::memset(&p_other_frame[offset], 0x99, other_bpp); } } } }
rs2::frame pointcloud::process_depth_frame(const rs2::frame_source& source, const rs2::depth_frame& depth) { auto res = allocate_points(source, depth); auto pframe = (librealsense::points*)(res.get()); auto depth_data = (const uint16_t*)depth.get_data(); float2* tex_ptr = pframe->get_texture_coordinates(); const float3* points; points = depth_to_points(res, (uint8_t*)pframe->get_vertices(), *_depth_intrinsics, depth_data, *_depth_units); auto vid_frame = depth.as<rs2::video_frame>(); // Pixels calculated in the mapped texture. Used in post-processing filters float2* pixels_ptr = _pixels_map.data(); rs2_intrinsics mapped_intr; rs2_extrinsics extr; bool map_texture = false; { if (_extrinsics && _other_intrinsics) { mapped_intr = *_other_intrinsics; extr = *_extrinsics; map_texture = true; } } if (map_texture) { auto height = vid_frame.get_height(); auto width = vid_frame.get_width(); get_texture_map(res, points, width, height, mapped_intr, extr, tex_ptr, pixels_ptr); if (_occlusion_filter->active()) { _occlusion_filter->process(pframe->get_vertices(), pframe->get_texture_coordinates(), _pixels_map); } } return res; }