最美情侣中文字幕电影,在线麻豆精品传媒,在线网站高清黄,久久黄色视频

歡迎光臨散文網(wǎng) 會(huì)員登陸 & 注冊(cè)

AirSim在UE4中運(yùn)行時(shí)顯示第一人稱捕獲圖像窗口——settings.json配置和pygame兩種方法

2023-06-20 15:33 作者:皮卡丘上大學(xué)啦  | 我要投稿

一、通過settings.json配置“subwindows”字段去顯示

{

? ? "SettingsVersion": 1.2,

? ? "SeeDocsAt": "https://github.com/Microsoft/AirSim/blob/master/docs/settings.md",

? ? "SimMode": "Multirotor",

? ? "ViewMode": "FlyWithMe",

? ? "SubWindows": [

? ? ? ? {

? ? ? ? ? ? "WindowID": 0,

? ? ? ? ? ? "CameraName": "front_center_custom",

? ? ? ? ? ? "ImageType": 0,

? ? ? ? ? ? "Visible": true,

? ? ? ? ? ? "ImageSize": [480, 270],

? ? ? ? ? ? "CameraPosition": [0.0, 0.0, -2.5],

? ? ? ? ? ? "CameraRotation": [0.0, 0.0, 0.0]

? ? ? ? },

? ? ? ? {

? ? ? ? ? ? "WindowID": 1,

? ? ? ? ? ? "CameraName": "front_center_custom",

? ? ? ? ? ? "ImageType": 3,

? ? ? ? ? ? "Visible": true,

? ? ? ? ? ? "ImageSize": [480, 270],

? ? ? ? ? ? "CameraPosition": [0.0, 0.0, -2.5],

? ? ? ? ? ? "CameraRotation": [0.0, 0.0, 0.0]

? ? ? ? },

{

? ? "WindowID": 2,

? ? ? ? ? ? "CameraName": "front_center_custom",

? ? ? ? ? ? "ImageType": 5,

? ? ? ? ? ? "Visible": true,

? ? ? ? ? ? "ImageSize": [480, 270],

? ? ? ? ? ? "CameraPosition": [0.0, 0.0, -2.5],

? ? ? ? ? ? "CameraRotation": [0.0, 0.0, 0.0]

}

? ? ],

? ? "Vehicles": {

? ? "Drone": {

? ? ? ? "VehicleType": "SimpleFlight",

? ? ? ? "DisplayName": "My First Drone",

? ? ? ? "AutoCreate": true

}

? ? }

}

自己修改時(shí)注意窗口索引的正確性。

二、利用pygame繪制窗口并獲取無(wú)人機(jī)FPV實(shí)時(shí)圖像呈現(xiàn)

import sys
import time
import airsim
import pygame
import CV2
import numpy as np

# >------>>> ?pygame settings ? <<<------< #
pygame.init()

screen = pygame.display.set_mode((800, 144))
pygame.display.set_caption('screen')
screen.fill((0, 0, 0))

# >------>>> ?AirSim settings ? <<<------< #
# 這里改為你要控制的無(wú)人機(jī)名稱(settings文件里面設(shè)置的)
vehicle_name = "Drone"
AirSim_client = airsim.MultirotorClient()
AirSim_client.confirmConnection()
AirSim_client.enableApiControl(True, vehicle_name=vehicle_name)
AirSim_client.armDisarm(True, vehicle_name=vehicle_name)
AirSim_client.takeoffAsync(vehicle_name=vehicle_name).join()
image_types = {
? ?"scene": airsim.ImageType.Scene,
? ?"depth": airsim.ImageType.DepthVis,
? ?"seg": airsim.ImageType.Segmentation,
? ?"normals": airsim.ImageType.SurfaceNormals,
? ?"segmentation": airsim.ImageType.Segmentation,
? ?"disparity": airsim.ImageType.DisparityNormalized,
? ?"Infrared": airsim.ImageType.Infrared
}

# 基礎(chǔ)的控制速度(m/s)
vehicle_velocity = 2.0
# 設(shè)置臨時(shí)加速比例
speedup_ratio = 10.0
# 用來(lái)設(shè)置臨時(shí)加速
speedup_flag = False

# 基礎(chǔ)的偏航速率
vehicle_yaw_rate = 5.0

while True:
? ?yaw_rate = 0.0
? ?velocity_x = 0.0
? ?velocity_y = 0.0
? ?velocity_z = 0.0

? ?time.sleep(0.02)

? ?for event in pygame.event.get():
? ? ? ?if event.type == pygame.QUIT:
? ? ? ? ? ?sys.exit()

? ?scan_wrapper = pygame.key.get_pressed()

? ?# 按下空格鍵加速10倍
? ?if scan_wrapper[pygame.K_SPACE]:
? ? ? ?scale_ratio = speedup_ratio
? ?else:
? ? ? ?scale_ratio = speedup_ratio / speedup_ratio

? ?# 根據(jù) 'A' 和 'D' 按鍵來(lái)設(shè)置偏航速率變量
? ?if scan_wrapper[pygame.K_a] or scan_wrapper[pygame.K_d]:
? ? ? ?yaw_rate = (scan_wrapper[pygame.K_d] - scan_wrapper[pygame.K_a]) * scale_ratio * vehicle_yaw_rate

? ?# 根據(jù) 'UP' 和 'DOWN' 按鍵來(lái)設(shè)置pitch軸速度變量(NED坐標(biāo)系,x為機(jī)頭向前)
? ?if scan_wrapper[pygame.K_UP] or scan_wrapper[pygame.K_DOWN]:
? ? ? ?velocity_x = (scan_wrapper[pygame.K_UP] - scan_wrapper[pygame.K_DOWN]) * scale_ratio

? ?# 根據(jù) 'LEFT' 和 'RIGHT' 按鍵來(lái)設(shè)置roll軸速度變量(NED坐標(biāo)系,y為正右方)
? ?if scan_wrapper[pygame.K_LEFT] or scan_wrapper[pygame.K_RIGHT]:
? ? ? ?velocity_y = -(scan_wrapper[pygame.K_LEFT] - scan_wrapper[pygame.K_RIGHT]) * scale_ratio

? ?# 根據(jù) 'W' 和 'S' 按鍵來(lái)設(shè)置z軸速度變量(NED坐標(biāo)系,z軸向上為負(fù))
? ?if scan_wrapper[pygame.K_w] or scan_wrapper[pygame.K_s]:
? ? ? ?velocity_z = -(scan_wrapper[pygame.K_w] - scan_wrapper[pygame.K_s]) * scale_ratio

? ?# print(f": Expectation gesture: {velocity_x}, {velocity_y}, {velocity_z}, {yaw_rate}")

? ?# 設(shè)置速度控制以及設(shè)置偏航控制
? ?AirSim_client.moveByVelocityBodyFrameAsync(vx=velocity_x, vy=velocity_y, vz=velocity_z, duration=1,
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? yaw_mode=airsim.YawMode(True, yaw_or_rate=yaw_rate), vehicle_name=vehicle_name)

? ?temp_image1 = AirSim_client.simGetImage('0', image_types["scene"], vehicle_name=vehicle_name)
? ?image1 = CV2.imdecode(airsim.string_to_uint8_array(temp_image1), CV2.IMREAD_COLOR)
? ?CV2.imwrite('screen/visual1.png', image1)
? ?# 利用pygame庫(kù)加載保存的第一視角圖像,
? ?screen_image1 = pygame.image.load("screen/visual1.png")
? ?# 圖像坐標(biāo)系,左上角為(0, 0),在此放置圖片
? ?screen.blit(screen_image1, (0, 0))
? ?pygame.display.flip()
? ?pygame.display.update()

? ?temp_image2 = AirSim_client.simGetImage('0', image_types["Infrared"], vehicle_name=vehicle_name)
? ?image2 = CV2.imdecode(airsim.string_to_uint8_array(temp_image2), CV2.IMREAD_COLOR)
? ?CV2.imwrite('screen/visual2.png', image2)
? ?# 利用pygame庫(kù)加載保存的第一視角圖像,
? ?screen_image2 = pygame.image.load("screen/visual2.png")
? ?# 圖像坐標(biāo)系,左上角為(0, 0),在此放置圖片
? ?screen.blit(screen_image2, (272, 0))
? ?pygame.display.flip()
? ?pygame.display.update()

? ?temp_image3 = AirSim_client.simGetImage('0', image_types["segmentation"], vehicle_name=vehicle_name)
? ?image3 = CV2.imdecode(airsim.string_to_uint8_array(temp_image3), CV2.IMREAD_COLOR)
? ?CV2.imwrite('screen/visual3.png', image3)
? ?# 利用pygame庫(kù)加載保存的第一視角圖像,
? ?screen_image3 = pygame.image.load("screen/visual3.png")
? ?# 圖像坐標(biāo)系,左上角為(0, 0),在此放置圖片
? ?screen.blit(screen_image3, (544, 0))
? ?pygame.display.flip()
? ?pygame.display.update()

? ?if scan_wrapper[pygame.K_ESCAPE]:
? ? ? ?pygame.quit()
? ? ? ?sys.exit()


AirSim在UE4中運(yùn)行時(shí)顯示第一人稱捕獲圖像窗口——settings.json配置和pygame兩種方法的評(píng)論 (共 條)

分享到微博請(qǐng)遵守國(guó)家法律
花莲县| 萍乡市| 桐梓县| 图片| 莆田市| 温泉县| 根河市| 鱼台县| 莎车县| 韶关市| 个旧市| 神木县| 屯门区| 邳州市| 金华市| 广德县| 大田县| 巩义市| 宝丰县| 十堰市| 桐柏县| 曲阜市| 广宗县| 白沙| 新巴尔虎右旗| 玛纳斯县| 海淀区| 金秀| 右玉县| 青龙| 于田县| 博客| 资源县| 武夷山市| 高阳县| 蒙自县| 佳木斯市| 社会| 洛阳市| 崇州市| 井陉县|