Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Disable cameras after fetching images, projection matrix #2881

Merged
merged 2 commits into from
Sep 2, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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