Skip to content

Commit

Permalink
Merge pull request #53 from JuliaRobotics/feat/3Q20/drawimgtags
Browse files Browse the repository at this point in the history
add drawTags! and bump v0.7.4
  • Loading branch information
dehann authored Aug 21, 2020
2 parents 79f28d4 + 9637074 commit 88d771e
Show file tree
Hide file tree
Showing 6 changed files with 81 additions and 8 deletions.
3 changes: 2 additions & 1 deletion Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name = "AprilTags"
uuid = "f0fec3d5-a81e-5a6a-8c28-d2b34f3659de"
keywords = ["AprilTags", "fiducials", "markers"]
desc = "Visual fiducial marking system"
version = "0.7.3"
version = "0.7.4"

[deps]
ColorTypes = "3da002f7-5984-5a60-b8a6-cbb66c0b333f"
Expand All @@ -24,6 +24,7 @@ julia = "0.7, 1"

[extras]
FileIO = "5789e2e9-d7fb-5bc7-8068-2c6fae9b9549"
FreeTypeAbstraction = "663a7486-cb36-511b-a19d-713bb74d65c9"
ImageCore = "a09fc81d-aa75-5fe9-8630-4744c3626534"
ImageMagick = "6218d12a-5da1-5696-b52f-db25d2ecc6d1"
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"
Expand Down
25 changes: 25 additions & 0 deletions docs/src/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,31 @@ Eg. to create a tag image with id 1 from family 'tag36h11' run:
getAprilTagImage(1, AprilTags.tag36h11)
```

## Visualizing Tags

Images can be updated to include the tag detections,
```julia
drawTagBox!(image, tag)
```

Or if the camera matrix `K` is known, the axes can be shown with
```julia
drawTagAxes!(image, tag, K)
```

Furthermore, the tag IDs can also be visualized by first loading a different package:
```julia
using FreeTypeAbstraction
using AprilTags
using ImageView

# get an image
img_ = drawTags(image, K)
imshow(img_)

# drawTags!(image, K, tags)
```

## Manual Outline
```@contents
Pages = [
Expand Down
7 changes: 2 additions & 5 deletions src/AprilTags.jl
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,7 @@ function __init__()
isfile(depfile) ? include(depfile) : error("AprilTags.jl not properly installed. Please run: Pkg.build(\"AprilTags\")")

# conditional requirement
@require FreeTypeAbstraction="663a7486-cb36-511b-a19d-713bb74d65c9" begin
using .FreeTypeAbstraction
@info "AprilTags.jl is loading tagtext.jl conditioned on using FreeTypeAbstraction"
include("tagtext.jl")
end
@require FreeTypeAbstraction="663a7486-cb36-511b-a19d-713bb74d65c9" include("tagtext.jl")
end

using LinearAlgebra, Statistics
Expand Down Expand Up @@ -49,5 +45,6 @@ drawTagAxes!
include("wrapper.jl")
include("helpers.jl")
include("tagdraw.jl")
include("additionalutils.jl")

end # module
42 changes: 42 additions & 0 deletions src/additionalutils.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
# Functionality that may be loaded more than one

export drawTags!, drawTags


"""
drawTags!
Draw axes and tag IDs on an image based on detections in `tags`.
Notes
- Will self detect tags, or requires user to pass in `tags` detections.
"""
function drawTags!(imageCol::AbstractArray{<:AbstractRGB,2},
K::AbstractArray{<:Real,2},
tags::AbstractArray{AprilTag,1} = AprilTagDetector()(imageCol),
drawReticle::Bool = false )
#
# draw the tag number for each tag
if @isdefined(drawTagID!)
foreach(x->drawTagID!(imageCol, x),tags)
end
#draw color box on tag corners
foreach(tag->drawTagBox!(imageCol, tag, width = 2, drawReticle = drawReticle), tags)
foreach(tag->drawTagAxes!(imageCol,tag, K), tags)
imageCol
end

"""
drawTags
Draw axes and tag IDs on an image based on detections in `tags`.
Notes
- Will self detect tags, or requires user to pass in `tags` detections.
"""
drawTags(imageCol::AbstractArray{<:AbstractRGB,2},K::AbstractArray{<:Real,2},tags::AbstractArray{AprilTag,1}=AprilTagDetector()(imageCol),drawReticle::Bool=false ) = drawTags!(RGB.(imageCol),K,tags,drawReticle)
# Convert image to RGB
# imageCol = RGB.(image)


#
8 changes: 6 additions & 2 deletions src/tagdraw.jl
Original file line number Diff line number Diff line change
Expand Up @@ -97,8 +97,10 @@ Draw the tag x, y, and z axes to show the orientation.
foreach(tag->drawTagAxes!(imageCol, tag, K), tags)
`
"""
function drawTagAxes!(image::Array{T,2}, tag::AprilTag, K::Array{Float64,2}) where T <: RGB

function drawTagAxes!(image::AbstractArray{<:AbstractRGB,2},
tag::AprilTag,
K::AbstractArray{<:Real,2} )
#
Kp = [K [0;0]; 0.0 0.0 1.0 0.0]
pose = AprilTags.homography_to_pose(tag.H, K[1,1], K[2,2], K[1,3], K[2,3])

Expand Down Expand Up @@ -126,3 +128,5 @@ function drawTagAxes!(image::Array{T,2}, tag::AprilTag, K::Array{Float64,2}) whe
draw!(image, LineSegment(ip0, ip3), RGB{N0f8}(0.0, 0.0, 1.0), boundedBresenham)
image
end


4 changes: 4 additions & 0 deletions src/tagtext.jl
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# text and tags and images

using .FreeTypeAbstraction
@info "AprilTags.jl is loading tagtext.jl conditioned on using FreeTypeAbstraction"


export drawTagID!, drawTagNumber!

"""
Expand Down

0 comments on commit 88d771e

Please sign in to comment.