Skip to content

Adding depth units value to frame metadata - #9154

Merged
ev-mp merged 16 commits into
realsenseai:developmentfrom
nohayassin:dso_16066_04
Jun 21, 2021
Merged

Adding depth units value to frame metadata#9154
ev-mp merged 16 commits into
realsenseai:developmentfrom
nohayassin:dso_16066_04

Conversation

@nohayassin

Copy link
Copy Markdown
Contributor

Track on DSO-16066

Comment thread src/sensor.cpp Outdated
Comment on lines +651 to +654
void uvc_sensor::set_depth_units(float value)
{
_depth_units = value;
}

@ev-mp ev-mp Jun 6, 2021

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Applies to Depth sensor only. Don't put in the base class
Add comment - TODO for refactoring

Comment thread src/ds5/ds5-device.cpp Outdated
Comment thread src/proc/colorizer.cpp Outdated
}
}
depth_units = ((depth_frame*)f.get())->get_units();

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Revert the playback sensor

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ev-mp I still think this part is redundant because depth_units is defined the same way regardless to playback condition, but I will add it for you to see

Comment thread src/proc/colorizer.cpp Outdated
};

auto make_value_cropped_frame = [this](const rs2::video_frame& depth, rs2::video_frame rgb)
auto make_value_cropped_frame = [this, depth_units](const rs2::video_frame& depth, rs2::video_frame rgb)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Retrieve the depth units from the depth frame

Comment thread src/metadata.h Outdated
struct md_depth_control
{
md_header header;
uint32_t depth_units;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The metadata is part of FW API - remove it

Comment thread src/proc/colorizer.cpp Outdated
throw std::runtime_error( "failed to query depth units from sensor" );
}
}
depth_units = ((depth_frame*)f.get())->get_units();

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should be checked externally

Comment thread src/proc/pointcloud.cpp Outdated
auto pframe = (librealsense::points*)(res.get());

const float3* points = depth_to_points(res, *_depth_intrinsics, depth, *_depth_units);
auto depth_units = ((depth_frame*)depth.get())->get_units();

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Check if the member should be updated instead of local

Comment thread src/sensor.h Outdated
const unsigned long long& last_frame_number,
std::shared_ptr<stream_profile_interface> profile);
std::shared_ptr<stream_profile_interface> profile,
float depth_units = -1);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

don't use default values

Comment thread src/media/ros/ros_writer.cpp Outdated
image.header.stamp = rs2rosinternal::Time(std::chrono::duration<double>(timestamp_ms).count());
std::string TODO_CORRECT_ME = "0";
image.header.frame_id = TODO_CORRECT_ME;
image.header.depth_units = static_cast<float>(vid_frame->get_frame_depth_units());

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Need to be retrieved using librealsense:: methods only

Comment thread include/librealsense2/hpp/rs_frame.hpp Outdated
Comment on lines +529 to +536
float get_frame_depth_units() const
{
rs2_error* e = nullptr;
auto r = rs2_depth_frame_get_units(frame_ref, &e);
error::handle(e);
return r;
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To remove

Comment thread src/archive.h Outdated
bool is_blocking = false; // when running from recording, this bit indicates
// if the recorder was configured to realtime mode or not
// if true, this will force any queue receiving this frame not to drop it
float depth_units = 0.0f;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add comment that this is a temporal solution

Comment thread src/archive.h Outdated
Comment on lines +264 to +267
float get_frame_depth_units() const override
{
return first()->get_frame_depth_units();
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To remove

Comment thread src/archive.h Outdated
rs2_timestamp_domain get_frame_timestamp_domain() const override;
void set_timestamp(double new_ts) override { additional_data.timestamp = new_ts; }
unsigned long long get_frame_number() const override;
float get_frame_depth_units() const override;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To remove

Comment thread src/gl/colorizer-gl.cpp Outdated

auto info = disparity_info::update_info_from_frame(f);
_depth_units = info.depth_units;
_depth_units = ((depth_frame*)f.get())->get_units();

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Must be performed each iteration - move outside of the profile update clause

Comment thread src/proc/colorizer.cpp Outdated

rs2::frame colorizer::process_frame(const rs2::frame_source& source, const rs2::frame& f)
{
_depth_units = ((depth_frame*)f.get())->get_units();

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Check frame type before dereferencing

Comment thread src/proc/disparity-transform.h Outdated
librealsense::depth_stereo_sensor* dss;
auto info = disparity_info::info();
float stereo_baseline_meter;
info.depth_units = ((depth_frame*)f.get())->get_units();

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Verify frame's type is depth

Comment thread src/proc/synthetic-stream.cpp Outdated
data.metadata_size = 0;
data.system_time = _actual_source.get_time();
data.is_blocking = original->is_blocking();
data.depth_units = original->get_frame_depth_units();

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please check if required

Comment thread src/tm2/tm-device.cpp
frame_md.arrival_ts = duration_cast<std::chrono::nanoseconds>(ts.arrival_ts).count();

frame_additional_data additional_data(ts.device_ts.count(), frame_num++, ts.arrival_ts.count(), sizeof(frame_md), (uint8_t*)&frame_md, ts.global_ts.count(), 0, 0, false);
frame_additional_data additional_data(ts.device_ts.count(), frame_num++, ts.arrival_ts.count(), sizeof(frame_md), (uint8_t*)&frame_md, ts.global_ts.count(), 0, 0, false, 0.0);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Check if can be dropped - no need to explicitly set for T265

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it should stay, the API with default depth_units=-1 is not related to this

@ev-mp ev-mp left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The actual dependency injection is not clear yet.
For review

Comment thread src/proc/synthetic-stream.cpp Outdated
Comment on lines +75 to +86
// For old playback sensors
if (!((depth_frame*)f.get())->get_units())
{
auto snr = ((frame_interface*)f.get())->get_sensor().get();
auto depth_sensor = As< librealsense::depth_sensor >(snr);
auto extendable = As< librealsense::extendable_interface >(snr);
if (extendable && extendable->extend_to(TypeToExtension< librealsense::depth_sensor >::value, (void**)(&depth_sensor)))
{
auto du = depth_sensor->get_depth_scale();
((depth_frame*)f.get())->set_units(du);
}
}

@ev-mp ev-mp Jun 14, 2021

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The DU injection should occur during the frame construction in uvc_sensor::open( or playback

Comment thread src/sensor.cpp Outdated
// generate additional data
float depth_units = 0;
if(_on_frame)
_on_frame(depth_units);//_additional_data.depth_units;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The callback should get the additional_data handle and modify its content

Comment thread src/sensor.h Outdated
class option;

typedef std::function<void(std::vector<platform::stream_profile>)> on_open;
typedef std::function<void(float &val)> on_frame_md;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The function should receive a reference to additional_data and modify its content

Comment thread src/sensor.h Outdated
std::atomic<bool> _is_opened;
std::shared_ptr<notifications_processor> _notifications_processor;
on_open _on_open;
on_frame_md _on_frame;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rename to metadata_modifier for clarity

Comment thread src/sensor.h Outdated
return action(*_device);
}

void update_params(on_frame_md callback) override

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably should be called set_metadata_modifier or similar

Comment thread src/archive.h Outdated
Comment on lines +342 to +346
void set_units(float depth_units)
{
additional_data.depth_units = depth_units;
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't be needed

Comment thread src/media/ros/ros_writer.cpp Outdated
std::string TODO_CORRECT_ME = "0";
image.header.frame_id = TODO_CORRECT_ME;
image.header.depth_units = static_cast<float>(((depth_frame*)vid_frame)->get_units());
image.depth_units = static_cast<float>(((depth_frame*)vid_frame)->get_units());

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's review the record/playback mechanims

stream.next(m.data);
try
{
stream.next(m.depth_units);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is a header that should be used to differentiate according to version number

Comment thread tools/rosbag-inspector/print_helpers.h Outdated
os << "Width : " << image->width << std::endl;
os << "Height : " << image->height << std::endl;
os << "Step : " << image->step << std::endl;
//os << "Frame Number : " << image->header.seq << std::endl;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove the comment

Comment thread src/ds5/ds5-device.cpp Outdated
{
_metadata_modifier = callback;
auto s = get_raw_sensor().get();
As< librealsense::uvc_sensor >(s)->modify_frame_metadata(callback);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rename to set_frame_metadata_modifier

Comment thread src/ds5/ds5-device.cpp Outdated
void set_depth_scale(float val)
{
_depth_units = val;
modify_frame_metadata([&](frame_additional_data& data) {data.depth_units = _depth_units.load(); });

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Check _depth_units lifetime

Comment thread src/gl/colorizer-gl.cpp
_width = vp.width(); _height = vp.height();

auto info = disparity_info::update_info_from_frame(f);
_depth_units = info.depth_units;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove the field depth_units from disparity_info

Comment thread src/media/ros/ros_writer.cpp Outdated
std::string TODO_CORRECT_ME = "0";
image.header.frame_id = TODO_CORRECT_ME;
std::string NEW_ROSBAG = "1";
image.header.frame_id = NEW_ROSBAG;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rename to version + comment for maintainers

Comment thread src/media/ros/ros_writer.cpp Outdated
image.header.stamp = rs2rosinternal::Time(std::chrono::duration<double>(timestamp_ms).count());
std::string TODO_CORRECT_ME = "0";
image.header.frame_id = TODO_CORRECT_ME;
std::string NEW_ROSBAG = "1";

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No need for it

Comment thread src/media/ros/ros_writer.cpp Outdated
image.header.frame_id = TODO_CORRECT_ME;
std::string NEW_ROSBAG = "1";
image.header.frame_id = NEW_ROSBAG;
image.depth_units = static_cast<float>(((depth_frame*)vid_frame)->get_units());

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Must be dynamically checked

Comment on lines +284 to +285
s << indent << "depth_units: ";
Printer<float>::stream(s, indent + " ", v.depth_units);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Print only for depth frame

}
s << indent << "depth_units: ";
Printer<float>::stream(s, indent + " ", v.depth_units);
if (v.depth_units)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Check for floating_point != zero explicitly using numeric_limits


typedef std::basic_string<char, std::char_traits<char>, typename ContainerAllocator::template rebind<char>::other > _frame_id_type;
_frame_id_type frame_id;
_frame_id_type version;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Provide comment for maintainers

Comment thread src/ds5/ds5-device.cpp Outdated
_metadata_modifier = callback;
auto s = get_raw_sensor().get();
As< librealsense::uvc_sensor >(s)->modify_frame_metadata(callback);
As< librealsense::uvc_sensor >(s)->set_frame_metadata_modifier(callback);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Check that the extension conversion is not null before dereferencing

Comment thread src/media/ros/ros_writer.cpp Outdated
imu_msg.header.stamp = rs2rosinternal::Time(std::chrono::duration<double>(timestamp_ms).count());
std::string TODO_CORRECT_ME = "0";
imu_msg.header.frame_id = TODO_CORRECT_ME;
imu_msg.header.version = "1"; // used to distinguish between old rosbag and new rosbag that contains depth units in frame metadata

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add comment that the field is unused and therefore assigned for ROSbag versions control

@ev-mp ev-mp left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fix the last comment

Printer<uint8_t>::stream(s, indent + " ", v.data[i]);
}
if (v.depth_units)
if (v.depth_units != 0)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use std::numeric_limits<float>::min() as in original comment

@ev-mp
ev-mp merged commit 161cee2 into realsenseai:development Jun 21, 2021
@ev-mp ev-mp mentioned this pull request Jun 23, 2021
@ev-mp ev-mp mentioned this pull request Jul 24, 2021
@maloel maloel mentioned this pull request Jul 26, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants