Skip to content
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

YARP 3.9: compatibility with python 3.12 when handling images #3116

Open
MissingSignal opened this issue Jun 20, 2024 · 4 comments
Open

YARP 3.9: compatibility with python 3.12 when handling images #3116

MissingSignal opened this issue Jun 20, 2024 · 4 comments

Comments

@MissingSignal
Copy link

Describe the bug
Dear support,
I get a segmentation fault when handling images on python 3.12.
In particular something goes wrong when I wrap images with yarp_image.setExternal() .
The same code runs well on python < 3.11 .

To Reproduce
I've experienced the error on my personal code but here's a snippet to reproduce the error.

# Create the array with random data
img_array = numpy.random.uniform(0., 255., (240, 320)).astype(numpy.float32)
 
# Create the yarp image and wrap it around the array  
yarp_image = yarp.ImageFloat()
yarp_image.setExternal(img_array, img_array.shape[1], img_array.shape[0])

Configuration (please complete the following information):

  • OS: Ubuntu 24.04 - MacOS Sonoma 14.5
  • yarp version: latest stable release of YARP 3.9
@traversaro
Copy link
Member

traversaro commented Jun 20, 2024

Interestingly there have been some related issue but for different pairs of Python versions:

Perhaps we are all barking at the wrong tree, and the issue is not the Python version? To have a full picture about the problem, I think it is important to know:

  • Which Python are you using? The one from apt or the one from conda? Are you sure you are recompiling YARP against the correct version of Python you want to use?
  • Which version of numpy are you using? Are you mixing packages installed with conda and/or apt and the one installed by pip? Perhaps it may be helpful to post the output of https://github.com/ami-iit/log-installed-software both in the environment that has Python 3.11 and the one with Python 3.12 .
  • Are you able to reproduce the problem in a clean system, for example in a Docker image? The MWE in this case needs also to include how to install the different versions of Python and how you install YARP in those cases.

@traversaro
Copy link
Member

By the way, #1873 suggests that you should pass img_array.data to setExternal instead of img_array, probably it may be worth to try that.

@traversaro
Copy link
Member

By the way, #1873 suggests that you should pass img_array.data to setExternal instead of img_array, probably it may be worth to try that.

If that works, it may be worth updating the example in

in_buf_image.setExternal(in_buf_array, in_buf_array.shape[1], in_buf_array.shape[0])
.

@MissingSignal
Copy link
Author

Dear Silvio,
thanks for the incredibly fast answer, I'have done some tests and you solved my error !
We need to pass img_array.data to setExternal instead of img_array.
As expected, this way of passing the image seems to be backwards compatible and work with earlier versions of python, I tested 3.11.

For reference I attach a working version of my previous snippet:

# Create the array with random data
img_array = np.random.uniform(0., 255., (240, 320)).astype(np.float32)
 
# Create the yarp image and wrap it around the array  
yarp_image = yarp.ImageFloat()
yarp_image.setExternal(img_array.data, img_array.shape[1], img_array.shape[0])

I was experiencing that error on:

  • A clean installation of Ubuntu 24.04 + source installation of Robobotlogy Superbuild (bindings compiled against its native python 3.12)
  • A virtual env created with conda, here yarp was installed through conda-forge with python 3.12

I does not seem to be dependent on any particular configuration of mine.

P.S: It may be worth updating also the example in icub-tutorials

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants