# GLMakie Method error (Makie.image!)

**URL:** <https://discourse.julialang.org/t/glmakie-method-error-makie-image/63090>\
**Category:** Visualization\
**Created:** [June 17, 2021, 2:03pm UTC](https://discourse.julialang.org/t/glmakie-method-error-makie-image/63090 "2021-06-17T14:03:38Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![Jake](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jake/32/46007_2.png) [@Jake](https://discourse.julialang.org/u/Jake)\
**Post date:** [June 17, 2021, 2:03pm UTC](https://discourse.julialang.org/t/glmakie-method-error-makie-image/63090/1 "2021-06-17T14:03:38Z")

</div>

I am trying to duplicate the [example](https://juliaio.github.io/VideoIO.jl/stable/reading/#Video-Playback) on the VideoIO github page that uses Makie. My code is very similar to this example but using some cell phone video from a Blackberry Key2.

```julia
using VideoIO
using GLMakie

path = string(homedir(), "\\OneDrive\\DanielShare\\Muskogee\\motion video")
cd(path)
f = VideoIO.openvideo("MOV_20210608_1540366.mp4")

img = read(f)
scene = Makie.Scene(resolution = reverse(size(img)))
makieimg = Makie.image!(scene, img, show_axis = false, scale_plot = true)[end]
Makie.rotate!(scene, -1pi)
display(scene)

while !eof(f)
	read!(f, img)
	makieimg[1] = img
	sleep(1/f.framerate)
end

```

This gives me the error message:

```julia
julia> includet("reviewmovie.jl")
ERROR: MethodError: no method matching lastindex(::Image{Tuple{IntervalSets.ClosedInterval{Float32}, IntervalSets.ClosedInterval{Float32}, Matrix{ColorTypes.RGB{Float32}}}})
Closest candidates are:
  lastindex(::Any, ::Any) at abstractarray.jl:348
  lastindex(::Union{ArrayInterface.BidiagonalIndex, ArrayInterface.TridiagonalIndex, ArrayInterface.BandedBlockBandedMatrixIndex, ArrayInterface.BandedMatrixIndex, ArrayInterface.BlockBandedMatrixIndex}) at C:\Users\jakez\.julia\packages\ArrayInterface\CYf5x\src\array_index.jl:203
  lastindex(::Union{Tables.AbstractColumns, Tables.AbstractRow}) at C:\Users\jakez\.julia\packages\Tables\YzCZp\src\Tables.jl:173
  ...
Stacktrace:
 [1] top-level scope
   @ C:\Users\jakez\OneDrive\DanielShare\Muskogee\motion video\reviewmovie.jl:10
in expression starting at C:\Users\jakez\OneDrive\DanielShare\Muskogee\motion video\reviewmovie.jl:10

julia>

```

Your ideas are appreciated.

---

<div class="post-metadata">

**Author:** ![Jake](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jake/32/46007_2.png) [@Jake](https://discourse.julialang.org/u/Jake)\
**Post date:** [June 17, 2021, 6:53pm UTC](https://discourse.julialang.org/t/glmakie-method-error-makie-image/63090/2 "2021-06-17T18:53:31Z")

</div>

I tried again with an exact duplicate of the sample program from VideoIO and get the same error.

The program used is below with the command Makie.image! causing the problem.

```julia
import Makie
import VideoIO

#io = VideoIO.open(video_file)
io = VideoIO.testvideo("annie_oakley") # for testing purposes
f = VideoIO.openvideo(io)

img = read(f)
scene = Makie.Scene(resolution = reverse(size(img)))
makieimg = Makie.image!(scene, img, show_axis = false, scale_plot = true)[end]
Makie.rotate!(scene, -0.5pi)
display(scene)

while !eof(f)
    read!(f, img)
    makieimg[1] = img
    sleep(1/f.framerate)
end

```

---

<div class="post-metadata">

**Author:** ![sdanisch](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/sdanisch/32/1406_2.png) [@sdanisch](https://discourse.julialang.org/u/sdanisch)\
**Post date:** [June 17, 2021, 6:59pm UTC](https://discourse.julialang.org/t/glmakie-method-error-makie-image/63090/3 "2021-06-17T18:59:52Z")

</div>

The example is outdated 😉 I’m not at a pc, but it should be easy to update the syntax with the docs!

---

<div class="post-metadata">

**Author:** ![Jake](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jake/32/46007_2.png) [@Jake](https://discourse.julialang.org/u/Jake)\
**Post date:** [June 17, 2021, 7:20pm UTC](https://discourse.julialang.org/t/glmakie-method-error-makie-image/63090/4 "2021-06-17T19:20:06Z")

</div>

I have to confess that this is my first use of Makie and VideoIO. I am looking through the docs, but nothing obvious yet.

---

<div class="post-metadata">

**Author:** ![Jake](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jake/32/46007_2.png) [@Jake](https://discourse.julialang.org/u/Jake)\
**Post date:** [June 17, 2021, 8:26pm UTC](https://discourse.julialang.org/t/glmakie-method-error-makie-image/63090/5 "2021-06-17T20:26:51Z")

</div>

Just experimenting here, if I create a tuple I can index into it as follows:

```julia
julia> a = (1, "a", 3.4)
(1, "a", 3.4)

julia> a[1]
1

julia> a[2]
"a"

julia> a[3]
3.4

julia> a[end]
3.4

julia> a[begin]
1

```

Then if I run a portion of the example code

```julia
import Makie
import VideoIO

#io = VideoIO.open(video_file)
io = VideoIO.testvideo("annie_oakley") # for testing purposes
f = VideoIO.openvideo(io)

img = read(f)
scene = Makie.Scene(resolution = reverse(size(img)))
makieimg = Makie.image!(scene, img, show_axis = false, scale_plot = true)

```

Note the [end] has been removed from the last line, this portion of the code runs. I can index into makieimg with digits within the square brackets but not with makieimg[end] or makieimg[begin]. If I run the remaining lines before the while loop nothing displays on my laptop but an image displays on another laptop. Mine is running Julia 1.6.1 and the other is 1.6.0, otherwise they are the same. The while loop does not run on either machine.

---

<div class="post-metadata">

**Author:** ![lazarusA](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/lazarusa/32/6571_2.png) [@lazarusA](https://discourse.julialang.org/u/lazarusA)\
**Post date:** [June 17, 2021, 8:34pm UTC](https://discourse.julialang.org/t/glmakie-method-error-makie-image/63090/6 "2021-06-17T20:34:04Z")

</div>

please take a look at the current documentation of Makie.  
[http://makie.juliaplots.org/stable/index.html](http://makie.juliaplots.org/stable/index.html)

Scene is not longer the proper way of doing it. Probably, something like this will help

```julia
fig = Figure()
makieImg = image!(fig[1,1], img)
fig

```

---

<div class="post-metadata">

**Author:** ![Jake](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jake/32/46007_2.png) [@Jake](https://discourse.julialang.org/u/Jake)\
**Post date:** [June 19, 2021, 11:09pm UTC](https://discourse.julialang.org/t/glmakie-method-error-makie-image/63090/7 "2021-06-19T23:09:07Z")

</div>

I now have code that runs but eats up CPU cycles and memory. The code I now have is

```julia
using GLMakie
using VideoIO

io = VideoIO.testvideo("annie_oakley") # for testing purposes
f = VideoIO.openvideo(io)

img = read(f)
fig = Figure()
ax = Axis(fig[1,1], aspect = DataAspect())
hidedecorations!(ax)

makieimg = image!(rotr90(img))

framerate = 30
i = 0
while !eof(f)
    i += 1
    print("Frame $i\r")
    read!(f, img)
    makieimg = image!(rotr90(img))
    sleep(1/framerate)
end

```

when I look at the memory used after I run the program I obtain:

```julia
julia> varinfo()
  name size summary

  –––––––––––––––– ––––––––––– –––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––
  Base Module

  Core Module

  InteractiveUtils 272.678 KiB Module

  Main Module

  ans 0 bytes typeof(varinfo)

  ax 801.817 MiB Axis

  f 1.440 KiB VideoIO.VideoReader{true, VideoIO.SwsTransform, String}
  fig 801.817 MiB Figure
  framerate 8 bytes Int64
  i 8 bytes Int64
  img 225.047 KiB 240×320 PermutedDimsArray(::Array{RGB{N0f8},2}, (2, 1)) with eltype ColorTypes.RGB{FixedPointNumbers.N0f8}
  io 1.440 KiB VideoIO.AVInput{String}
  makieimg 801.817 MiB Image{Tuple{IntervalSets.ClosedInterval{Float32}, IntervalSets.ClosedInterval{Float32}, Matrix{ColorTypes.RGB{Float32}}}}
  subtypetree 0 bytes typeof(subtypetree)

julia>

```

Watching the task manager the memory consumption increases while the code is running. Watching the video as it progresses, the framerate decreases. When I play a cellphone video, the program totally stalls. I am sure there is a more efficient way of doing things, some help is appreciated.

---

<div class="post-metadata">

**Author:** ![lazarusA](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/lazarusa/32/6571_2.png) [@lazarusA](https://discourse.julialang.org/u/lazarusA)\
**Post date:** [June 20, 2021, 8:35am UTC](https://discourse.julialang.org/t/glmakie-method-error-makie-image/63090/8 "2021-06-20T08:35:33Z")

</div>

You should use Nodes, e.g.

imgNode = Node(img)  
then in your loop, you call something like

`imgNode[] = read(f, img)`

this should just update your figure… I didn’t tested but something like that should work.  
[http://makie.juliaplots.org/stable/animation.html#Animations](http://makie.juliaplots.org/stable/animation.html#Animations)

---

<div class="post-metadata">

**Author:** ![Jake](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jake/32/46007_2.png) [@Jake](https://discourse.julialang.org/u/Jake)\
**Post date:** [June 21, 2021, 4:40pm UTC](https://discourse.julialang.org/t/glmakie-method-error-makie-image/63090/9 "2021-06-21T16:40:16Z")

</div>

That was most helpful. I now have something that does not eat memory! The only thing currently missing is a foolproof way to get the framerate from the file. In the past it would have been f.framerate according to the demo code on the github VideoIO page but that seems not to work anymore. I have a workaround that works in some cases.  
My current code is:

```julia
using GLMakie
using VideoIO
using Printf

#filename = "MOV_20210607_1540323.mp4"
#f = VideoIO.openvideo(filename)
io = VideoIO.testvideo("annie_oakley") # for testing purposes
f = VideoIO.openvideo(io)

framerate = 0.0
try
    framerate = VideoIO.get_number_frames(filename) / VideoIO.get_duration(filename)
    println("Using calculated framerate of $framerate")
catch
    framerate = 30.0
    println("Using default framerate of $framerate")
end
@show(framerate)
img = read(f)
fig = Figure()
ax = Axis(fig[1,1], aspect = DataAspect())
hidedecorations!(ax)
node = Node(rotr90(img))

makieimg = image!(node)

i = 0
while !eof(f)
    i += 1
    print("Frame $i\r")
    read!(f, img)
    node[] = rotr90(img)
    save(@sprintf("test_%04d.png", i) , fig.scene)
    sleep(1/framerate)
end

```

Thank you very much for your help!

Edit: minor correction and added a line to save every frame to a png file.

---

<div class="post-metadata">

**Author:** ![Jake](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jake/32/46007_2.png) [@Jake](https://discourse.julialang.org/u/Jake)\
**Post date:** [June 29, 2021, 1:22pm UTC](https://discourse.julialang.org/t/glmakie-method-error-makie-image/63090/10 "2021-06-29T13:22:14Z")

</div>

One more minor correction, the first line after try should read

```julia
framerate = (VideoIO.get_number_frames(filename) - 1) / VideoIO.get_duration(filename)

```
