How to use event_generator method in localstack

Best Python code snippet using localstack_python

test_event_sim.py

Source:test_event_sim.py Github

copy

Full Screen

1import numpy as np2import airsim3import time4import cv25import matplotlib.pyplot as plt6import argparse7import sys, signal8import pandas as pd9import pickle10from event_simulator import *11parser = argparse.ArgumentParser(description="Simulate event data from AirSim")12parser.add_argument("--debug", action="store_true")13parser.add_argument("--save", action="store_true")14parser.add_argument("--height", type=int, default=144)15parser.add_argument("--width", type=int, default=256)16class AirSimEventGen:17 def __init__(self, W, H, save=False, debug=False):18 self.ev_sim = EventSimulator(W, H)19 self.W = W20 self.H = H21 self.image_request = airsim.ImageRequest(22 "0", airsim.ImageType.Scene, False, False23 )24 self.client = airsim.VehicleClient()25 self.client.confirmConnection()26 self.init = True27 self.start_ts = None28 self.rgb_image_shape = [H, W, 3]29 self.debug = debug30 self.save = save31 self.event_file = open("events.pkl", "ab")32 self.event_fmt = "%1.7f", "%d", "%d", "%d"33 if debug:34 self.fig, self.ax = plt.subplots(1, 1)35 def visualize_events(self, event_img):36 event_img = self.convert_event_img_rgb(event_img)37 self.ax.cla()38 self.ax.imshow(event_img, cmap="viridis")39 plt.draw()40 plt.pause(0.01)41 def convert_event_img_rgb(self, image):42 image = image.reshape(self.H, self.W)43 out = np.zeros((self.H, self.W, 3), dtype=np.uint8)44 out[:, :, 0] = np.clip(image, 0, 1) * 25545 out[:, :, 2] = np.clip(image, -1, 0) * -25546 return out47 def _stop_event_gen(self, signal, frame):48 print("\nCtrl+C received. Stopping event sim...")49 self.event_file.close()50 sys.exit(0)51if __name__ == "__main__":52 args = parser.parse_args()53 event_generator = AirSimEventGen(args.width, args.height, save=args.save, debug=args.debug)54 i = 055 start_time = 056 t_start = time.time()57 signal.signal(signal.SIGINT, event_generator._stop_event_gen)58 while True:59 image_request = airsim.ImageRequest("0", airsim.ImageType.Scene, False, False)60 response = event_generator.client.simGetImages([event_generator.image_request])61 while response[0].height == 0 or response[0].width == 0:62 response = event_generator.client.simGetImages(63 [event_generator.image_request]64 )65 ts = time.time_ns()66 if event_generator.init:67 event_generator.start_ts = ts68 event_generator.init = False69 img = np.reshape(70 np.fromstring(response[0].image_data_uint8, dtype=np.uint8),71 event_generator.rgb_image_shape,72 )73 img = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY).astype(np.float32)74 # Add small number to avoid issues with log(I)75 img = cv2.add(img, 0.001)76 ts = time.time_ns()77 ts_delta = (ts - event_generator.start_ts) * 1e-378 # Event sim keeps track of previous image automatically79 event_img, events = event_generator.ev_sim.image_callback(img, ts_delta)80 if events is not None and events.shape[0] > 0:81 if event_generator.save:82 # Using pickle dump in a per-frame fashion to save time, instead of savetxt83 # Optimizations possible84 pickle.dump(events, event_generator.event_file)85 if event_generator.debug:...

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run localstack automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful