AirSim Image data processing in Simulink

2 次查看(过去 30 天)
Hi,
I’m trying to do an autonomous landing exercise using Airsim and Simulink (connected via a ROS network). I have set up the environment and have managed to get image data to MATLAB using a script. However, when I do this in MATLAB, I do get an image with colours inverted. (orange goes to blue etc which is not an issue for me right now). When I try to do it in Simulink using ROS subscriber, Read Image and Video Viewer blocks the image turns out to be black. I’m looking at an image of 240H x 320W and the image topic does give out 240x320x3=230400 to match the RGB image. When I took the data directly from the subscriber block in Simulink only 128 data points are given. I need to convert the image given by Airsim to a HxWx3 array so it can be processed by my target detecting algorithm. Has anyone come across this issue? Or is there a better way to do it? Please help
This is the Python API used to get the image:
import setup_path
import airsim
import rospy
# ROS Image message
from sensor_msgs.msg import Image
def airpub():
pub = rospy.Publisher("airsim/image_raw", Image, queue_size=1)
rospy.init_node('image_raw', anonymous=True)
rate = rospy.Rate(10) # 10hz
# connect to the AirSim simulator
client = airsim.MultirotorClient()
client.confirmConnection()
while not rospy.is_shutdown()
responses = client.simGetImages([
airsim.ImageRequest("0", airsim.ImageType.Scene,False,False)]) #scene vision image in uncompressed RGB array
response = responses[0]
for response in responses:
img_rgb_string = response.image_data_uint8
# Populate image message
msg=Image()
msg.header.stamp = rospy.Time.now()
msg.header.frame_id = "frameId"
msg.encoding = "rgb8"
msg.height = 240 # resolution should match values in settings.json
msg.width = 320
msg.data = img_rgb_string
msg.is_bigendian = 0
msg.step = msg.width * 1
# log time and size of published image
rospy.loginfo(len(response.image_data_uint8))
# publish image message
pub.publish(msg)
# sleep until next cycle
rate.sleep()
if __name__ == '__main__':
try:
airpub()
except rospy.ROSInterruptException:
pass

回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Specialized Messages 的更多信息

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by