Comments (2)
My input:
- More performant communication from opencv / numpy.arrays to godot types
- functions that encapsulate creating images or streaming audio files generated in python.
from godot-python.
I know you commented on my related issue for this (#305) but for the sake of completeness, this is how one can currently go about efficiently converting a Matplotlib canvas (a Numpy Array) to a Godot PoolByteArray:
def canvas_to_godot_image(self, canvas):
image = Image()
width = canvas.get_width_height()[1]
height = canvas.get_width_height()[0]
size = width * height * 3
pool_array = PoolByteArray()
pool_array.resize(size)
with pool_array.raw_access() as ptr:
numpy_array = np.ctypeslib.as_array(ctypes.cast(ptr.get_address(), ctypes.POINTER(ctypes.c_uint8)), (size,))
numpy_array[:] = np.frombuffer(canvas.tostring_rgb(), dtype=np.uint8).reshape(canvas.get_width_height()[::-1] + (3,)).flatten()
image.create_from_data(height, width, False, Image.FORMAT_RGB8, pool_array)
return image
As you wrote, it would be great if godot-python could provide this kind of functionality out of the box.
I think there are two ways in which this could be done:
- Define a PoolByteArray constructor specifically to construct from a Numpy Array, or
- Provide a Numpy-specific util class with a function such as
NumpyUtil.numpy_array_to_pool_byte_array(array)
I think the first one would be more comfortable for users since they don't need to know that Numpy Arrays are a special case with a performant conversion method. However, the second one would be better for the godot-python codebase since it doesn't pollute the core codebase with Numpy-specific functionality.
Alternatively (or in addition), I think both options are realizable with compile options specifying whether Numpy-specific functionality should be compiled in or not - that would be another way of keeping things a bit separate.
@touilleMan what are your thoughts?
from godot-python.
Related Issues (20)
- Installing packages only shows "requirement already satisfied " but points to global python installation HOT 2
- Best way to display the texture produced in python on a spatial material HOT 4
- Adding Custom Icons to Classes for Nodes HOT 2
- Weird bug when using pip lib that connects to the external camera. HOT 2
- Test project crashes while loading methods (invalid pointer) HOT 2
- impossible to use wandb. HOT 1
- Build failure
- Cant set shader parameter on custom visual shader
- get_children() not working when Label3D is a child. HOT 1
- Question - Embedded Application HOT 2
- Path incorrect for godot-headers HOT 6
- Pass or return Python instance to/from Godot
- How to access nodes from the tree.
- Segmentation fault while using matplotlib under Linux
- make.py initialization fails
- godot3 export python problem HOT 2
- trying on fedora linux HOT 4
- PythonJIT like LuaJIT.
- GDExtension HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from godot-python.