From c916b7a9d37b929b54a4e03b9793d8cdbbf64ace Mon Sep 17 00:00:00 2001 From: Rajat Singhal Date: Wed, 6 Jan 2021 20:10:24 +0530 Subject: [PATCH 1/2] Update Camera FoV as well when using simSetCameraFoV API Previously only Render texture FoVs were being updated --- Unreal/Plugins/AirSim/Source/PIPCamera.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Unreal/Plugins/AirSim/Source/PIPCamera.cpp b/Unreal/Plugins/AirSim/Source/PIPCamera.cpp index a1718a3fc0..b3c476f5e6 100644 --- a/Unreal/Plugins/AirSim/Source/PIPCamera.cpp +++ b/Unreal/Plugins/AirSim/Source/PIPCamera.cpp @@ -288,6 +288,8 @@ void APIPCamera::setCameraFoV(float fov_degrees) for (int image_type = 0; image_type < image_count; ++image_type) { captures_[image_type]->FOVAngle = fov_degrees; } + + camera_->SetFieldOfView(fov_degrees); } From 717d63acf37f6bdf116232e685b72482f5ff4ac1 Mon Sep 17 00:00:00 2001 From: Rajat Singhal Date: Wed, 6 Jan 2021 20:45:48 +0530 Subject: [PATCH 2/2] Pythonclient: Add example script for changing FoV of camera --- PythonClient/computer_vision/fov_change.py | 53 ++++++++++++++++++++++ 1 file changed, 53 insertions(+) create mode 100644 PythonClient/computer_vision/fov_change.py diff --git a/PythonClient/computer_vision/fov_change.py b/PythonClient/computer_vision/fov_change.py new file mode 100644 index 0000000000..8c15c09210 --- /dev/null +++ b/PythonClient/computer_vision/fov_change.py @@ -0,0 +1,53 @@ +import setup_path +import airsim +import os +import tempfile + +client = airsim.VehicleClient() +client.confirmConnection() + +tmp_dir = os.path.join(tempfile.gettempdir(), "airsim_cv_mode") +print ("Saving images to %s" % tmp_dir) +try: + os.makedirs(tmp_dir) +except OSError: + if not os.path.isdir(tmp_dir): + raise + +CAM_NAME = "front_center" +print(f"Camera: {CAM_NAME}") + +airsim.wait_key('Press any key to get camera parameters') + +cam_info = client.simGetCameraInfo(CAM_NAME) +print(cam_info) + +airsim.wait_key(f'Press any key to get images, saving to {tmp_dir}') + +requests = [airsim.ImageRequest(CAM_NAME, airsim.ImageType.Scene), + airsim.ImageRequest(CAM_NAME, airsim.ImageType.DepthVis)] + +def save_images(responses, prefix = ""): + for i, response in enumerate(responses): + filename = os.path.join(tmp_dir, prefix + "_" + str(i)) + if response.pixels_as_float: + print(f"Type {response.image_type}, size {len(response.image_data_float)}, pos {response.camera_position}") + airsim.write_pfm(os.path.normpath(filename + '.pfm'), airsim.get_pfm_array(response)) + else: + print(f"Type {response.image_type}, size {len(response.image_data_uint8)}, pos {response.camera_position}") + airsim.write_file(os.path.normpath(filename + '.png'), response.image_data_uint8) + + +responses = client.simGetImages(requests) +save_images(responses, "old_fov") + +airsim.wait_key('Press any key to change FoV and get images') + +client.simSetCameraFov(CAM_NAME, 120) +responses = client.simGetImages(requests) +save_images(responses, "new_fov") + +new_cam_info = client.simGetCameraInfo(CAM_NAME) +print(new_cam_info) + +print(f"Old FOV: {cam_info.fov}, New FOV: {new_cam_info.fov}")