Skip to content

Commit

Permalink
Merge pull request #3278 from rajat2004/fix-camera-fov
Browse files Browse the repository at this point in the history
Update Camera FoV as well when using simSetCameraFoV API
  • Loading branch information
zimmy87 authored May 20, 2021
2 parents c5fb3a3 + 717d63a commit d2c8c3a
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 0 deletions.
53 changes: 53 additions & 0 deletions PythonClient/computer_vision/fov_change.py
Original file line number Diff line number Diff line change
@@ -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}")
2 changes: 2 additions & 0 deletions Unreal/Plugins/AirSim/Source/PIPCamera.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -277,6 +277,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);
}

void APIPCamera::setupCameraFromSettings(const APIPCamera::CameraSetting& camera_setting, const NedTransform& ned_transform)
Expand Down

0 comments on commit d2c8c3a

Please sign in to comment.