SBWO/cam_test.jl

79 lines
1.8 KiB
Julia

using CondaPkg
using PythonCall
using Images
using ImageView
import VideoIO
using GLMakie
##
VideoIO.TestVideos.available()
videoFile = VideoIO.TestVideos.testvideo("black_hole")
VideoIO.playvideo(videoFile)
close(videoFile)
##
cam = VideoIO.opencamera("/dev/video0")
img = read(cam)
# @show VideoIO.framerate(cam)
# cam |> close
try
img = read(cam)
obs_img = GLMakie.Observable(GLMakie.rotr90(img))
scene = GLMakie.Scene(camera=GLMakie.campixel!, resolution=reverse(size(img)))
GLMakie.image!(scene, obs_img)
display(scene)
fps = VideoIO.framerate(cam)
while GLMakie.isopen(scene)
img = read(cam)
obs_img[] = GLMakie.rotr90(img)
sleep(1 / fps)
end
finally
close(cam)
end
##
cam = VideoIO.opencamera("/dev/video0")
imgstack = []
secrec = 1
frames = 30*secrec
framecounter = 0
fps = VideoIO.framerate(cam)
try
# read the first image in start
img = read(cam)
obs_img = GLMakie.Observable(GLMakie.rotr90(img))
scene = GLMakie.Scene(camera=GLMakie.campixel!, size=reverse(size(img)))
# set the first image on screen of Makie window
GLMakie.image!(scene, obs_img)
# display the GLMakie scene
display(scene)
# until the window is open
i = 0
while GLMakie.isopen(scene)
# read from camera
img = read(cam)
# we can process our image here
# you should comment below 4 lines if don't wanna save
# img = process(img)
# push!(imgstack, img)
# framecounter = framecounter + 1
# if(framecounter == frames) break end
# update image in the window
# obs_img[] = GLMakie.rotr90(img)
# delay to achieve right framerate
# also when you don't delay, it ends up hanging everything as
# it's a while loop with no control and huge number of reads.
sleep(1e-6)
end
finally
close(cam)
end