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

[RSDK-1109] Add custom Depth MIMEType #1666

Merged
merged 10 commits into from
Jan 6, 2023

Conversation

kharijarrett
Copy link
Member

No description provided.

@kharijarrett kharijarrett added the safe to test This pull request is marked safe to test from a trusted zone label Dec 13, 2022
@viambot viambot added safe to test This pull request is marked safe to test from a trusted zone and removed safe to test This pull request is marked safe to test from a trusted zone labels Dec 13, 2022
@kharijarrett kharijarrett marked this pull request as ready for review December 14, 2022 15:42
@kharijarrett kharijarrett requested a review from bhaney December 14, 2022 15:42
@kharijarrett kharijarrett changed the title Viam depth map [RSDK-1109] Add custom Depth MIMEType Dec 14, 2022
Copy link
Member

@bhaney bhaney left a comment

Choose a reason for hiding this comment

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

I like the way this preserves all of our old formats too! There is essentially one change I would like you to do, which is change the image.Config{} function to just read the first bytes of the new file type, rather than the whole file, so that users can get the config info quick

@@ -331,3 +332,36 @@ func TestDepthColorModel(t *testing.T) {
test.That(t, convGray, test.ShouldHaveSameTypeAs, gray)
test.That(t, convGray.(color.Gray16).Y, test.ShouldEqual, 6168)
}

func TestDepthMapEncoding(t *testing.T) {
Copy link
Member

Choose a reason for hiding this comment

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

Great test! Glad to see it all works as expected

@bhaney bhaney requested a review from tessavitabile December 15, 2022 23:05
Copy link
Contributor

@tessavitabile tessavitabile left a comment

Choose a reason for hiding this comment

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

Nice! Can you remind me of the context for this change? Is it that sending raw depth maps to app/sdks is faster than sending pngs? And are app/sdks all able to understand raw depth maps?

if rawWidth == 6363110499870197078 { // magic number for VERSIONX
return readDepthMapFormat2(f)
switch firstBytes {
case 6363110499870197078: // magic number for VERSIONX
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we use constants for the magic numbers?

Copy link
Member Author

Choose a reason for hiding this comment

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

Yeah on it

@kharijarrett
Copy link
Member Author

Context for the change in general... Right now we use PNGs for depth which is slower than raw but the main thing is that it's less correct. Like, PNG does compression (not a lot but still) and that's not the vibe for depth images. You probably want every pixel of information you're supposed to get

@viambot viambot added safe to test This pull request is marked safe to test from a trusted zone and removed safe to test This pull request is marked safe to test from a trusted zone labels Dec 16, 2022
@viambot viambot added safe to test This pull request is marked safe to test from a trusted zone and removed safe to test This pull request is marked safe to test from a trusted zone labels Dec 16, 2022
@tessavitabile
Copy link
Contributor

Thank you! Are app/sdks all able to understand raw depth maps, or will there need to be changes on that end?

@viambot viambot added safe to test This pull request is marked safe to test from a trusted zone and removed safe to test This pull request is marked safe to test from a trusted zone labels Dec 16, 2022
@kharijarrett
Copy link
Member Author

Uhhh... they kinda don't understand depth maps in general rn. On the app side, we normally use something called "depth_to_pretty" which is a transform that turns the depth image into a color one so ppl can kinda visualize it. On the SDK side rn we'd just spit back out the raw bytes. So probably some changes needed eventually.

@github-actions
Copy link
Contributor

Code Coverage

Package Line Rate Delta Health
go.viam.com/rdk/components/arm 61% 0.00%
go.viam.com/rdk/components/arm/universalrobots 13% 0.00%
go.viam.com/rdk/components/arm/xarm 2% 0.00%
go.viam.com/rdk/components/arm/yahboom 7% 0.00%
go.viam.com/rdk/components/audioinput 55% +0.34%
go.viam.com/rdk/components/base 67% 0.00%
go.viam.com/rdk/components/base/agilex 62% 0.00%
go.viam.com/rdk/components/base/boat 41% 0.00%
go.viam.com/rdk/components/base/wheeled 76% 0.00%
go.viam.com/rdk/components/board 68% 0.00%
go.viam.com/rdk/components/board/arduino 10% 0.00%
go.viam.com/rdk/components/board/commonsysfs 47% 0.00%
go.viam.com/rdk/components/board/fake 38% 0.00%
go.viam.com/rdk/components/board/numato 19% 0.00%
go.viam.com/rdk/components/board/pi 50% 0.00%
go.viam.com/rdk/components/camera 65% 0.00%
go.viam.com/rdk/components/camera/align 63% -0.48%
go.viam.com/rdk/components/camera/fake 67% 0.00%
go.viam.com/rdk/components/camera/ffmpeg 77% 0.00%
go.viam.com/rdk/components/camera/transformpipeline 79% +1.00%
go.viam.com/rdk/components/camera/videosource 50% 0.00%
go.viam.com/rdk/components/encoder/fake 77% 0.00%
go.viam.com/rdk/components/gantry 68% 0.00%
go.viam.com/rdk/components/gantry/multiaxis 84% 0.00%
go.viam.com/rdk/components/gantry/oneaxis 86% 0.00%
go.viam.com/rdk/components/generic 83% 0.00%
go.viam.com/rdk/components/gripper 80% 0.00%
go.viam.com/rdk/components/input 87% 0.00%
go.viam.com/rdk/components/input/gpio 84% 0.00%
go.viam.com/rdk/components/motor 81% 0.00%
go.viam.com/rdk/components/motor/dimensionengineering 63% 0.00%
go.viam.com/rdk/components/motor/dmc4000 69% 0.00%
go.viam.com/rdk/components/motor/fake 57% 0.00%
go.viam.com/rdk/components/motor/gpio 64% 0.00%
go.viam.com/rdk/components/motor/gpiostepper 57% +0.59%
go.viam.com/rdk/components/motor/tmcstepper 62% 0.00%
go.viam.com/rdk/components/movementsensor 75% 0.00%
go.viam.com/rdk/components/movementsensor/cameramono 40% 0.00%
go.viam.com/rdk/components/movementsensor/gpsnmea 37% 0.00%
go.viam.com/rdk/components/movementsensor/gpsrtk 28% 0.00%
go.viam.com/rdk/components/posetracker 86% 0.00%
go.viam.com/rdk/components/sensor 86% 0.00%
go.viam.com/rdk/components/sensor/ultrasonic 34% 0.00%
go.viam.com/rdk/components/servo 78% 0.00%
go.viam.com/rdk/components/servo/gpio 71% 0.00%
go.viam.com/rdk/config 76% +0.07%
go.viam.com/rdk/control 57% 0.00%
go.viam.com/rdk/data 77% 0.00%
go.viam.com/rdk/grpc 25% 0.00%
go.viam.com/rdk/ml 67% 0.00%
go.viam.com/rdk/ml/inference 70% 0.00%
go.viam.com/rdk/motionplan 59% -11.40%
go.viam.com/rdk/octree 98% 0.00%
go.viam.com/rdk/operation 82% 0.00%
go.viam.com/rdk/pointcloud 71% -0.09%
go.viam.com/rdk/protoutils 59% 0.00%
go.viam.com/rdk/referenceframe 70% 0.00%
go.viam.com/rdk/registry 90% 0.00%
go.viam.com/rdk/resource 83% 0.00%
go.viam.com/rdk/rimage 78% -0.44%
go.viam.com/rdk/rimage/depthadapter 94% 0.00%
go.viam.com/rdk/rimage/transform 73% 0.00%
go.viam.com/rdk/rimage/transform/cmd/extrinsic_calibration 67% 0.00%
go.viam.com/rdk/robot 85% 0.00%
go.viam.com/rdk/robot/client 82% 0.00%
go.viam.com/rdk/robot/framesystem 68% 0.00%
go.viam.com/rdk/robot/impl 81% 0.00%
go.viam.com/rdk/robot/server 57% 0.00%
go.viam.com/rdk/robot/web 59% 0.00%
go.viam.com/rdk/robot/web/stream 87% 0.00%
go.viam.com/rdk/services/armremotecontrol 71% 0.00%
go.viam.com/rdk/services/armremotecontrol/builtin 52% 0.00%
go.viam.com/rdk/services/baseremotecontrol 71% 0.00%
go.viam.com/rdk/services/baseremotecontrol/builtin 79% 0.00%
go.viam.com/rdk/services/datamanager 65% 0.00%
go.viam.com/rdk/services/datamanager/builtin 80% 0.00%
go.viam.com/rdk/services/datamanager/datacapture 21% 0.00%
go.viam.com/rdk/services/datamanager/datasync 72% 0.00%
go.viam.com/rdk/services/motion 63% 0.00%
go.viam.com/rdk/services/motion/builtin 88% 0.00%
go.viam.com/rdk/services/navigation 54% 0.00%
go.viam.com/rdk/services/sensors 77% 0.00%
go.viam.com/rdk/services/sensors/builtin 97% 0.00%
go.viam.com/rdk/services/shell 14% 0.00%
go.viam.com/rdk/services/slam 84% 0.00%
go.viam.com/rdk/services/slam/builtin 72% 0.00%
go.viam.com/rdk/services/vision 80% 0.00%
go.viam.com/rdk/services/vision/builtin 74% 0.00%
go.viam.com/rdk/session 97% 0.00%
go.viam.com/rdk/spatialmath 83% 0.00%
go.viam.com/rdk/subtype 96% 0.00%
go.viam.com/rdk/utils 72% 0.00%
go.viam.com/rdk/vision 26% 0.00%
go.viam.com/rdk/vision/chess 80% 0.00%
go.viam.com/rdk/vision/delaunay 87% 0.00%
go.viam.com/rdk/vision/keypoints 92% 0.00%
go.viam.com/rdk/vision/objectdetection 82% 0.00%
go.viam.com/rdk/vision/odometry 60% 0.00%
go.viam.com/rdk/vision/odometry/cmd 0% 0.00%
go.viam.com/rdk/vision/segmentation 49% 0.00%
go.viam.com/rdk/web/server 26% 0.00%
Summary 66% (20332 / 30879) -0.74%

@tessavitabile
Copy link
Contributor

Thanks, that makes sense. I guess I'm still wondering: if we return a custom format, what do we expect people to do with it? Will they be able to use it?

@bhaney
Copy link
Member

bhaney commented Dec 16, 2022

Thanks, that makes sense. I guess I'm still wondering: if we return a custom format, what do we expect people to do with it? Will they be able to use it?

Adding to this comment, given that python PIL does not support 16bit grayscale images (or else you could use this Image Register function to decode the images) is it instead possible to return a uint16 numpy 2D array, or even just a standard 2D list of unint16 values?

@bhaney
Copy link
Member

bhaney commented Dec 16, 2022

Actually, https://pillow.readthedocs.io/en/stable/reference/ImageFile.html you may be able to work around PIL's limitations if the ImageFile methods are flexible enough

@bhaney
Copy link
Member

bhaney commented Jan 3, 2023

Thanks, that makes sense. I guess I'm still wondering: if we return a custom format, what do we expect people to do with it? Will they be able to use it?

To more directly answer this question - the hope is that the end user would not have to interact with the bytes directly, but be given the 2D array of depth info. The custom mime type is mostly that - it just adds the three extra parts at the beggining of the bytes stream, the "DEPTHMAP" name, the height, and the width. But asking a user to decode it themselves is undesireable.

In the Go SDK, it gets decoded to the DepthMap struct, in App in gets converted into a 16bit grayscale image, and in Python they get the raw bytes. Ideally, Python would instead return the 2D array of the depth info.

@tessavitabile
Copy link
Contributor

Thank you for the explanation! Is there a ticket for the python SDK work?

@bhaney
Copy link
Member

bhaney commented Jan 3, 2023

Thank you for the explanation! Is there a ticket for the python SDK work?

No, I can make it soon

@bhaney
Copy link
Member

bhaney commented Jan 3, 2023

Thank you for the explanation! Is there a ticket for the python SDK work?

No, I can make it soon

https://viam.atlassian.net/browse/RSDK-1623

Copy link
Member

@bhaney bhaney left a comment

Choose a reason for hiding this comment

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

There is one fix with creating a descriptive error for if the first bytes are not the magic number.

Once that is fixed, LGTM!

Comment on lines +102 to +103
if err != nil || firstBytes != MagicNumIntViamType {
return image.Config{}, err
Copy link
Member

@bhaney bhaney Jan 6, 2023

Choose a reason for hiding this comment

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

If the first bytes != the Magic Number, create an error message saying that, and return that error. Though- I think that error should never happen, as the RegisterFormat function won't run the function if the magic number doesn't match.

Maybe create a test for that, to make sure the behavior is as expected.

@kharijarrett kharijarrett merged commit 781a156 into viamrobotics:main Jan 6, 2023
@kharijarrett kharijarrett deleted the ViamDepthMap branch January 9, 2023 15:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
safe to test This pull request is marked safe to test from a trusted zone
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants