Giter Site home page Giter Site logo

Comments (4)

TheBricktop avatar TheBricktop commented on May 27, 2024 2

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

obraz

ive tried bgr to rgb and various formats but none is changing for the better

from godot-python.

Zireael07 avatar Zireael07 commented on May 27, 2024

check material and mesh settings: is HDR on? is mirror/repeat on?

from godot-python.

Zireael07 avatar Zireael07 commented on May 27, 2024

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.

TheBricktop avatar TheBricktop commented on May 27, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.