{ "cells": [ { "cell_type": "code", "execution_count": null, "id": "40c027eb", "metadata": {}, "outputs": [], "source": [ "### Camera" ] }, { "cell_type": "code", "execution_count": null, "id": "51ab933a", "metadata": {}, "outputs": [], "source": [ "from simworld.communicator.communicator import Communicator\n", "from simworld.communicator.unrealcv import UnrealCV" ] }, { "cell_type": "code", "execution_count": null, "id": "60f59d1e", "metadata": {}, "outputs": [], "source": [ "ucv = UnrealCV()\n", "communicator = Communicator(ucv)" ] }, { "cell_type": "code", "execution_count": null, "id": "cd2a4fd0", "metadata": {}, "outputs": [], "source": [ "# Spawn a robot dog in the environment for demonstration\n", "# This creates an object that we can observe with cameras\n", "robot_dog_name = \"Demo_Robot\"\n", "robot_dog_asset = \"/Game/Robot_Dog/Blueprint/BP_SpotRobot.BP_SpotRobot_C\"\n", "ucv.spawn_bp_asset(robot_dog_asset, robot_dog_name)\n", "ucv.set_location((0, 0, 20), robot_dog_name) # Set position (x, y, z)\n", "ucv.enable_controller(robot_dog_name, True) # Enable controller for the robot" ] }, { "cell_type": "code", "execution_count": null, "id": "23b15d4c", "metadata": {}, "outputs": [], "source": [ "# Get and display a lit (RGB) image from camera 1\n", "# Camera IDs typically start from 0 or 1\n", "camera_id = 1\n", "image = communicator.get_camera_observation(camera_id, 'lit')\n", "communicator.show_img(image)" ] }, { "cell_type": "markdown", "id": "03c2add5", "metadata": {}, "source": [ "## Get Different View Modes\n", "\n", "SimWorld supports multiple view modes for different types of sensor data." ] }, { "cell_type": "code", "execution_count": null, "id": "7ee6e9df", "metadata": {}, "outputs": [], "source": [ "# Get RGB image with lighting\n", "rgb_image = communicator.get_camera_observation(camera_id, 'lit')\n", "print(f\"RGB image shape: {rgb_image.shape}\")\n", "communicator.show_img(rgb_image)" ] }, { "cell_type": "code", "execution_count": null, "id": "41854393", "metadata": {}, "outputs": [], "source": [ "# Get depth map\n", "depth_image = communicator.get_camera_observation(camera_id, 'depth')\n", "print(f\"Depth image shape: {depth_image.shape}\")\n", "communicator.show_img(depth_image)" ] }, { "cell_type": "code", "execution_count": null, "id": "d4f17d5e", "metadata": {}, "outputs": [], "source": [ "# Get object segmentation mask\n", "mask_image = communicator.get_camera_observation(camera_id, 'object_mask')\n", "print(f\"Mask image shape: {mask_image.shape}\")\n", "communicator.show_img(mask_image)" ] }, { "cell_type": "markdown", "id": "db2e401a", "metadata": {}, "source": [ "## Camera Management\n", "\n", "You can query and adjust camera parameters such as position, rotation, field of view, and resolution." ] }, { "cell_type": "code", "execution_count": null, "id": "4cf1391c", "metadata": {}, "outputs": [], "source": [ "# Get list of all available cameras\n", "cameras = ucv.get_cameras()\n", "print(f\"Available cameras: {cameras}\")\n", "\n", "# Get current camera parameters\n", "location = ucv.get_camera_location(camera_id)\n", "rotation = ucv.get_camera_rotation(camera_id)\n", "fov = ucv.get_camera_fov(camera_id)\n", "resolution = ucv.get_camera_resolution(camera_id)\n", "\n", "print(f\"Camera {camera_id} parameters:\")\n", "print(f\" Location: {location}\")\n", "print(f\" Rotation: {rotation}\")\n", "print(f\" FOV: {fov}\")\n", "print(f\" Resolution: {resolution}\")" ] }, { "cell_type": "code", "execution_count": null, "id": "41ec81e2", "metadata": {}, "outputs": [], "source": [ "# Adjust camera position (x, y, z in Unreal units)\n", "new_location = (100, 200, 150) # Example: move camera to a new position\n", "ucv.set_camera_location(camera_id, new_location)\n", "print(f\"Camera {camera_id} location set to: {new_location}\")\n", "\n", "# Adjust camera rotation (pitch, yaw, roll in degrees)\n", "new_rotation = (0, 45, 0) # Example: rotate camera 45 degrees on yaw axis\n", "ucv.set_camera_rotation(camera_id, new_rotation)\n", "print(f\"Camera {camera_id} rotation set to: {new_rotation}\")\n", "\n", "# Adjust field of view (horizontal FOV in degrees)\n", "new_fov = 90.0 # Example: set FOV to 90 degrees\n", "ucv.set_camera_fov(camera_id, new_fov)\n", "print(f\"Camera {camera_id} FOV set to: {new_fov}\")\n", "\n", "# Adjust camera resolution (width, height in pixels)\n", "new_resolution = (1920, 1080) # Example: set to Full HD\n", "ucv.set_camera_resolution(camera_id, new_resolution)\n", "print(f\"Camera {camera_id} resolution set to: {new_resolution}\")" ] } ], "metadata": { "kernelspec": { "display_name": "simworld", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.10.18" } }, "nbformat": 4, "nbformat_minor": 5 }