# Use the homography matrix from Apriltag

**URL:** <https://discourse.julialang.org/t/use-the-homography-matrix-from-apriltag/114824>\
**Category:** Signal and Image Processing\
**Created:** [May 28, 2024, 9:38am UTC](https://discourse.julialang.org/t/use-the-homography-matrix-from-apriltag/114824 "2024-05-28T09:38:43Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![yakir12](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/yakir12/32/297_2.png) [@yakir12](https://discourse.julialang.org/u/yakir12)\
**Post date:** [May 28, 2024, 9:38am UTC](https://discourse.julialang.org/t/use-the-homography-matrix-from-apriltag/114824/1 "2024-05-28T09:38:43Z")

</div>

This is just to share a piece of a code that might prove useful for someone.

If you want to use the homography matrix from a detected Apriltag (such as the ones from [Apriltags.jl](https://github.com/JuliaRobotics/AprilTags.jl)), in order to convert from pixel coordinates to the 1 to 10 indices of the bit array of a `tag36h11` tag, this can help:

```julia
using StaticArrays, CoordinateTransformations

push1(x) = CoordinateTransformations.push(x, 1)

function get_transform(H)
    s = 3.5
    scale = inv(SDiagonal(s, s, 1))
    M = LinearMap(SMatrix{3,3, Float64}(H * scale))
    trans = Translation(-4.5, -4.5)
    return reverse ∘ PerspectiveMap() ∘ M ∘ push1 ∘ trans ∘ reverse
end

```

Where `H` is the homography matrix.
