PlusToolkit / ndicapi

A common C API for communicating with NDI Polaris and Aurora devices
MIT License
46 stars 31 forks source link

UnicodeDecodeError when 3 rigid bodies are in view of the Polaris Vicra #46

Open Larbino1 opened 3 months ago

Larbino1 commented 3 months ago

Stracktrace:

Traceback (most recent call last):
  File "/home/daniellarby/camtracking/vicra/VicraJuliaClient.py", line 142, in <module>
    vc.run()
  File "/home/daniellarby/camtracking/vicra/VicraJuliaClient.py", line 49, in run
    port_numbers, timestamps, framenumbers, transforms, quality = self.tracker.get_frame()
  File "/home/daniellarby/.local/lib/python3.8/site-packages/sksurgerynditracker/nditracker.py", line 461, in get_frame
    ndicapy.ndiCommand(self._device, self._capture_string)
UnicodeDecodeError: 'utf-8' codec can't decode byte 0x8b in position 2: invalid start byte

This reliably happens when I move a third rigid body into the view of the Polaris vicra. Otherwise, tracking works perfectly.

I would really appreciate a bit of guidance as to where to look to fix this problem. Am I right that the error is in this repository, ndicapi? Where does ndicapy reside? Is the Error thrown from python or C++ code?

Larbino1 commented 3 months ago

@thompson318

thompson318 commented 3 months ago

This may be a problem with trying to use BX transforms. Have a look at _set_use_bx_transforms in nditracker.py. You can add your devices firmware string to the list at line 169. If that fixes your problem then you should probably transfer this issue to scikit-surgeryndirtracker and create a pull request there.

thompson318 commented 3 months ago

We've seen very similar with other trackers: see https://github.com/SciKit-Surgery/scikit-surgerynditracker/issues/17

lassoan commented 3 months ago

A binary buffer is attempted to be interpreted as utf8 encoded string, but of course not all binary stream is valid utf8. To fix it, replace PyString_AsString in ndicapy.ndiCommand to return a bytes object instead (or maybe a latin1-encoded string would work, too).

Larbino1 commented 3 months ago

A binary buffer is attempted to be interpreted as utf8 encoded string, but of course not all binary stream is valid utf8. To fix it, replace PyString_AsString in ndicapy.ndiCommand to return a bytes object instead (or maybe a latin1-encoded string would work, too).

Thanks for the help - I suspected it would be something like this but couldn't find where it was happening. With your comment I've found where this is in the code, built the code and started trying to make a fix!

I'm looking at using PyBytes_FromString instead of PyUnicode_FromUTF8 where a command is received, but this change results in other errors, which I'm now hunting down.