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 2077 write gray16 images to viam depth format #1960

Merged

Conversation

bhaney
Copy link
Member

@bhaney bhaney commented Mar 2, 2023

This will allow an *image.Gray16 to be written to an image/vnd.viam.dep as well.
It also speeds up some of the writing to file if you are writing a Viam *DepthMap.

This also changes the form a vnd.viam.dep file. Before, each depth value was given 8 bytes of space to put in 2 bytes of depth info. The new way of encoding just gives each pixel the necessary 2 bytes. This also allows dumps of data from the DepthMap slices to be written and read faster.

Testing with an intel realsense, and it makes correct point clouds.

@viambot viambot added viam-org Is part of the viamrobotics organization. safe to test This pull request is marked safe to test from a trusted zone labels Mar 2, 2023
@bhaney bhaney requested a review from kharijarrett March 2, 2023 15:37
@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 Mar 2, 2023
@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 Mar 2, 2023
@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 Mar 2, 2023
Copy link
Member

@kharijarrett kharijarrett left a comment

Choose a reason for hiding this comment

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

Love this. Gray16 >> Gray8. Left some comments below but I mostly wanna make sure we still test reading DMs from a file


return setRawDepthMapValues(f, &dm)
// dump the rest of the bytes in a depth slice
datSlice := make([]Depth, dm.height*dm.width)
Copy link
Member

Choose a reason for hiding this comment

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

This seems like a smoother way to do setRawDepthMapValues() except now there's two places with basically the same code chunk. We only use this here and in readDepthMapRaw, so maybe just go ahead and replace the function with this logic? Might mean that the error printout gets slightly less specific though...

Copy link
Member

Choose a reason for hiding this comment

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

Seems like we're just dumping it all out as opposed to reading 8 bytes at a time. Nice. This should also be valid for raw depth maps.

Copy link
Member Author

Choose a reason for hiding this comment

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

Raw Depth maps are actually treated differently:

In the raw depth map function, it is writing the two bytes (uint16) of depth info from the *DepthMap to 8 bytes (uint64) of space in the buffer. These leaves a lot of 0-padding in the files. When reading the Raw Depth file using setRawDepthMapValues, it has to read 8 byte chunks at a time, just to read the 2 bytes of depth to put into the *DepthMap pixel.

This new Viam function, on the other hand, writes out 2 bytes, and reads 2 bytes. So the space the file takes up is smaller, because it doesn't have 6 extra bytes of 0s for every 2 bytes of depth info. This also allows you to just dump the data from the file into a depth slice, without having to parse 8 bytes at a time.

Copy link
Member Author

Choose a reason for hiding this comment

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

I'll put a comment in the file pointing out the difference


// Test values at points of DepthMap
// This example DepthMap (fakeDM) was made such that Depth(x,y) = x*y
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.

I think we lost the "make sure you can read this from a file with the right extension" test and we might wanna keep it. The depth map in artifact/rimage/fakeDM.vnd.viam.dep is just like the one created below from scratch.

Copy link
Member Author

@bhaney bhaney Mar 2, 2023

Choose a reason for hiding this comment

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

This PR changes the way vnd.viam.dep files are written. Each value is not given 8 bytes of space in the file, but only two bytes. This "compression" makes the new file sizes smaller, but also means that the format is different from what it was before.

But yes, I will create a new vnd.viam.dep file without the 8byte padding, and just the 2byte per pixel length.

Copy link
Member Author

@bhaney bhaney Mar 2, 2023

Choose a reason for hiding this comment

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

0000000   D   E   P   T   H   M   A   P 
0000010  024  \0  \0  \0  \0  \0  \0  \0
0000020  \n  \0  \0  \0  \0  \0  \0  \0  
0000030  \0  \0  \0  \0  \0  \0  \0  \0
0000040  \0  \0  \0  \0  \0  \0  \0  \0  
0000050  \0  \0  \0  \0  \0  \0  \0  \0
0000060  \0  \0  \0  \0  \0  \0  \0  \0  
0000070  \0  \0  \0  \0  \0  \0  \0  \0
0000100  \0  \0  \0  \0  \0  \0  \0  \0  
0000110  \0  \0  \0  \0  \0  \0  \0  \0
0000120  \0  \0  \0  \0  \0  \0  \0  \0  
0000130  \0  \0  \0  \0  \0  \0  \0  \0
0000140  \0  \0  \0  \0  \0  \0  \0  \0  
0000150  \0  \0  \0  \0  \0  \0  \0  \0
0000160  001  \0  \0  \0  \0  \0  \0  \0 
0000170  002  \0  \0  \0  \0  \0  \0  \0
0000200  003  \0  \0  \0  \0  \0  \0  \0
0000210  004 \0  \0  \0  \0  \0  \0  \0

Like, here is the byte writeout for artifact/rimage/fakeDM.vnd.viam.dep, where each line is 8 bytes, and the first 3 lines are the DEPTHMAP header, width and height respectively. And then after that, each 8 bytes is one pixel

Copy link
Member Author

@bhaney bhaney Mar 2, 2023

Choose a reason for hiding this comment

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

And here is the new vnd.viam.dep format, which is more compact, which essentially holds 4 pixels worth of data on each line

0000000   D   E   P   T   H   M   A   P 
0000010  024  \0  \0  \0  \0  \0  \0  \0
0000020  \n  \0  \0  \0  \0  \0  \0  \0  
0000030  \0  \0  \0  \0  \0  \0  \0  \0
0000040  \0  \0  \0  \0  \0  \0  \0  \0  
0000050  \0  \0  \0  \0  \0  \0  \0  \0
0000060  \0  \0  \0  \0  \0  \0  \0  \0  
0000070  \0  \0  \0  \0  \0  \0  \0  \0
0000100  \0  \0 001  \0 002  \0 003  \0 
0000110  004  \0 005  \0 006  \0  \a  \0
0000120  \b  \0  \t  \0  \n  \0  \v  \0  
0000130  \f  \0  \r  \0 016  \0 017  \0
0000140  020  \0 021  \0 022  \0 023  \0  
0000150  \0  \0 002  \0 004  \0 006  \0

Copy link
Member Author

Choose a reason for hiding this comment

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

Replaced the fakeDM file in artifact to new more compressed format.

@@ -61,15 +62,16 @@ func ReadDepthMap(r io.Reader) (*DepthMap, error) {
}
switch firstBytes {
case MagicNumIntVersionX: // magic number for VERSIONX
return readDepthMapVersionX(r.(*bufio.Reader))
return readDepthMapVersionX(r)
Copy link
Member

Choose a reason for hiding this comment

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

Yeah this is already a great change just from synchronizing the function signatures to all input a io.Reader. Love this.

@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 Mar 2, 2023
@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 Mar 2, 2023
@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 Mar 2, 2023
@bhaney bhaney requested a review from kharijarrett March 2, 2023 22:52
@github-actions
Copy link
Contributor

github-actions bot commented Mar 2, 2023

Code Coverage

Package Line Rate Delta Health
go.viam.com/rdk/components/arm 60% 0.00%
go.viam.com/rdk/components/arm/universalrobots 42% 0.00%
go.viam.com/rdk/components/arm/xarm 6% 0.00%
go.viam.com/rdk/components/arm/yahboom 6% 0.00%
go.viam.com/rdk/components/audioinput 54% 0.00%
go.viam.com/rdk/components/base 62% 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 75% 0.00%
go.viam.com/rdk/components/board 66% 0.00%
go.viam.com/rdk/components/board/arduino 10% 0.00%
go.viam.com/rdk/components/board/fake 39% 0.00%
go.viam.com/rdk/components/board/genericlinux 34% 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 64% 0.00%
go.viam.com/rdk/components/camera/align 64% 0.00%
go.viam.com/rdk/components/camera/fake 64% 0.00%
go.viam.com/rdk/components/camera/ffmpeg 77% 0.00%
go.viam.com/rdk/components/camera/rtsp 59% 0.00%
go.viam.com/rdk/components/camera/transformpipeline 78% 0.00%
go.viam.com/rdk/components/camera/videosource 34% 0.00%
go.viam.com/rdk/components/encoder 4% 0.00%
go.viam.com/rdk/components/encoder/fake 76% 0.00%
go.viam.com/rdk/components/gantry 59% 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 82% 0.00%
go.viam.com/rdk/components/gripper 67% 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 76% 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 56% 0.00%
go.viam.com/rdk/components/motor/tmcstepper 62% 0.00%
go.viam.com/rdk/components/motor/ulnstepper 52% 0.00%
go.viam.com/rdk/components/movementsensor 75% 0.00%
go.viam.com/rdk/components/movementsensor/cameramono 45% 0.00%
go.viam.com/rdk/components/movementsensor/gpsnmea 37% 0.00%
go.viam.com/rdk/components/movementsensor/gpsrtk 29% 0.00%
go.viam.com/rdk/components/posetracker 84% 0.00%
go.viam.com/rdk/components/sensor 66% 0.00%
go.viam.com/rdk/components/sensor/ultrasonic 31% 0.00%
go.viam.com/rdk/components/servo 66% 0.00%
go.viam.com/rdk/components/servo/gpio 71% 0.00%
go.viam.com/rdk/config 75% 0.00%
go.viam.com/rdk/control 57% 0.00%
go.viam.com/rdk/data 80% +0.92%
go.viam.com/rdk/examples/customresources/demos/complexmodule 0% 0.00%
go.viam.com/rdk/examples/customresources/demos/remoteserver 0% 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/module 65% 0.00%
go.viam.com/rdk/module/modmanager 79% 0.00%
go.viam.com/rdk/motionplan 69% +0.05%
go.viam.com/rdk/operation 82% 0.00%
go.viam.com/rdk/pointcloud 73% 0.00%
go.viam.com/rdk/protoutils 49% 0.00%
go.viam.com/rdk/referenceframe 73% 0.00%
go.viam.com/rdk/registry 89% 0.00%
go.viam.com/rdk/resource 84% 0.00%
go.viam.com/rdk/rimage 78% +0.02%
go.viam.com/rdk/rimage/depthadapter 94% 0.00%
go.viam.com/rdk/rimage/transform 75% 0.00%
go.viam.com/rdk/rimage/transform/cmd/extrinsic_calibration 67% 0.00%
go.viam.com/rdk/robot 86% -0.91%
go.viam.com/rdk/robot/client 81% 0.00%
go.viam.com/rdk/robot/framesystem 65% 0.00%
go.viam.com/rdk/robot/impl 81% 0.00%
go.viam.com/rdk/robot/packages 78% 0.00%
go.viam.com/rdk/robot/server 55% +0.59%
go.viam.com/rdk/robot/web 62% 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 55% 0.00%
go.viam.com/rdk/services/baseremotecontrol 71% 0.00%
go.viam.com/rdk/services/baseremotecontrol/builtin 81% 0.00%
go.viam.com/rdk/services/datamanager 75% 0.00%
go.viam.com/rdk/services/datamanager/builtin 78% 0.00%
go.viam.com/rdk/services/datamanager/datacapture 74% 0.00%
go.viam.com/rdk/services/datamanager/datasync 0% 0.00%
go.viam.com/rdk/services/motion 60% 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 74% 0.00%
go.viam.com/rdk/services/sensors/builtin 97% 0.00%
go.viam.com/rdk/services/shell 25% 0.00%
go.viam.com/rdk/services/slam 78% 0.00%
go.viam.com/rdk/services/slam/builtin 70% 0.00%
go.viam.com/rdk/services/slam/fake 80% 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 84% 0.00%
go.viam.com/rdk/subtype 92% 0.00%
go.viam.com/rdk/utils 72% +0.18%
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 24% 0.00%
Summary 65% (22185 / 34034) +0.03%

@github-actions
Copy link
Contributor

github-actions bot commented Mar 2, 2023

Warning changing any of the following functions will break code samples on app if an api for these function changes please contact the fleet team

component function
base IsMoving
board GPIOPinByName
camera Properties
motor IsMoving
sensor Readings
servo Position
arm EndPosition
audio MediaProperties
gantry Lengths
gripper IsMoving
input_controller Controls
movement_sensor LinearAcceleration
pose_tracker Poses
motion GetPose
vision DetectorNames

Copy link
Member

@kharijarrett kharijarrett left a comment

Choose a reason for hiding this comment

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

Cool got it. The comments are very helpful. This LGTM!

@bhaney bhaney merged commit dffe30b into viamrobotics:main Mar 3, 2023
biotinker pushed a commit to biotinker/robotcore that referenced this pull request Mar 16, 2023
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 viam-org Is part of the viamrobotics organization.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants