naver / kapture

kapture is a file format as well as a set of tools for manipulating datasets, and in particular Visual Localization and Structure from Motion data.
BSD 3-Clause "New" or "Revised" License
466 stars 66 forks source link

Kapture reading trajectory error when rig identifier two characters in size #36

Closed StephenHausler closed 2 years ago

StephenHausler commented 2 years ago

Hi, I've been using Kapture and have encountered a problem where the reading trajectory from file doesn't work when the rig id (also known as device_id) is only two characters or less.

From my debugging, what I've been able to figure out is that when the trajectory and rig files are created, a padding is defined which sets the minimum size of that field. By default, this is 3 elements (line 82 of csv.py). Therefore the new rig id becomes whitespace then the user defined rig id.

The problem is, when re-reading the trajectory file, the table_from_file function (line 195 of csv.py) is removing all whitespace with the strip command (line 214). The intention of strip is to remove the whitespace following the comma in the csv, however the strip command removes all whitespace and also removes the padding whitespace that is now a component of the rig id.

The error occurs when this stripped rig id is compared to the rig id produced by kapture_data.rigs.keys() (line 1487 of csv.py), which has no strip command and returns the rig id as whitespace plus the user defined characters.

I have not been able to figure out a solution, hopefully you are able to find a solution to this problem.

jujumo commented 2 years ago

Hi @StephenHausler ,

Thanks for mentioning this bug. Your analysis is correct, and I was able to reproduce with dummy files AND in debug mode. I made a fix in commit 494ccb081c62b1a56a3e328985cf05097b833bae

Tell me if it works for you.

Regards.

StephenHausler commented 2 years ago

Hi @jujumo, Thanks for your fast response and fix. I've tested your fix on my end, it works perfectly the bug is gone. Cheers