@@ -40,22 +40,33 @@ function unmarshal(
4040end
4141
4242
43- function toImage (msgd:: Dict{String,Any} )
44- data = base64decode (msgd[" data_b64" ])
45- h, w = msgd[" height" ], msgd[" width" ]
46-
47- if msgd[" encoding" ] == " mono8"
48- img = Matrix {Gray{N0f8}} (undef, h, w)
49- # assuming one endian type for now, TODO both little and big endian
50- for i in 1 : h, j in 1 : w
51- img[i,j] = Gray {N0f8} (data[msgd[" step" ]* (i- 1 )+ j]/ 255 )
52- end
53- img
54- else
55- error (" Conversion for ROS sensor_msgs.Image encoding not implemented yet $(msgd[" encoding" ]) " )
56- end
57- end
58-
5943toImage (msg:: Main.sensor_msgs.msg.Image ) = unmarshal (msg) |> toImage
6044
45+
46+ """
47+ $SIGNATURES
48+
49+ Convert `Caesar.Image::Dict` type to ROS message `sensor_msgs.msg.Image`.
50+
51+ See also: [`Caesar.unmarshal`](@ref), [`Caesar.toImage`](@ref), [`Caesar._PCL.toROSPointCloud2`](@ref)
52+ """
53+ function toROSImage (msgd:: Dict{String,Any} )
54+ header = Main. std_msgs. msg. Header ();
55+ header. seq = msgd[" header" ][" seq" ]
56+ header. stamp = RobotOS. Time (msgd[" header" ][" stamp" ][" secs" ], msgd[" header" ][" stamp" ][" nsecs" ])
57+ header. frame_id = msgd[" header" ][" frame_id" ]
58+
59+ msg = Main. sensor_msgs. msg. Image ();
60+
61+ msg. header = header
62+ msg. height = UInt32 (msgd[" height" ])
63+ msg. width = UInt32 (msgd[" width" ])
64+
65+ msg. is_bigendian = UInt8 (msgd[" is_bigendian" ])
66+ msg. step = UInt32 (msgd[" step" ])
67+ msg. data = base64decode (msgd[" data_b64" ])
68+ msg. encoding = msgd[" encoding" ]
69+
70+ msg
71+ end
6172#
0 commit comments