Comments (4)
okay after some tinkering ive got some results
current code
from godot import exposed, export
from godot import *
import ctypes
import subprocess
import sys
import cv2
import depthai as dai
import numpy as np
@exposed
class Main(Spatial):
# member variables here, example:
material = export (SpatialMaterial)
texture = ImageTexture()
def frame_to_godot_image(self, frame):
height, width, channels = frame.shape
print(width, height, channels)
image = Image()
size = width * height * channels
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(frame, dtype=np.uint8).reshape(channels,height,width).flatten()
image.create_from_data(height, width, False, Image.FORMAT_RGB8, pool_array)
return image
vid = cv2.VideoCapture(0)
def _ready(self):
print("YEllo")
#if self.material is not None:
# self.material.albedo_texture = self.texture
def _process(self,delta):
ret, bgr = self.vid.read()
frame = cv2.cvtColor(bgr, cv2.COLOR_YUV2RGB)
image = self.frame_to_godot_image(frame)
self.texture.create_from_image(image)
self.material.albedo_texture = self.texture
but now im getting interlaced image with shift to green
ive tried bgr to rgb and various formats but none is changing for the better
from godot-python.
check material and mesh settings: is HDR on? is mirror/repeat on?
from godot-python.
Also IIRC opencv uses some weird format/color ordering, IIRC it's not RGB but YCK or something (yes, not even the standard CMYK)
from godot-python.
well that helped :
from godot import exposed, export
from godot import *
import ctypes
import subprocess
import sys
import cv2
import numpy as np
@exposed
class Main(Spatial):
# member variables here, example:
material = export (SpatialMaterial)
texture = ImageTexture()
vid = cv2.VideoCapture(0)
pool_array = PoolByteArray()
frame, height, width, channels, size = None,None,None,None,None
def frame_to_godot_image(self, frame, height, width, channels, size):
print(width, height, channels)
image = Image()
with self.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(frame, dtype=np.uint8).reshape((height,width)[::-1]+(channels,)).flatten()
image.create_from_data( width, height, False, Image.FORMAT_RGB8, self.pool_array)
return image
def _ready(self):
print("YEllo")
ret, frame = self.vid.read()
self.height, self.width, self.channels = frame.shape
self.size = self.width * self.height * self.channels
self.pool_array.resize(self.size)
#if self.material is not None:
# self.material.albedo_texture = self.texture
def _process(self,delta):
ret, frame = self.vid.read()
image = self.frame_to_godot_image(frame,self.height, self.width, self.channels, self.size)
self.texture.create_from_image(image)
self.material.emission_texture = self.texture
ive simply switched the height and width variables around
from godot-python.
Related Issues (20)
- Installing packages only shows "requirement already satisfied " but points to global python installation HOT 2
- [Godot 4] Better numpy support for image / np.arrays HOT 2
- 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.