Skip to content

Commit

Permalink
Added test scripts for camera without reshape.
Browse files Browse the repository at this point in the history
  • Loading branch information
YoruCathy committed Apr 28, 2024
1 parent 725b82c commit 8e7fbf8
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 4 deletions.
16 changes: 16 additions & 0 deletions hackathon_demo/test_camera_raw.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
from pyrcareworld.envs import RCareWorld
import cv2
import numpy as np

env = RCareWorld(executable_file="@Editor")


env.instance_channel.set_action("GetRGB", id=654321, width=512, height=1024)
info = env.instance_channel.data[654321]

env.step()
image_byte = env.instance_channel.data[654321]["rgb"]
image_rgb = np.frombuffer(image_byte, dtype=np.uint8)
image_rgb = cv2.imdecode(image_rgb, cv2.IMREAD_COLOR)
cv2.imshow("show", image_rgb)
cv2.waitKey(0)
11 changes: 11 additions & 0 deletions hackathon_demo/test_camera_rcw.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
from pyrcareworld.envs import RCareWorld
import cv2
import numpy as np

env = RCareWorld(executable_file="@Editor")
cam = env.create_camera(id=654321, name="Camera", width=512, height=1024, is_in_scene=True)
image_rgb = cam.getRGB()
image_rgb = cv2.imdecode(image_rgb, cv2.IMREAD_COLOR)
cv2.imshow("show", image_rgb)
cv2.waitKey(0)

5 changes: 1 addition & 4 deletions pyrcareworld/pyrcareworld/sensors/camera.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,10 +71,7 @@ def getRGB(self, mode="wh"):
self.env._step()
image_byte = self.env.instance_channel.data[self.id]["rgb"]
image_rgb = np.frombuffer(image_byte, dtype=np.uint8)
reshaped_image_rgb = image_rgb.reshape(self.height, self.width, 3)
# upside down and convert bgr to rgb
reshaped_image_rgb = np.flipud(reshaped_image_rgb)[:, :, ::-1]
return reshaped_image_rgb
return image_rgb

def getDepthEXR(self, mode="wh"):
"""
Expand Down

0 comments on commit 8e7fbf8

Please sign in to comment.