Adding depth units value to frame metadata - #9154
Conversation
| void uvc_sensor::set_depth_units(float value) | ||
| { | ||
| _depth_units = value; | ||
| } |
There was a problem hiding this comment.
Applies to Depth sensor only. Don't put in the base class
Add comment - TODO for refactoring
| } | ||
| } | ||
| depth_units = ((depth_frame*)f.get())->get_units(); | ||
|
|
There was a problem hiding this comment.
@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
| }; | ||
|
|
||
| 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) |
There was a problem hiding this comment.
Retrieve the depth units from the depth frame
| struct md_depth_control | ||
| { | ||
| md_header header; | ||
| uint32_t depth_units; |
There was a problem hiding this comment.
The metadata is part of FW API - remove it
| throw std::runtime_error( "failed to query depth units from sensor" ); | ||
| } | ||
| } | ||
| depth_units = ((depth_frame*)f.get())->get_units(); |
| 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(); |
There was a problem hiding this comment.
Check if the member should be updated instead of local
| 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); |
| 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()); |
There was a problem hiding this comment.
Need to be retrieved using librealsense:: methods only
| 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; | ||
| } | ||
|
|
| 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; |
There was a problem hiding this comment.
Add comment that this is a temporal solution
| float get_frame_depth_units() const override | ||
| { | ||
| return first()->get_frame_depth_units(); | ||
| } |
| 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; |
|
|
||
| auto info = disparity_info::update_info_from_frame(f); | ||
| _depth_units = info.depth_units; | ||
| _depth_units = ((depth_frame*)f.get())->get_units(); |
There was a problem hiding this comment.
Must be performed each iteration - move outside of the profile update clause
|
|
||
| rs2::frame colorizer::process_frame(const rs2::frame_source& source, const rs2::frame& f) | ||
| { | ||
| _depth_units = ((depth_frame*)f.get())->get_units(); |
There was a problem hiding this comment.
Check frame type before dereferencing
| librealsense::depth_stereo_sensor* dss; | ||
| auto info = disparity_info::info(); | ||
| float stereo_baseline_meter; | ||
| info.depth_units = ((depth_frame*)f.get())->get_units(); |
| 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(); |
| 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); |
There was a problem hiding this comment.
Check if can be dropped - no need to explicitly set for T265
There was a problem hiding this comment.
it should stay, the API with default depth_units=-1 is not related to this
ev-mp
left a comment
There was a problem hiding this comment.
The actual dependency injection is not clear yet.
For review
| // 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); | ||
| } | ||
| } |
There was a problem hiding this comment.
The DU injection should occur during the frame construction in uvc_sensor::open( or playback
| // generate additional data | ||
| float depth_units = 0; | ||
| if(_on_frame) | ||
| _on_frame(depth_units);//_additional_data.depth_units; |
There was a problem hiding this comment.
The callback should get the additional_data handle and modify its content
| class option; | ||
|
|
||
| typedef std::function<void(std::vector<platform::stream_profile>)> on_open; | ||
| typedef std::function<void(float &val)> on_frame_md; |
There was a problem hiding this comment.
The function should receive a reference to additional_data and modify its content
| std::atomic<bool> _is_opened; | ||
| std::shared_ptr<notifications_processor> _notifications_processor; | ||
| on_open _on_open; | ||
| on_frame_md _on_frame; |
There was a problem hiding this comment.
Rename to metadata_modifier for clarity
| return action(*_device); | ||
| } | ||
|
|
||
| void update_params(on_frame_md callback) override |
There was a problem hiding this comment.
Probably should be called set_metadata_modifier or similar
| void set_units(float depth_units) | ||
| { | ||
| additional_data.depth_units = depth_units; | ||
| } | ||
|
|
| 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()); |
There was a problem hiding this comment.
Let's review the record/playback mechanims
| stream.next(m.data); | ||
| try | ||
| { | ||
| stream.next(m.depth_units); |
There was a problem hiding this comment.
There is a header that should be used to differentiate according to version number
| 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; |
| { | ||
| _metadata_modifier = callback; | ||
| auto s = get_raw_sensor().get(); | ||
| As< librealsense::uvc_sensor >(s)->modify_frame_metadata(callback); |
There was a problem hiding this comment.
Rename to set_frame_metadata_modifier
| void set_depth_scale(float val) | ||
| { | ||
| _depth_units = val; | ||
| modify_frame_metadata([&](frame_additional_data& data) {data.depth_units = _depth_units.load(); }); |
| _width = vp.width(); _height = vp.height(); | ||
|
|
||
| auto info = disparity_info::update_info_from_frame(f); | ||
| _depth_units = info.depth_units; |
There was a problem hiding this comment.
Remove the field depth_units from disparity_info
| std::string TODO_CORRECT_ME = "0"; | ||
| image.header.frame_id = TODO_CORRECT_ME; | ||
| std::string NEW_ROSBAG = "1"; | ||
| image.header.frame_id = NEW_ROSBAG; |
There was a problem hiding this comment.
Rename to version + comment for maintainers
| 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"; |
| 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()); |
| s << indent << "depth_units: "; | ||
| Printer<float>::stream(s, indent + " ", v.depth_units); |
| } | ||
| s << indent << "depth_units: "; | ||
| Printer<float>::stream(s, indent + " ", v.depth_units); | ||
| if (v.depth_units) |
There was a problem hiding this comment.
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; |
There was a problem hiding this comment.
Provide comment for maintainers
| _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); |
There was a problem hiding this comment.
Check that the extension conversion is not null before dereferencing
| 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 |
There was a problem hiding this comment.
Add comment that the field is unused and therefore assigned for ROSbag versions control
| Printer<uint8_t>::stream(s, indent + " ", v.data[i]); | ||
| } | ||
| if (v.depth_units) | ||
| if (v.depth_units != 0) |
There was a problem hiding this comment.
Use std::numeric_limits<float>::min() as in original comment
Track on DSO-16066