Skip to content

Instantly share code, notes, and snippets.

@tshort
Last active January 16, 2018 21:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tshort/4d1b3baf8e07c26c0d02bc7759f6e8fd to your computer and use it in GitHub Desktop.
Save tshort/4d1b3baf8e07c26c0d02bc7759f6e8fd to your computer and use it in GitHub Desktop.
Example of using Makie.jl to pick points off of an image with the mouse/keyboard

Run the Julia code below, and it'll pop up a window with an image. Select the window. Move the mouse around, and hit the f key. A red marker should appear.

I used the keyboard with the mouse because my application had several different features I wanted to pick out. You could adapt this to use the mouse buttons.

using Makie, FileIO, GeometryTypes, Colors, Images
scene = Scene(resolution = (500, 500), color = :black)
img = rand(RGB{N0f8}, 500, 500)
mimg = image(img)
scene[:keyboardbuttons] = lift_node(scene[:buttons_pressed]) do x
map(Keyboard.Button, x)
end
scene[:markers] = to_node(GeometryTypes.Point{2,Float32}[])
sc = scatter(scene[:markers], marker = :+, markersize = 20, color = RGBA(1,0,0, 0.8))
cam = scene[:screen].cameras[:orthographic_pixel]
s = lift_node(scene[:keyboardbuttons]) do keyset
# println(scene[:keyboardbuttons])
if ispressed(scene, Keyboard.f) # mark a point on the image
mp = scene[:mouseposition]
p = to_world(Point2f0(to_value(mp)), cam)
println(p)
scene[:markers] = push!(to_value(scene[:markers]), p)
elseif ispressed(scene, Keyboard.x) # do other stuff here...
end
nothing
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment