Parcourir la source

added depthimage-reader. Had to alter idlpython because (I think) python 2.7 code iso python 3 (in import)
The idlpython directory should be in your PYTHONPATH.

Result not very good. image seems inverted (wrt ROS image) and stream is very slow (image every 5-10 seconds) unlike ROS topic. Could not use cv-bridge zo mangled data myself to get 32 bit depthimage, and show it in opencv.

When I run Ubuntu in parallel the Windows Python image readers seems to slow down the Ubuntu reader too (??)

Edward Hage il y a 3 ans
Parent
commit
bd9eae7c4d

BIN
pythonDDS/idlpython/sensor_msgs/Image_/__pycache__/__init__.cpython-36.pyc


BIN
pythonDDS/idlpython/sensor_msgs/Image_/sensor_msgs/__pycache__/__init__.cpython-36.pyc


BIN
pythonDDS/idlpython/sensor_msgs/Image_/sensor_msgs/msg/__pycache__/__init__.cpython-36.pyc


+ 5 - 5
pythonDDS/idlpython/sensor_msgs/Image_/sensor_msgs/msg/dds_/__init__.py

@@ -1,6 +1,6 @@
 import dds
 import ddsutil
-import std_msgs/msg/Header_.std_msgs.msg.dds_
+import std_msgs.Header_.std_msgs.msg.dds_
 import struct
 
 class Image___TypeSupport(dds.TypeSupport):
@@ -42,7 +42,7 @@ class Image_(ddsutil.TopicDataClass):
         '''
         return self._header__
 
-    _header__checker = ddsutil._class_checker(std_msgs/msg/Header_.std_msgs.msg.dds_.Header_)
+    _header__checker = ddsutil._class_checker(std_msgs.Header_.std_msgs.msg.dds_.Header_)
     @header_.setter
     def header_(self, value):
         self._header__checker(value)
@@ -137,7 +137,7 @@ class Image_(ddsutil.TopicDataClass):
     def __init__(self, **kwargs):
         ''' Create a Image_ instance, optionally initializing fields by name '''
         # init attributes to default value
-        self.header_ = std_msgs/msg/Header_.std_msgs.msg.dds_.Header_()
+        self.header_ = std_msgs.Header_.std_msgs.msg.dds_.Header_()
         self.height_ = 0
         self.width_ = 0
         self.encoding_ = ''
@@ -158,7 +158,7 @@ class Image_(ddsutil.TopicDataClass):
         if Image_._packing_fmt is not None:
             return Image_._packing_fmt
         fmt = ''
-        fmt += ddsutil._align(fmt, std_msgs/msg/Header_.std_msgs.msg.dds_.Header_._get_packing_fmt())
+        fmt += ddsutil._align(fmt, std_msgs.Header_.std_msgs.msg.dds_.Header_._get_packing_fmt())
         fmt += 'I'
         fmt += 'I'
         fmt += 'P'
@@ -178,7 +178,7 @@ class Image_(ddsutil.TopicDataClass):
 
     def _deserialize(self, data):
         ''' Initialize values from data returned by struct.unpack()'''
-        self.header_ = std_msgs/msg/Header_.std_msgs.msg.dds_.Header_()._deserialize(data)
+        self.header_ = std_msgs.Header_.std_msgs.msg.dds_.Header_()._deserialize(data)
         self.height_ = data.pop(0)
         self.width_ = data.pop(0)
         self.encoding_ = ddsutil._ptr_to_bytes(data.pop(0)).decode('ISO-8859-1')

BIN
pythonDDS/idlpython/sensor_msgs/Image_/sensor_msgs/msg/dds_/__pycache__/__init__.cpython-36.pyc


BIN
pythonDDS/idlpython/std_msgs/Header_/__pycache__/__init__.cpython-36.pyc


BIN
pythonDDS/idlpython/std_msgs/Header_/std_msgs/__pycache__/__init__.cpython-36.pyc


BIN
pythonDDS/idlpython/std_msgs/Header_/std_msgs/msg/__pycache__/__init__.cpython-36.pyc


+ 5 - 5
pythonDDS/idlpython/std_msgs/Header_/std_msgs/msg/dds_/__init__.py

@@ -1,4 +1,4 @@
-import builtin_interfaces/msg/Time_.builtin_interfaces.msg.dds_
+import builtin_interfaces.Time_.builtin_interfaces.msg.dds_
 import dds
 import ddsutil
 import struct
@@ -42,7 +42,7 @@ class Header_(ddsutil.TopicDataClass):
         '''
         return self._stamp__
 
-    _stamp__checker = ddsutil._class_checker(builtin_interfaces/msg/Time_.builtin_interfaces.msg.dds_.Time_)
+    _stamp__checker = ddsutil._class_checker(builtin_interfaces.Time_.builtin_interfaces.msg.dds_.Time_)
     @stamp_.setter
     def stamp_(self, value):
         self._stamp__checker(value)
@@ -67,7 +67,7 @@ class Header_(ddsutil.TopicDataClass):
     def __init__(self, **kwargs):
         ''' Create a Header_ instance, optionally initializing fields by name '''
         # init attributes to default value
-        self.stamp_ = builtin_interfaces/msg/Time_.builtin_interfaces.msg.dds_.Time_()
+        self.stamp_ = builtin_interfaces.Time_.builtin_interfaces.msg.dds_.Time_()
         self.frame_id_ = ''
         # set values for attributes passed in
         for key, value in kwargs.items():
@@ -83,7 +83,7 @@ class Header_(ddsutil.TopicDataClass):
         if Header_._packing_fmt is not None:
             return Header_._packing_fmt
         fmt = ''
-        fmt += ddsutil._align(fmt, builtin_interfaces/msg/Time_.builtin_interfaces.msg.dds_.Time_._get_packing_fmt())
+        fmt += ddsutil._align(fmt, builtin_interfaces.Time_.builtin_interfaces.msg.dds_.Time_._get_packing_fmt())
         fmt += 'P'
 
         Header_._packing_fmt = ddsutil._pad_fmt(fmt)
@@ -98,7 +98,7 @@ class Header_(ddsutil.TopicDataClass):
 
     def _deserialize(self, data):
         ''' Initialize values from data returned by struct.unpack()'''
-        self.stamp_ = builtin_interfaces/msg/Time_.builtin_interfaces.msg.dds_.Time_()._deserialize(data)
+        self.stamp_ = builtin_interfaces.Time_.builtin_interfaces.msg.dds_.Time_()._deserialize(data)
         self.frame_id_ = ddsutil._ptr_to_bytes(data.pop(0)).decode('ISO-8859-1')
         return self;
 

BIN
pythonDDS/idlpython/std_msgs/Header_/std_msgs/msg/dds_/__pycache__/__init__.cpython-36.pyc


Fichier diff supprimé car celui-ci est trop grand
+ 3350 - 0
pythonDDS/ospl-info.log


+ 71 - 0
pythonDDS/read_depthimage.py

@@ -0,0 +1,71 @@
+# -*- coding: utf-8 -*-
+"""
+Created on 23 Jan 2022
+
+@author: Edward Hage
+"""
+
+import numpy as np
+import cv2
+import struct
+
+from dds import Listener, DomainParticipant, Topic, QosProvider, Qos
+from dds import PresentationQosPolicy, PartitionQosPolicy, DDSPresentationAccessScopeKind, DurabilityQosPolicy,DDSDurabilityKind
+from idlpython.sensor_msgs.Image_.sensor_msgs.msg.dds_ import Image___TypeSupport
+
+class ImageReader():
+   
+    class ImageListener(Listener):
+        
+        def __init__(self):
+            Listener.__init__(self)
+    
+        def on_data_available(self, entity):
+            l = entity.take(1)
+          
+            for (sd, si) in l:
+                current_frame = self.convert(sd)
+                
+                clipmin = 0.3
+                clipmax = 2.0
+                
+                new_frame = current_frame.copy()
+                np.clip(new_frame, clipmin, clipmax, out=new_frame)
+                new_frame -= clipmin
+                new_frame /= (clipmax-clipmin)/255.0
+                new_frame = new_frame.astype(dtype=np.uint8, copy=False)
+
+                im_color = cv2.applyColorMap(new_frame, cv2.COLORMAP_AUTUMN)
+              
+                cv2.imshow("camera", current_frame) # of new_frame
+                cv2.waitKey(1) # 1 for automatic update
+        
+        def convert(self, img_msg):
+            # dtype, n_channels = "32F", 1 # hardcoded data from Unity
+            # dtype = np.dtype(dtype)
+            # dtype = dtype.newbyteorder('>' if img_msg.is_bigendian_ else '<')
+            # print( dtype)
+            # print("totsize = " + str(len(img_msg.data_)) + "  height = " + str(img_msg.height_) + " width " + str(img_msg.width_))
+            
+            dt = np.dtype('float32')
+            dt = dt.newbyteorder('<')
+            #im = np.ndarray(shape=(img_msg.height_, img_msg.width_, 1), dtype = 'float32', buffer = bytearray(img_msg.data_))
+            
+            im = np.ndarray(shape=(img_msg.height_, img_msg.width_, 1), dtype = dt, buffer = bytearray(img_msg.data_))
+            return im
+
+    listener = ImageListener()
+    
+    def __init__(self, topicname):
+        qp = QosProvider('file://DDS_ROSQoS.xml', 'DDS ROSQosProfile')
+        dp = DomainParticipant(qos = qp.get_participant_qos())
+        sub = dp.create_subscriber(Qos([PresentationQosPolicy(DDSPresentationAccessScopeKind.INSTANCE, False, False), 
+                                      PartitionQosPolicy(['']),
+                                      DurabilityQosPolicy(DDSDurabilityKind.VOLATILE)]))
+        topic = Topic(dp, topicname, Image___TypeSupport(), qp.get_topic_qos(), None)
+        self.reader = sub.create_datareader(topic, qp.get_reader_qos(), self.listener)
+
+reader = ImageReader("rt/depth_image") 
+
+input("Press a key to stop ...")
+

+ 11 - 0
pythonDDS/start_read_image.bat

@@ -0,0 +1,11 @@
+@echo off
+echo Setting paths for Vortex OpenSplice ..
+if "%SPLICE_ORB%"=="" set SPLICE_ORB=DDS_OpenFusion_1_6_1
+set OSPL_HOME=D:\HDE\x86_64.win64
+set PATH=%OSPL_HOME%\bin;%OSPL_HOME%\lib;%OSPL_HOME%\examples\lib;%PATH%
+set OSPL_TMPL_PATH=%OSPL_HOME%\etc\idlpp
+if "%OSPL_URI%"=="" set OSPL_URI=file://%OSPL_HOME%\etc\config\ospl_sp_ddsi_1gbps.xml
+python "read_depthimage.py"
+
+
+