Skip to content

Commit

Permalink
rgb only
Browse files Browse the repository at this point in the history
  • Loading branch information
jnewb1 committed Sep 28, 2023
1 parent 2f8379a commit f2958ef
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
2 changes: 1 addition & 1 deletion metadrive/component/sensors/base_camera.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
8 changes: 5 additions & 3 deletions metadrive/engine/core/image_buffer.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit f2958ef

Please sign in to comment.