Skip to content

Commit

Permalink
Implemented rgb_array mode for rqt6
Browse files Browse the repository at this point in the history
  • Loading branch information
AhmadAmine998 committed Aug 9, 2024
1 parent 719465a commit 78591eb
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 5 deletions.
2 changes: 1 addition & 1 deletion examples/video_recording.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ def main():
}

env = gym.make(
"f1tenth_gym:f1tenth-v0,
"f1tenth_gym:f1tenth-v0",
config={
"map": "Spielberg",
"num_agents": 1,
Expand Down
19 changes: 15 additions & 4 deletions f1tenth_gym/envs/rendering/rendering_pyqt.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
from PyQt6 import QtGui
import pyqtgraph as pg
from pyqtgraph.examples.utils import FrameCounter
from pyqtgraph.exporters import ImageExporter
from PIL import ImageColor

from .pyqt_objects import (
Expand Down Expand Up @@ -160,7 +161,10 @@ def __init__(
self.follow_agent_flag: bool = False
self.agent_to_follow: int = None

self.window.show()
if self.render_mode in ["human", "human_fast"]:
self.window.show()
elif self.render_mode == "rgb_array":
self.exporter = ImageExporter(self.canvas)

def update(self, state: dict) -> None:
"""
Expand Down Expand Up @@ -304,9 +308,16 @@ def render(self) -> Optional[np.ndarray]:
assert self.window is not None

else:
# rgb_array
# TODO: extract the frame from the canvas
frame = None
# rgb_array mode => extract the frame from the canvas
qImage = self.exporter.export(toBytes=True)

width = qImage.width()
height = qImage.height()

ptr = qImage.bits()
ptr.setsize(height * width * 4)
frame = np.array(ptr).reshape(height, width, 4) # Copies the data

return frame

def render_points(
Expand Down

0 comments on commit 78591eb

Please sign in to comment.