toinsson / pyrealsense

Cross-platform ctypes/Cython wrapper to the librealsense library (v1.x)
http://pyrealsense.readthedocs.io
Apache License 2.0
121 stars 46 forks source link

ValueError: '<P' is not a valid PEP 3118 buffer format string #82

Closed OrganicIrradiation closed 5 years ago

OrganicIrradiation commented 6 years ago
Required Info
Camera Model R200
Firmware Version 1.0.72.04
Operating System & Version Mac OS X 10.13.6 (17G65) & Ubuntu 18.04.1 LTS (GNU/Linux 4.14.55-146 armv7l)
librealsense version legacy branch, compiled from github clone
pyrealsense version 2.2
python version 3.7

Running the example code (on Mac OS X), I get the following error:

INFO:pyrealsense.core:There are 1 connected RealSense devices.
INFO:pyrealsense.core:Using device 0, an Intel RealSense R200
INFO:pyrealsense.core:    Serial number: XXXXXXXXXX
INFO:pyrealsense.core:    Firmware version: 1.0.72.04
Traceback (most recent call last):
  File "test_pyrealsense.py", line 17, in <module>
    print(cam.color)
  File "/Users/user/.virtualenvs/test_pyrealsense/lib/python3.7/site-packages/pyrealsense/core.py", line 518, in <lambda>
    return lambda x: get_stream_data(s)
  File "/Users/user/.virtualenvs/test_pyrealsense/lib/python3.7/site-packages/pyrealsense/core.py", line 512, in get_stream_data
    data = lrs.rs_get_frame_data(self.dev, s.stream, ctypes.byref(e))
  File "_ctypes/callproc.c", line 911, in GetResult
  File "/Users/user/.virtualenvs/test_pyrealsense/lib/python3.7/site-packages/numpy/ctypeslib.py", line 183, in _check_retval_
    return array(self)
ValueError: '<P' is not a valid PEP 3118 buffer format string

I get the same error with Linux.

OrganicIrradiation commented 6 years ago

I thought it might be with using version python 3.7, so I tested with 3.6 in Linux, and got the same error:

INFO:pyrealsense.core:There are 1 connected RealSense devices.
INFO:pyrealsense.core:Using device 0, an Intel RealSense R200
INFO:pyrealsense.core:    Serial number: XXXXXXXXXX
INFO:pyrealsense.core:    Firmware version: 1.0.72.04
Traceback (most recent call last):
  File "test_pyrealsense.py", line 17, in <module>
    print(cam.color)
  File "/usr/local/lib/python3.6/dist-packages/pyrealsense-2.2-py3.6-linux-armv7l.egg/pyrealsense/core.py", line 518, in <lambda>
    return lambda x: get_stream_data(s)
  File "/usr/local/lib/python3.6/dist-packages/pyrealsense-2.2-py3.6-linux-armv7l.egg/pyrealsense/core.py", line 512, in get_stream_data
    data = lrs.rs_get_frame_data(self.dev, s.stream, ctypes.byref(e))
  File "_ctypes/callproc.c", line 918, in GetResult
  File "/usr/local/lib/python3.6/dist-packages/numpy/ctypeslib.py", line 183, in _check_retval_
    return array(self)
ValueError: '<P' is not a valid PEP 3118 buffer format string
OrganicIrradiation commented 6 years ago

Seems like the camera is working fine though using the included examples:

$ cpp-headless 
There are 1 connected RealSense devices.

Using device 0, an Intel RealSense R200
    Serial number: XXXXXXXXXX
    Firmware version: 1.0.72.04
Writing cpp-headless-output-DEPTH.png, 480 x 360 pixels
Writing cpp-headless-output-COLOR.png, 640 x 480 pixels
Writing cpp-headless-output-INFRARED.png, 480 x 360 pixels
Writing cpp-headless-output-INFRARED2.png, 480 x 360 pixels
wrote frames to current working directory.
toinsson commented 6 years ago

I have seen the same error recently too. I'm using conda for my install and doing a re-install did the work for me on python 3.6. I'm still not sure what is the reason : ( If you have some ideas, please post it here.

sebbue commented 6 years ago

I am struggeling with the same issue.

Required Info  
Camera Model ZR300
Firmware Version 2.0.71.28
Operating System & Version Mac OS X 10.13.6 (17G65)
librealsense version legacy branch, compiled from github clone
pyrealsense version 2.2
python version 2.7 and 3.7

The reason for this issue is a byte order / format character: "<P" in the stream. According to section 7.1.2.2 at https://docs.python.org/3/library/struct.html "the 'P' format character is only available for the native byte ordering (selected as the default or with the '@' byte order character). The byte order character '=' chooses to use little- or big-endian ordering based on the host system. The struct module does not interpret this as native ordering, so the 'P' format is not available." However, I have no idea how to overcome this issue.

toinsson commented 6 years ago

I am not really sure what the actual problem is either.

It could be the result of an incompatibility between numpy and ctypes in relations to new commits supporting PEP 3118 buffer protocol. There is little we do in pyrealsense apart from calling rs_get_frame_data and setting restype. I tried some different flags when declaring the ndpointer but that has not solved the issue.

Swtiching back to python 3.6 and numpy 1.13 - again through conda - does remove the issue though.

sebbue commented 6 years ago

Thanks for your help! Indeed, I can confirm that my setup works with old versions of python and numpy, but not with the latest version of numpy: it does work with python 3.6.6 and numpy 1.14.4, but it does NOT work with python 3.6.6 and numpy 1.15.1. The NumPy 1.15.0 Release Notes specify some C-API changes, which might cause the issue.

toinsson commented 6 years ago

Thanks for the additional testing. Found this thread: https://github.com/numpy/numpy/issues/11150 which might be related.

AdamMiltonBarker commented 6 years ago

I am having this on UP2, I downgraded numpy to 1.14.4 and using Python 3.5 (At the minute this is a requirement and do not want to start reinstalling anything) I no longer get the <P error but the camera light (F200) does not come on and captured frames are black. R200 does not work still loads of errors, attempting to get F200 fixed at the moment but now I have no errors/warnings and stumped lol.

JL2718 commented 6 years ago

conda install numpy=1.14.6

eric-wieser commented 5 years ago

This is an upstream bug

eric-wieser commented 5 years ago

This should be fixed upstream - can this issue be closed?