From f2958efddc475f1e45f1771816507e76d9d77e78 Mon Sep 17 00:00:00 2001 From: Justin Newberry Date: Thu, 28 Sep 2023 13:33:24 -0700 Subject: [PATCH] rgb only --- metadrive/component/sensors/base_camera.py | 2 +- metadrive/engine/core/image_buffer.py | 8 +++++--- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/metadrive/component/sensors/base_camera.py b/metadrive/component/sensors/base_camera.py index dba7f2d78..574457b98 100644 --- a/metadrive/component/sensors/base_camera.py +++ b/metadrive/component/sensors/base_camera.py @@ -110,7 +110,7 @@ def perceive(self, base_object, clip=True) -> np.ndarray: if self.engine.global_config["rgb_to_grayscale"]: ret = np.dot(ret[..., :3], [0.299, 0.587, 0.114]) if not clip: - return ret.astype(np.uint8) + return ret.astype(np.uint8, copy=False, order="C") else: return ret / 255 diff --git a/metadrive/engine/core/image_buffer.py b/metadrive/engine/core/image_buffer.py index f1697e25e..eeab072a0 100644 --- a/metadrive/engine/core/image_buffer.py +++ b/metadrive/engine/core/image_buffer.py @@ -5,7 +5,7 @@ from typing import Union, List import numpy as np -from panda3d.core import NodePath, Vec3, Vec4, Camera, PNMImage, Shader, RenderState, ShaderAttrib +from panda3d.core import NodePath, Vec3, Vec4, Camera, PNMImage, Shader, RenderState, ShaderAttrib, FrameBufferProperties from metadrive.constants import RENDER_MODE_ONSCREEN, BKG_COLOR, RENDER_MODE_NONE @@ -51,6 +51,9 @@ def __init__( self.lens = self.cam.node().getLens() return + + frame_buffer_property = FrameBufferProperties() + frame_buffer_property.set_rgba_bits(8,8,8,0) # disable alpha for RGB camera # self.texture = Texture() if frame_buffer_property is None: @@ -102,10 +105,9 @@ def __init__( def get_rgb_array_cpu(self): origin_img = self.buffer.getDisplayRegion(1).getScreenshot() img = np.frombuffer(origin_img.getRamImage().getData(), dtype=np.uint8) - img = img.reshape((origin_img.getYSize(), origin_img.getXSize(), 4)) + img = img.reshape((origin_img.getYSize(), origin_img.getXSize(), 3)) # img = np.swapaxes(img, 1, 0) img = img[::-1] - img = img[..., :-1] return img @staticmethod