Skip to content

Commit

Permalink
refac more ros code
Browse files Browse the repository at this point in the history
  • Loading branch information
dehann committed Sep 22, 2023
1 parent 69be612 commit 2466175
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 26 deletions.
25 changes: 0 additions & 25 deletions ext/Images/ROSImageConversion.jl
Original file line number Diff line number Diff line change
@@ -1,27 +1,2 @@


"""
$SIGNATURES
Also see: [`toROSImage`](@ref)
"""
function toImage(msgd::Dict{String,Any})
data = haskey(msgd, "data_b64") ? base64decode(msgd["data_b64"]) : UInt8.(msgd["data"])
h, w = msgd["height"], msgd["width"]
@show h, w, msgd["step"]
if msgd["encoding"] == "mono8" || msgd["encoding"] == "8UC1"
# img_ = normedview(N0f8, data)
# reshape(img_, w, h)'
img = Matrix{Gray{N0f8}}(undef, h, w)
# assuming one endian type for now, TODO both little and big endian
for i in 1:h, j in 1:w
img[i,j] = Gray{N0f8}(data[msgd["step"]*(i-1)+j]/(2^8 - 1))
end
img
elseif msgd["encoding"] == "mono16" || msgd["encoding"] == "16UC1"
img_ = normedview(N0f16, data)
reshape(img_, w, h)'
else
error("Conversion for ROS sensor_msgs.Image encoding not implemented yet $(msgd["encoding"])")
end
end
2 changes: 2 additions & 0 deletions src/Caesar.jl
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,8 @@ include("beamforming/MatchedFilter.jl")
include("beamforming/SASBearing2D.jl")
include("beamforming/SASUtils.jl")

include("services/ToImage.jl")

include("3rdParty/_PCL/_PCL.jl")

# object affordance work
Expand Down
4 changes: 3 additions & 1 deletion src/ExportAPI.jl
Original file line number Diff line number Diff line change
Expand Up @@ -53,4 +53,6 @@ export packBlob, unpackBlob

# imagedraw.jl
export makeImage!
export drawKeypointsAndMask
export drawKeypointsAndMask

export toImage
27 changes: 27 additions & 0 deletions src/services/ToImage.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@


"""
$SIGNATURES
Also see: [`PyCaesar.toROSImage`](@ref)
"""
function toImage(msgd::Dict{String,Any})
data = haskey(msgd, "data_b64") ? base64decode(msgd["data_b64"]) : UInt8.(msgd["data"])
h, w = msgd["height"], msgd["width"]
@show h, w, msgd["step"]
if msgd["encoding"] == "mono8" || msgd["encoding"] == "8UC1"
# img_ = normedview(N0f8, data)
# reshape(img_, w, h)'
img = Matrix{Gray{N0f8}}(undef, h, w)
# assuming one endian type for now, TODO both little and big endian
for i in 1:h, j in 1:w
img[i,j] = Gray{N0f8}(data[msgd["step"]*(i-1)+j]/(2^8 - 1))
end
img
elseif msgd["encoding"] == "mono16" || msgd["encoding"] == "16UC1"
img_ = normedview(N0f16, data)
reshape(img_, w, h)'
else
error("Conversion for ROS sensor_msgs.Image encoding not implemented yet $(msgd["encoding"])")
end
end

0 comments on commit 2466175

Please sign in to comment.