From ed94729d0c17d6309da3ac43eb4b9cb87b843159 Mon Sep 17 00:00:00 2001 From: Rajat Singhal Date: Wed, 7 Oct 2020 21:03:25 +0530 Subject: [PATCH] Revert "Disable cameras after fetching images, projection matrix (#2881)" Running the Image API continuously seems to trigger exceptions This reverts commit ba4be152b5f06279261150aada9af510e6e1b431. --- PythonClient/multirotor/high_res_camera.py | 61 ------------------- Unreal/Plugins/AirSim/Source/PIPCamera.cpp | 15 +++-- .../AirSim/Source/UnrealImageCapture.cpp | 4 -- 3 files changed, 7 insertions(+), 73 deletions(-) delete mode 100644 PythonClient/multirotor/high_res_camera.py diff --git a/PythonClient/multirotor/high_res_camera.py b/PythonClient/multirotor/high_res_camera.py deleted file mode 100644 index 151383f444..0000000000 --- a/PythonClient/multirotor/high_res_camera.py +++ /dev/null @@ -1,61 +0,0 @@ -import airsim -from datetime import datetime - -''' -Simple script with settings to create a high-resolution camera, and fetching it - -Settings used- -{ - "SettingsVersion": 1.2, - "SimMode": "Multirotor", - "Vehicles" : { - "Drone1" : { - "VehicleType" : "SimpleFlight", - "AutoCreate" : true, - "Cameras" : { - "high_res": { - "CaptureSettings" : [ - { - "ImageType" : 0, - "Width" : 4320, - "Height" : 2160 - } - ], - "X": 0.50, "Y": 0.00, "Z": 0.10, - "Pitch": 0.0, "Roll": 0.0, "Yaw": 0.0 - }, - "low_res": { - "CaptureSettings" : [ - { - "ImageType" : 0, - "Width" : 256, - "Height" : 144 - } - ], - "X": 0.50, "Y": 0.00, "Z": 0.10, - "Pitch": 0.0, "Roll": 0.0, "Yaw": 0.0 - } - } - } - } -} -''' - -client = airsim.VehicleClient() -client.confirmConnection() -framecounter = 1 - -prevtimestamp = datetime.now() - -while(framecounter <= 500): - if framecounter%150 == 0: - client.simGetImages([airsim.ImageRequest("high_res", airsim.ImageType.Scene, False, False)]) - print("High resolution image captured.") - - if framecounter%30 == 0: - now = datetime.now() - print(f"Time spent for 30 frames: {now-prevtimestamp}") - prevtimestamp = now - - client.simGetImages([airsim.ImageRequest("low_res", airsim.ImageType.Scene, False, False)]) - framecounter += 1 diff --git a/Unreal/Plugins/AirSim/Source/PIPCamera.cpp b/Unreal/Plugins/AirSim/Source/PIPCamera.cpp index b87ad3749a..735298788c 100644 --- a/Unreal/Plugins/AirSim/Source/PIPCamera.cpp +++ b/Unreal/Plugins/AirSim/Source/PIPCamera.cpp @@ -86,8 +86,6 @@ void APIPCamera::BeginPlay() msr::airlib::ProjectionMatrix APIPCamera::getProjectionMatrix(const APIPCamera::ImageType image_type) const { - msr::airlib::ProjectionMatrix mat; - //TODO: avoid the need to override const cast here const_cast(this)->setCameraTypeEnabled(image_type, true); const USceneCaptureComponent2D* capture = const_cast(this)->getCaptureComponent(image_type, false); @@ -163,17 +161,18 @@ msr::airlib::ProjectionMatrix APIPCamera::getProjectionMatrix(const APIPCamera:: FMatrix projMatTransposeInAirSim = coordinateChangeTranspose * proj_mat_transpose; //Copy the result to an airlib::ProjectionMatrix while taking transpose. + msr::airlib::ProjectionMatrix mat; for (auto row = 0; row < 4; ++row) for (auto col = 0; col < 4; ++col) mat.matrix[col][row] = projMatTransposeInAirSim.M[row][col]; + + return mat; } - else + else { + msr::airlib::ProjectionMatrix mat; mat.setTo(Utils::nan()); - - // Disable camera after our work is done - const_cast(this)->setCameraTypeEnabled(image_type, false); - - return mat; + return mat; + } } void APIPCamera::Tick(float DeltaTime) diff --git a/Unreal/Plugins/AirSim/Source/UnrealImageCapture.cpp b/Unreal/Plugins/AirSim/Source/UnrealImageCapture.cpp index 6b034f81df..da28a1795f 100644 --- a/Unreal/Plugins/AirSim/Source/UnrealImageCapture.cpp +++ b/Unreal/Plugins/AirSim/Source/UnrealImageCapture.cpp @@ -112,10 +112,6 @@ void UnrealImageCapture::getSceneCaptureImage(const std::vectorwidth; response.height = render_results[i]->height; response.image_type = request.image_type; - - // Disable camera after fetching images - APIPCamera* camera = cameras_->at(request.camera_name); - camera->setCameraTypeEnabled(request.image_type, false); } }