-
Notifications
You must be signed in to change notification settings - Fork 113
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
Rsdk 2077 write gray16 images to viam depth format #1960
Conversation
There was a problem hiding this 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) |
There was a problem hiding this comment.
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...
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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) { |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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) |
There was a problem hiding this comment.
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.
|
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
|
There was a problem hiding this 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!
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.