Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix GetDistance() issue for SoftwareDevice in C# #12193

Conversation

hsuys
Copy link
Contributor

@hsuys hsuys commented Sep 13, 2023

Fix GetDistance() issue for SoftwareDevice in C#

changes:
add depth_units field to type SoftwareVideoFrame and class AddVideoFrame

Tracked on: [DSO-19246]
Original issue: #12170

@Nir-Az Nir-Az requested a review from maloel September 14, 2023 04:18
@Nir-Az
Copy link
Collaborator

Nir-Az commented Sep 14, 2023

Thanks @hsuys .
@maloel can you help with reviewing this?

I don't know this deeply but the SW device can handle DEPTH_UNIT option no?

Do we really want to set it on each frame?

@maloel
Copy link
Collaborator

maloel commented Sep 14, 2023

Do we really want to set it on each frame?

My first question when seeing the user's problem was the same:

  • Why not just set the DEPTH_UNITS in their software-sensor??

But:

  • even in Python, our software_video_frame object has no field for depth_units
  • the C++ code assigns the frame's depth-units (which, with a regular camera, comes from metadata) from this field in the structure, per frame
  • the C++ structure for software_video_frame has no initialization for this field; I assume it's initialized to 0
  • the code for get_distance() just uses this data in the frame (get_units()), without checking if it's zero

So, IMO, the fix from @hsuys is technically correct: the user should be able to specify the depth-units per frame, as we allow in C++. However, this should be done in Python, too, and the rest of the wrappers.

Furthermore, I believe the broader issue is: what happens if, like up until now, the user couldn't or didn't set this field? I think the proper thing to do is get the sensor from the frame and query it for DEPTH_UNITS (query_units() is already written but not made use of...) if the frame-specific units are 0.

The latter would also take care of the user's problem, without specific fixes in C# and Python (or other wrappers) -- assuming the user does not need to set the depth-units per frame.

@maloel
Copy link
Collaborator

maloel commented Sep 14, 2023

  • the C++ structure for software_video_frame has no initialization for this field; I assume it's initialized to 0

I wrote a small unit-test and checked:
The field is uninitialized. I get garbage, not 0. That would also explain the user's "bogus number".

@@ -19,7 +19,7 @@ public void AddVideoFrame(SoftwareVideoFrame f)
NativeMethods.rs2_software_sensor_on_video_frame(Handle, f, out error);
}

public void AddVideoFrame<T>(T[] pixels, int stride, int bpp, double timestamp, TimestampDomain domain, int frameNumber, VideoStreamProfile profile)
public void AddVideoFrame<T>(T[] pixels, int stride, int bpp, double timestamp, TimestampDomain domain, int frameNumber, VideoStreamProfile profile, float depthUnits = 0.001f)
Copy link
Collaborator

Choose a reason for hiding this comment

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

I think the default should be 0, not 0.001.
That way, it will check DEPTH_UNITS after I do my own PR.
We cannot assume to know what units the user uses.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done. Default to 0.
Also added and initialized the depth unit when constructing sw depth frame in the software-device tutorial.

@maloel maloel merged commit 273a0b4 into IntelRealSense:development Sep 18, 2023
15 of 16 checks passed
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.

3 participants