Skip to content

Commit

Permalink
Merge branch 'microsoft:master' into master
Browse files Browse the repository at this point in the history
  • Loading branch information
ppueyor authored Nov 8, 2021
2 parents bca2944 + 2891632 commit eb4ee74
Show file tree
Hide file tree
Showing 68 changed files with 1,892 additions and 595 deletions.
9 changes: 9 additions & 0 deletions .github/workflows/test_ubuntu.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,3 +31,12 @@ jobs:
source /opt/ros/*/setup.bash
cd ros
catkin build -DCMAKE_C_COMPILER=gcc-8 -DCMAKE_CXX_COMPILER=g++-8
- name: Build GazeboDrone
run: |
sudo apt-get install -qq libgazebo9-dev gcc-8 g++-8
./clean.sh && ./build.sh --gcc
cd GazeboDrone
mkdir build && cd build
cmake -DCMAKE_C_COMPILER=gcc-8 -DCMAKE_CXX_COMPILER=g++-8 ..
make
15 changes: 15 additions & 0 deletions AirLib/include/common/GeodeticConverter.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,11 @@ namespace airlib
setHome(home_latitude, home_longitude, home_altitude);
}

GeodeticConverter(const GeoPoint& home_geopoint)
{
setHome(home_geopoint);
}

void setHome(double home_latitude, double home_longitude, float home_altitude)
{
home_latitude_ = home_latitude;
Expand All @@ -40,6 +45,11 @@ namespace airlib
ned_to_ecef_matrix_ = nRe(home_latitude_rad_, home_longitude_rad_).transpose();
}

void setHome(const GeoPoint& home_geopoint)
{
setHome(home_geopoint.latitude, home_geopoint.longitude, home_geopoint.altitude);
}

void getHome(double* latitude, double* longitude, float* altitude)
{
*latitude = home_latitude_;
Expand Down Expand Up @@ -139,6 +149,11 @@ namespace airlib
*altitude = home_altitude_ - down;
}

void ned2Geodetic(const Vector3r& ned_pos, GeoPoint& geopoint)
{
ned2Geodetic(ned_pos[0], ned_pos[1], ned_pos[2], &geopoint.latitude, &geopoint.longitude, &geopoint.altitude);
}

void geodetic2Enu(const double latitude, const double longitude, const double altitude,
double* east, double* north, double* up)
{
Expand Down
1 change: 0 additions & 1 deletion GazeboDrone/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ cmake_minimum_required(VERSION 2.8 FATAL_ERROR)
project(GazeboDrone)

set(AIRSIM_ROOT ..)
set(CMAKE_CXX_COMPILER /usr/bin/g++)

if(NOT CMAKE_CXX_STANDARD)
set(CMAKE_CXX_STANDARD 11)
Expand Down
14 changes: 1 addition & 13 deletions PythonClient/PythonClient.pyproj
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<SchemaVersion>2.0</SchemaVersion>
<ProjectGuid>e2049e20-b6dd-474e-8bca-1c8dc54725aa</ProjectGuid>
<ProjectHome>.</ProjectHome>
<StartupFile>computer_vision\character_control.py</StartupFile>
<StartupFile>computer_vision\cv_capture.py</StartupFile>
<SearchPath>
</SearchPath>
<WorkingDirectory>.</WorkingDirectory>
Expand Down Expand Up @@ -35,18 +35,12 @@
<Compile Include="airsim\__init__.py">
<SubType>Code</SubType>
</Compile>
<Compile Include="car\legacy_hello_car.py">
<SubType>Code</SubType>
</Compile>
<Compile Include="car\multi_agent_car.py">
<SubType>Code</SubType>
</Compile>
<Compile Include="car\setup_path.py">
<SubType>Code</SubType>
</Compile>
<Compile Include="computer_vision\character_control.py">
<SubType>Code</SubType>
</Compile>
<Compile Include="computer_vision\cv_capture.py">
<SubType>Code</SubType>
</Compile>
Expand Down Expand Up @@ -83,18 +77,15 @@
<Compile Include="car\car_collision.py" />
<Compile Include="car\car_monitor.py" />
<Compile Include="car\car_stress_test.py" />
<Compile Include="car\DQNcar.py" />
<Compile Include="car\drive_straight.py" />
<Compile Include="car\hello_car.py" />
<Compile Include="car\reset_test_car.py" />
<Compile Include="multirotor\opencv_show.py" />
<Compile Include="computer_vision\cv_mode.py" />
<Compile Include="multirotor\point_cloud.py" />
<Compile Include="computer_vision\segmentation.py" />
<Compile Include="computer_vision\seg_pallete.py" />
<Compile Include="multirotor\box.py" />
<Compile Include="multirotor\disarm.py" />
<Compile Include="multirotor\DQNdrone.py" />
<Compile Include="multirotor\drone_stress_test.py" />
<Compile Include="multirotor\hello_drone.py" />
<Compile Include="multirotor\orbit.py" />
Expand All @@ -120,9 +111,6 @@
<Folder Include="ros\" />
</ItemGroup>
<ItemGroup>
<Content Include="install_packages.bat">
<SubType>Code</SubType>
</Content>
<Content Include="LICENSE" />
<Content Include="README.md">
<SubType>Code</SubType>
Expand Down
2 changes: 1 addition & 1 deletion PythonClient/airsim/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@
from .utils import *
from .types import *

__version__ = "1.5.0"
__version__ = "1.6.0"
155 changes: 155 additions & 0 deletions PythonClient/computer_vision/image_benchmarker.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,155 @@
import setup_path
import airsim
from argparse import ArgumentParser
import time
import threading
import numpy as np
import cv2
import tempfile
import os


cameraTypeMap = {
"depth": airsim.ImageType.DepthVis,
"segmentation": airsim.ImageType.Segmentation,
"seg": airsim.ImageType.Segmentation,
"scene": airsim.ImageType.Scene,
"disparity": airsim.ImageType.DisparityNormalized,
"normals": airsim.ImageType.SurfaceNormals
}

CAM_NAME = "front_center"
DEBUG = False

def saveImage(response, filename):
if response.pixels_as_float:
# airsim.write_pfm(os.path.normpath(filename + '.pfm'), airsim.get_pfm_array(response))
depth = np.array(response.image_data_float, dtype=np.float64)
depth = depth.reshape((response.height, response.width, -1))
depth = np.array(depth * 255, dtype=np.uint8)
# save pic
cv2.imwrite(os.path.normpath(filename + '.png'), depth)

elif response.compress: #png format
airsim.write_file(os.path.normpath(filename + '.png'), response.image_data_uint8)

else: #uncompressed array
img1d = np.fromstring(response.image_data_uint8, dtype=np.uint8) # get numpy array
img_rgb = img1d.reshape(response.height, response.width, 3) # reshape array to 3 channel image array H X W X 3
cv2.imwrite(os.path.normpath(filename + '.png'), img_rgb) # write to png

class ImageBenchmarker():
def __init__(self,
img_benchmark_type = 'simGetImages',
viz_image_cv2 = False,
save_images = False,
img_type = "scene"):
self.airsim_client = airsim.VehicleClient()
self.airsim_client.confirmConnection()
self.image_benchmark_num_images = 0
self.image_benchmark_total_time = 0.0
self.avg_fps = 0.0
self.image_callback_thread = None
self.viz_image_cv2 = viz_image_cv2
self.save_images = save_images

self.img_type = cameraTypeMap[img_type]

if img_benchmark_type == "simGetImage":
self.image_callback_thread = threading.Thread(target=self.repeat_timer_img, args=(self.image_callback_benchmark_simGetImage, 0.001))
if img_benchmark_type == "simGetImages":
self.image_callback_thread = threading.Thread(target=self.repeat_timer_img, args=(self.image_callback_benchmark_simGetImages, 0.001))
self.is_image_thread_active = False

if self.save_images:
self.tmp_dir = os.path.join(tempfile.gettempdir(), "airsim_img_bm")
print(f"Saving images to {self.tmp_dir}")
try:
os.makedirs(self.tmp_dir)
except OSError:
if not os.path.isdir(self.tmp_dir):
raise

def start_img_benchmark_thread(self):
if not self.is_image_thread_active:
self.is_image_thread_active = True
self.benchmark_start_time = time.time()
self.image_callback_thread.start()
print("Started img image_callback thread")

def stop_img_benchmark_thread(self):
if self.is_image_thread_active:
self.is_image_thread_active = False
self.image_callback_thread.join()
print("Stopped image callback thread.")
print(f"FPS: {self.avg_fps} for {self.image_benchmark_num_images} images")

def repeat_timer_img(self, task, period):
while self.is_image_thread_active:
task()
time.sleep(period)

def update_benchmark_results(self):
self.image_benchmark_total_time = time.time() - self.benchmark_start_time
self.avg_fps = self.image_benchmark_num_images / self.image_benchmark_total_time
if self.image_benchmark_num_images % 10 == 0:
print(f"Result: {self.avg_fps} avg_fps for {self.image_benchmark_num_images} images")

def image_callback_benchmark_simGetImage(self):
self.image_benchmark_num_images += 1
image = self.airsim_client.simGetImage(CAM_NAME, self.img_type)
np_arr = np.frombuffer(image, dtype=np.uint8)
# Change the below dimensions appropriately for the camera settings
img_rgb = np_arr.reshape(240, 512, 4)

self.update_benchmark_results()

if self.viz_image_cv2:
cv2.imshow("img_rgb", img_rgb)
cv2.waitKey(1)

def image_callback_benchmark_simGetImages(self):
self.image_benchmark_num_images += 1
request = [airsim.ImageRequest(CAM_NAME, self.img_type, False, False)]
responses = self.airsim_client.simGetImages(request)
response = responses[0]

self.update_benchmark_results()

if DEBUG:
if response.pixels_as_float:
print(f"Type {response.image_type}, size {len(response.image_data_float)},"
f"height {response.height}, width {response.width}")
else:
print(f"Type {response.image_type}, size {len(response.image_data_uint8)},"
f"height {response.height}, width {response.width}")

if self.viz_image_cv2:
np_arr = np.frombuffer(response.image_data_uint8, dtype=np.uint8)
img = np_arr.reshape(response.height, response.width, -1)
cv2.imshow("img", img)
cv2.waitKey(1)

if self.save_images:
filename = os.path.join(self.tmp_dir, str(self.image_benchmark_num_images))
saveImage(response, filename)


def main(args):
image_benchmarker = ImageBenchmarker(img_benchmark_type=args.img_benchmark_type, viz_image_cv2=args.viz_image_cv2,
save_images=args.save_images, img_type=args.img_type)

image_benchmarker.start_img_benchmark_thread()
time.sleep(args.time)
image_benchmarker.stop_img_benchmark_thread()

if __name__ == "__main__":
parser = ArgumentParser()
parser.add_argument('--img_benchmark_type', type=str, choices=["simGetImage", "simGetImages"], default="simGetImages")
parser.add_argument('--enable_viz_image_cv2', dest='viz_image_cv2', action='store_true', default=False)
parser.add_argument('--save_images', dest='save_images', action='store_true', default=False)
parser.add_argument('--img_type', type=str, choices=cameraTypeMap.keys(), default="scene")
parser.add_argument('--time', help="Time in secs to run the benchmark for", type=int, default=30)

args = parser.parse_args()
main(args)
6 changes: 3 additions & 3 deletions PythonClient/eventcamera_sim/event_simulator.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,8 @@ def esim(

current_time = last_time
for i in range(spike_nums):
output_events[count].x = x // n_pix_row
output_events[count].y = x % n_pix_row
output_events[count].x = x % n_pix_row
output_events[count].y = x // n_pix_row
output_events[count].timestamp = np.round(current_time * 1e-6, 6)
output_events[count].polarity = 1 if pol > 0 else -1

Expand All @@ -82,7 +82,7 @@ def esim(


class EventSimulator:
def __init__(self, H, W, first_image=None, first_time=None, config=CONFIG):
def __init__(self, W, H, first_image=None, first_time=None, config=CONFIG):
self.H = H
self.W = W
self.config = config
Expand Down
2 changes: 1 addition & 1 deletion PythonClient/eventcamera_sim/test_event_sim.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@
class AirSimEventGen:
def __init__(self, W, H, save=False, debug=False):
self.ev_sim = EventSimulator(W, H)
self.W = W
self.H = H
self.W = W

self.image_request = airsim.ImageRequest(
"0", airsim.ImageType.Scene, False, False
Expand Down
Loading

0 comments on commit eb4ee74

Please sign in to comment.