Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

draw tag text #50

Merged
merged 8 commits into from
Aug 19, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ os:
dist: xenial
julia:
- 1.0
- 1.1
- 1.5
- nightly
notifications:
email: false
Expand Down
4 changes: 3 additions & 1 deletion Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,16 @@ name = "AprilTags"
uuid = "f0fec3d5-a81e-5a6a-8c28-d2b34f3659de"
keywords = ["AprilTags", "fiducials", "markers"]
desc = "Visual fiducial marking system"
version = "0.7.2"
version = "0.7.3"

[deps]
ColorTypes = "3da002f7-5984-5a60-b8a6-cbb66c0b333f"
Colors = "5ae59095-9a9b-59fe-a467-6f913c188581"
FixedPointNumbers = "53c48c17-4a7d-5ca2-90c5-79b7896eea93"
ImageDraw = "4381153b-2b60-58ae-a1ba-fd683676385f"
Libdl = "8f399da3-3557-5675-b5ff-fb832c97cbdb"
LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
Requires = "ae029012-a4dd-5104-9daa-d747884805df"
Statistics = "10745b16-79ce-11e8-11f9-7d13ad32a3b2"

[compat]
Expand Down
9 changes: 9 additions & 0 deletions src/AprilTags.jl
Original file line number Diff line number Diff line change
@@ -1,9 +1,18 @@
__precompile__()
module AprilTags

using Requires

function __init__()
depfile = joinpath(dirname(@__FILE__),"../deps/loadpath.jl")
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
end

using LinearAlgebra, Statistics
Expand Down
31 changes: 31 additions & 0 deletions src/tagtext.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# text and tags and images

export drawTagID!, drawTagNumber!

"""
drawTagNumber!(::Array{<:RGB,2},::AprilTag,face=FTFont(..);sz::Float64=0.6)

Draw on array image the tag number at center of each tag with size scaling `sz`.

Example
```julia
foreach(tag->drawTagNumber!(imageCol, tag)
```
"""
function drawTagNumber!(image::Array{<:RGB,2},
tag::AprilTag,
face=FTFont(joinpath(dirname(dirname(pathof(FreeTypeAbstraction))),"test","hack_regular.ttf") );
sz::Float64=0.6 )
#
pminx = round(Int, minimum((x->x[1]).(tag.p)) )
pminy = round(Int, minimum((x->x[2]).(tag.p)) )
pmaxx = round(Int, maximum((x->x[1]).(tag.p)) )
pmaxy = round(Int, maximum((x->x[2]).(tag.p)) )
centx = round(Int,0.5*(pmaxx+pminx))
centy = round(Int,0.5*(pmaxy+pminy))
text = "$(tag.id)"
szz = round(Int, sz*6.0/(length(text)+10.0)*(pmaxx-pminx+pmaxy-pminy))
renderstring!(image, text, face, szz, centy,centx, halign=:hcenter,valign=:vcenter)
end

const drawTagID! = drawTagNumber!