Home › Forums › AR Sandbox Forum › KinectUtil not writing intrinsic data file -my fix
- This topic has 5 replies, 2 voices, and was last updated 4 weeks ago by okreylos.
-
AuthorPosts
-
October 13, 2024 at 12:02 pm #2784robboParticipant
Hi Folks,
So I saw that with the latest updates that if you do a fresh PullPackage install that the “KinectUtil getCalib 0” step returns a protocol error and doesn’t write the intrinsic calibration parameters data file which looks like this:Intrinsic camera parameter file /opt/Vrui-12.2/etc/Kinect-4.1/IntrinsicParameters-A00366A18104044A.dat
which means that when you go to try and run ‘Rawkinectviewer’ and start calibrating your box that you’ll get errors and won’t be able to continue.
I’m not very good at coding but I am trying to learn so I took this as an opportunity to learn and see if I could debug it. The TLDR is I updated some code in Camera.cpp source file. If you delete KinectUtil and recompile it with the updated code it should work for you. Here is a pastebin link:
Camera.cpp updated source codeOctober 13, 2024 at 12:36 pm #2785robboParticipantI wrote a reply explaining how I got to this solution but the forum won’t let me reply so I put the text in a pastebin link for anyone that’s interested.
October 17, 2024 at 10:57 am #2792robboParticipantHere is a summary the differences between the original Camera.cpp and the new modified one. It should explain a little more succinctly and technically than my previous reply.
In the original version (../../../src/PullPackage/Camera.cpp), there are two read functions:
void read(int subsection, IO::File& file) void read(IO::File& file)
In the Kinect-4.1 version (../../../src/PullPackage/Kinect-4.1/Kinect/Camera.cpp), there are three read functions:
void read(int subsection, IO::File& file, size_t bytesToRead) void read(int subsection, IO::File& file) void read(IO::File& file)
The new overload in the Kinect-4.1 version
(read(int subsection, IO::File& file, size_t bytesToRead))
allows for more controlled reading of calibration data. It checks the number of bytes read against the bytesToRead parameter, ensuring that it doesn’t read beyond the intended data size. This can prevent buffer overruns and makes the function more robust when dealing with potentially incomplete or corrupted data.This change reflects an improvement in error handling and data safety in the newer Kinect-4.1 version of the code.
October 17, 2024 at 11:00 am #2793robboParticipantI was concerned that the data being passed to the rest of the KinectUtil program to create the Intrinsic parameters file wouldn’t be correct since the handling of that data had changed so I asked it to check and this is what it told me.
After analyzing both Camera.cpp files, I can confirm the differences in the expected number of bytes to read for the calibration parameters:
In the original version (../../../src/PullPackage/Camera.cpp):
calibrationParameterReplySizes[0] = 126
calibrationParameterReplySizes[1] = 16
calibrationParameterReplySizes[2] = 12
calibrationParameterReplySizes[3] = 330 or 342 (depending on the Kinect model)
In the Kinect-4.1 version (../../../src/PullPackage/Kinect-4.1/Kinect/Camera.cpp):The expected sizes are exactly the same as the original version.
The key difference is not in the expected sizes, but in how the reading is handled:The original version reads the entire expected size for each subset without any additional checks.
The Kinect-4.1 version introduces a new read function that takes a bytesToRead parameter, allowing it to handle cases where the actual received data might be less than expected. It checks the number of bytes read against the bytesToRead parameter, ensuring that it doesn’t read beyond the actual data size.
This change in the Kinect-4.1 version makes the code more robust when dealing with potentially incomplete or corrupted data, but it doesn’t change the expected number of bytes to read. Both versions expect to read the same amount of data; the Kinect-4.1 version just handles potential discrepancies more gracefully.
October 25, 2024 at 10:57 am #2799okreylosKeymasterI fixed this problem for real. The issue was a confusion between the units in which reply sizes are returned by the USB library. The USB library returns sizes in bytes, while the higher-level functions in the Kinect package assumed that sizes would be returned in USB words. Hence, the expected sizes didn’t match the actual sizes.
After fixing the underlying issue in Kinect::Camera, KinectUtil getCalib is working again.
I pushed the changes to version 4.2 of the Kinect package and made that the default version pulled by
PullPackage Kinect
In short, the fix is to re-run
PullPackage Kinect
which will insert the corrected package into the existing software stack. -
AuthorPosts
- You must be logged in to reply to this topic.