Skip to content

Commit 9935ae5

Browse files
committed
Python 2.7 fixes, fix camera view switching
1 parent 911bc24 commit 9935ae5

File tree

8 files changed

+32
-22
lines changed

8 files changed

+32
-22
lines changed

AirLib/include/common/common_utils/Utils.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -640,9 +640,9 @@ class Utils {
640640

641641
std::string bands;
642642
float fvalue; // scale factor and temp value to hold pixel value
643-
bands = "Pf"; // grayscale
643+
bands = "Pf"; // grayscale
644644

645-
// sign of scalefact indicates endianness, see pfms specs
645+
// sign of scalefact indicates endianness, see pfm specs
646646
if(isLittleEndian())
647647
scalef = -scalef;
648648

PythonClient/PythonClient.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -332,23 +332,23 @@ def write_pfm(file, image, scale=1):
332332
else:
333333
raise Exception('Image must have H x W x 3, H x W x 1 or H x W dimensions.')
334334

335-
file.write(bytes('PF\n', 'UTF-8') if color else bytes('Pf\n', 'UTF-8'))
335+
file.write('PF\n'.encode('utf-8') if color else 'Pf\n'.encode('utf-8'))
336336
temp_str = '%d %d\n' % (image.shape[1], image.shape[0])
337-
file.write(bytes(temp_str, 'UTF-8'))
337+
file.write(temp_str.encode('utf-8'))
338338

339339
endian = image.dtype.byteorder
340340

341341
if endian == '<' or endian == '=' and sys.byteorder == 'little':
342342
scale = -scale
343343

344344
temp_str = '%f\n' % scale
345-
file.write(bytes(temp_str, 'UTF-8'))
345+
file.write(temp_str.encode('utf-8'))
346346

347347
image.tofile(file)
348348

349349

350350
# ----------------------------------- Multirotor APIs ---------------------------------------------
351-
class MultirotorClient(AirSimClientBase):
351+
class MultirotorClient(AirSimClientBase, object):
352352
def __init__(self, ip = ""):
353353
if (ip == ""):
354354
ip = "127.0.0.1"
@@ -426,7 +426,7 @@ def rotateByYawRate(self, yaw_rate, duration):
426426
return self.client.call('rotateByYawRate', yaw_rate, duration)
427427

428428
# ----------------------------------- Car APIs ---------------------------------------------
429-
class CarClient(AirSimClientBase):
429+
class CarClient(AirSimClientBase, object):
430430
def __init__(self, ip = ""):
431431
if (ip == ""):
432432
ip = "127.0.0.1"

PythonClient/hello_car.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
car_controls.throttle = -0.5
3030
car_controls.is_manual_gear = True;
3131
car_controls.manual_gear = -1
32-
car_controls.steering = -1
32+
car_controls.steering = -0.5
3333
client.setCarControls(car_controls)
3434
print("Go reverse, steer right")
3535
time.sleep(3) # let car drive a bit

Unreal/Plugins/AirSim/Source/CameraDirector.cpp

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -51,11 +51,6 @@ void ACameraDirector::initializeForBeginPlay(ECameraDirectorMode view_mode, Vehi
5151

5252
mode_ = view_mode;
5353
setCameras(external_camera, vehicle_pawn_wrapper);
54-
55-
camera_start_location_ = this->GetActorLocation();
56-
camera_start_rotation_ = this->GetActorRotation();
57-
initial_ground_obs_offset_ = camera_start_location_ - follow_actor_->GetActorLocation();
58-
5954
}
6055

6156
void ACameraDirector::setCameras(APIPCamera* external_camera, VehiclePawnWrapper* vehicle_pawn_wrapper)
@@ -64,6 +59,10 @@ void ACameraDirector::setCameras(APIPCamera* external_camera, VehiclePawnWrapper
6459
fpv_camera_ = vehicle_pawn_wrapper->getCameraCount() > 0 ? vehicle_pawn_wrapper->getCamera() : nullptr;
6560
follow_actor_ = vehicle_pawn_wrapper->getPawn();
6661

62+
camera_start_location_ = this->GetActorLocation();
63+
camera_start_rotation_ = this->GetActorRotation();
64+
initial_ground_obs_offset_ = camera_start_location_ - follow_actor_->GetActorLocation();
65+
6766
manual_pose_controller_->setActor(external_camera_, false);
6867

6968
//set initial view mode
@@ -86,12 +85,12 @@ void ACameraDirector::attachSpringArm(bool attach)
8685
external_camera_->DetachFromActor(FDetachmentTransformRules::KeepWorldTransform);
8786
SpringArm->AttachToComponent(follow_actor_->GetRootComponent(), FAttachmentTransformRules::KeepRelativeTransform);
8887
SpringArm->SetRelativeLocation(FVector(0.0f, 0.0f, 34.0f));
88+
}
8989

90-
external_camera_->AttachToComponent(SpringArm, FAttachmentTransformRules::KeepRelativeTransform);
91-
external_camera_->SetActorRelativeLocation(FVector(-225.0, 0.0f, 0.0f));
92-
external_camera_->SetActorRelativeRotation(FRotator(10.0f, 0.0f, 0.0f));
93-
//external_camera_->bUsePawnControlRotation = false;
94-
}
90+
external_camera_->AttachToComponent(SpringArm, FAttachmentTransformRules::KeepRelativeTransform);
91+
external_camera_->SetActorRelativeLocation(FVector(-225.0, 0.0f, 0.0f));
92+
external_camera_->SetActorRelativeRotation(FRotator(10.0f, 0.0f, 0.0f));
93+
//external_camera_->bUsePawnControlRotation = false;
9594
}
9695
else {
9796
if (last_parent_ && external_camera_->GetRootComponent()->GetAttachParent() == SpringArm) {
@@ -184,6 +183,10 @@ void ACameraDirector::inputEventFlyWithView()
184183
{
185184
setMode(ECameraDirectorMode::CAMERA_DIRECTOR_MODE_FLY_WITH_ME);
186185
external_camera_->showToScreen();
186+
187+
if (follow_actor_)
188+
external_camera_->SetActorLocationAndRotation(
189+
follow_actor_->GetActorLocation() + initial_ground_obs_offset_, camera_start_rotation_);
187190
if (fpv_camera_)
188191
fpv_camera_->disableMain();
189192
ext_obs_fixed_z_ = false;

Unreal/Plugins/AirSim/Source/Car/SimModeCar.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ void ASimModeCar::setupVehiclesAndCamera(std::vector<VehiclePtr>& vehicles)
4141
APlayerController* player_controller = this->GetWorld()->GetFirstPlayerController();
4242
FTransform actor_transform = player_controller->GetActorTransform();
4343
//put camera little bit above vehicle
44-
FTransform camera_transform(actor_transform.GetLocation() + FVector(-300, 0, 200));
44+
FTransform camera_transform(actor_transform.GetLocation() + FVector(300, 0, 200));
4545

4646
//we will either find external camera if it already exist in evironment or create one
4747
APIPCamera* external_camera;

docs/apis.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ int main()
8484
You can find a ready to run project in HelloCar folder in the repository.
8585

8686
## Image / Computer Vision and Collision APIs
87-
AirSim offers comprehensive images APIs to retrieve synchronized images from multiple cameras along with ground truth including depth, disparity, surface normals and vision. You can set the resolution, FOV, motion blur etc parameters in [settings.json](settings.md). There is also API for detecting collision state. See also [complete code](../Examples/StereoImageGenerator.hpp) that generates specified number of stereo images and ground truth depth with normalization to camera plan, computation of disparity image and saving it to pfm format.
87+
AirSim offers comprehensive images APIs to retrieve synchronized images from multiple cameras along with ground truth including depth, disparity, surface normals and vision. You can set the resolution, FOV, motion blur etc parameters in [settings.json](settings.md). There is also API for detecting collision state. See also [complete code](../Examples/StereoImageGenerator.hpp) that generates specified number of stereo images and ground truth depth with normalization to camera plan, computation of disparity image and saving it to [pfm format](pfm.md).
8888

8989
More on [image APIs and Computer Vision mode](image_apis.md).
9090

docs/image_apis.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ int getStereoAndDepthImages()
4848
```
4949
For a ready to run sample code please see [sample code in HelloDrone project](../HelloDrone/main.cpp) for multirotors or [HelloCar project](../HelloCar/main.cpp).
5050

51-
See also [complete code](../Examples/StereoImageGenerator.hpp) that generates specified number of stereo images and ground truth depth with normalization to camera plan, computation of disparity image and saving it to pfm format.
51+
See also [complete code](../Examples/StereoImageGenerator.hpp) that generates specified number of stereo images and ground truth depth with normalization to camera plan, computation of disparity image and saving it to [pfm format](pfm.md).
5252

5353
Unlike `simGetImage`, the `simGetImages` API also allows you to get uncompressed images as well as floating point single channel images (instead of 3 channel (RGB), each 8 bit).
5454

@@ -111,4 +111,4 @@ When you specify `ImageType = Segmentation` in `ImageRequest`, you get image tha
111111
The collision information can be obtained using `getCollisionInfo` API. This call returns a struct that has information not only whether collision occurred but also collision position, surface normal, penetration depth and so on.
112112

113113
## Example Code
114-
A complete example of setting vehicle positions at random locations and orientations and then taking images can be found in [GenerateImageGenerator.hpp](../Examples/StereoImageGenerator.hpp). This example generates specified number of stereo images and ground truth disparity image and saving it to pfm format.
114+
A complete example of setting vehicle positions at random locations and orientations and then taking images can be found in [GenerateImageGenerator.hpp](../Examples/StereoImageGenerator.hpp). This example generates specified number of stereo images and ground truth disparity image and saving it to [pfm format](pfm.md).

docs/pfm.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# pfm Format
2+
3+
Pfm (or Portable FloatMap) image format stores image as floating point pixels and hence are not restricted to usual 0-255 pixel value range. This is useful for HDR images or images that describes something other than colors like depth.
4+
5+
One of the good viewer to view this file format is [PfmPad](https://sourceforge.net/projects/pfmpad/). We don't recommand Maverick photo viewer because it doesn't seem to show depth images properly.
6+
7+
AirSim has code to write pfm file for [C++](https://github.com/Microsoft/AirSim/blob/master/AirLib/include/common/common_utils/Utils.hpp#L637) and read as well as write for [Python](https://github.com/Microsoft/AirSim/blob/master/PythonClient/PythonClient.py#L273).

0 commit comments

Comments
 (0)