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

Convert memory address to Python pointer #1051

Closed
ejmeitz opened this issue Aug 28, 2023 · 3 comments
Closed

Convert memory address to Python pointer #1051

ejmeitz opened this issue Aug 28, 2023 · 3 comments

Comments

@ejmeitz
Copy link

ejmeitz commented Aug 28, 2023

I am using the PySide6 library and end up with a QImage. I would like to get the raw data of this image into a Matrix in Julia and the best approach to do that seems to involve obtaining the pointer to the image in memory and then doing an unsafe_wrap in Julia. However, I have no clue how to get the pointer from Python to a Julia Ptr{T} type. Currently, in Julia I have this object: PyObject <memory at 0x0000016112C022C0> and want a Ptr{Float64}(...)

This is similar to #868 but this should not be a void pointer and it seems that ctypes does not support c_float_p which would be the type of my raw image data. There might be some way to do this with ctypes still but is there any way to do this without an external library? Any help would be appreciated, thanks!

@stevengj
Copy link
Member

How would you do it in Python? If you can figure out how to get a numpy array, then that will give you a Julia array easily.

@stevengj
Copy link
Member

stevengj commented Aug 29, 2023

Closing this issue as it's more of a Python-library usage question than a PyCall issue per se. You might ask about it on Julia Discourse if you can't figure it out.

@ejmeitz
Copy link
Author

ejmeitz commented Aug 29, 2023

Hm didn't think to look at the Python options, been a bit stuck in Julia-land. In case anyone else runs into this you can use the numpy function below to take a pointer in python and get a numpy array.

raw_data = np.ctypeslib.as_array(ptr, shape=(height * width * n_color_channels))

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