Skip to content

Commit

Permalink
Disable cameras after fetching images, projection matrix (#2881)
Browse files Browse the repository at this point in the history
* Disable cameras after fetching images, projection matrix

* [Pythonclient] Add example script for testing high resolution camera
  • Loading branch information
rajat2004 authored Sep 2, 2020
1 parent 67d5b6a commit ba4be15
Show file tree
Hide file tree
Showing 3 changed files with 73 additions and 7 deletions.
61 changes: 61 additions & 0 deletions PythonClient/multirotor/high_res_camera.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
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
15 changes: 8 additions & 7 deletions Unreal/Plugins/AirSim/Source/PIPCamera.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,8 @@ 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<APIPCamera*>(this)->setCameraTypeEnabled(image_type, true);
const USceneCaptureComponent2D* capture = const_cast<APIPCamera*>(this)->getCaptureComponent(image_type, false);
Expand Down Expand Up @@ -161,18 +163,17 @@ 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 {
msr::airlib::ProjectionMatrix mat;
else
mat.setTo(Utils::nan<float>());
return mat;
}

// Disable camera after our work is done
const_cast<APIPCamera*>(this)->setCameraTypeEnabled(image_type, false);

return mat;
}

void APIPCamera::Tick(float DeltaTime)
Expand Down
4 changes: 4 additions & 0 deletions Unreal/Plugins/AirSim/Source/UnrealImageCapture.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,10 @@ void UnrealImageCapture::getSceneCaptureImage(const std::vector<msr::airlib::Ima
response.width = render_results[i]->width;
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);
}

}
Expand Down

0 comments on commit ba4be15

Please sign in to comment.