From 2466175b5fcfc2ce3b1560739600cc1749d8a50d Mon Sep 17 00:00:00 2001 From: dehann Date: Fri, 22 Sep 2023 04:08:23 -0700 Subject: [PATCH 1/2] refac more ros code --- ext/Images/ROSImageConversion.jl | 25 ------------------------- src/Caesar.jl | 2 ++ src/ExportAPI.jl | 4 +++- src/services/ToImage.jl | 27 +++++++++++++++++++++++++++ 4 files changed, 32 insertions(+), 26 deletions(-) create mode 100644 src/services/ToImage.jl diff --git a/ext/Images/ROSImageConversion.jl b/ext/Images/ROSImageConversion.jl index a021d4f0a..139597f9c 100644 --- a/ext/Images/ROSImageConversion.jl +++ b/ext/Images/ROSImageConversion.jl @@ -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 diff --git a/src/Caesar.jl b/src/Caesar.jl index d756609a2..5949a51a8 100644 --- a/src/Caesar.jl +++ b/src/Caesar.jl @@ -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 diff --git a/src/ExportAPI.jl b/src/ExportAPI.jl index cfe9610e0..16ea95ed2 100644 --- a/src/ExportAPI.jl +++ b/src/ExportAPI.jl @@ -53,4 +53,6 @@ export packBlob, unpackBlob # imagedraw.jl export makeImage! -export drawKeypointsAndMask \ No newline at end of file +export drawKeypointsAndMask + +export toImage \ No newline at end of file diff --git a/src/services/ToImage.jl b/src/services/ToImage.jl new file mode 100644 index 000000000..c2aeb7717 --- /dev/null +++ b/src/services/ToImage.jl @@ -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 \ No newline at end of file From c60a550b5a43dd13f7215bd3bc5d25c44d7d7e3c Mon Sep 17 00:00:00 2001 From: dehann Date: Fri, 22 Sep 2023 04:11:27 -0700 Subject: [PATCH 2/2] refac toImage --- ext/CaesarImagesExt.jl | 7 ++----- ext/Images/ROSImageConversion.jl | 2 -- 2 files changed, 2 insertions(+), 7 deletions(-) delete mode 100644 ext/Images/ROSImageConversion.jl diff --git a/ext/CaesarImagesExt.jl b/ext/CaesarImagesExt.jl index 65c134131..839830e78 100644 --- a/ext/CaesarImagesExt.jl +++ b/ext/CaesarImagesExt.jl @@ -1,8 +1,5 @@ module CaesarImagesExt -@info "Loading Caesar tools related to Images.jl." - - using Images # using ImageTransformations using ColorVectorSpace @@ -28,7 +25,7 @@ import GeometricalPredicates as GeoPr import ApproxManifoldProducts: sample, _update! import IncrementalInference: getSample, preambleCache, _update!, getManifold -import Caesar: applyMaskImage, makeMaskImage, makeMaskImages, imhcatPretty, toImage +import Caesar: applyMaskImage, makeMaskImage, makeMaskImages, imhcatPretty import Caesar: writevideo, csmAnimationJoinImgs, csmAnimateSideBySide, makeVideoFromData import Caesar: overlayScanMatcher import Caesar: overlayScatter, overlayScatterMutate @@ -46,7 +43,7 @@ import Caesar: unionFeatureMountain, sortKeysMinSighting # NOTE usage requires ImageFeatures.jl import Caesar: curateFeatureTracks -include("Images/ROSImageConversion.jl") + include("Images/ImageMask.jl") include("Images/ImageToVideoUtils.jl") include("Images/ScanMatcherUtils.jl") diff --git a/ext/Images/ROSImageConversion.jl b/ext/Images/ROSImageConversion.jl deleted file mode 100644 index 139597f9c..000000000 --- a/ext/Images/ROSImageConversion.jl +++ /dev/null @@ -1,2 +0,0 @@ - -