Skip to content

Instantly share code, notes, and snippets.

@SimonDanisch
Created September 11, 2014 19:19
Show Gist options
  • Save SimonDanisch/fa3993176a015215092c to your computer and use it in GitHub Desktop.
Save SimonDanisch/fa3993176a015215092c to your computer and use it in GitHub Desktop.
import VideoIO
using GLPlot, React, GLAbstraction
device = VideoIO.DEFAULT_CAMERA_DEVICE
format = VideoIO.DEFAULT_CAMERA_FORMAT
camera = VideoIO.opencamera(device, format)
img = VideoIO.read(camera)
# Just for fun, lets apply a laplace filter:
kernel = [-1 -1 -1;
-1 8 -1;
-1 -1 -1]
#async=true, for REPL use. Then you don't have to call renderloop(window)
window = createdisplay(#=async=true =#)
img = glplot(Texture(img, 3), kernel=kernel, filternorm=0.1f0)
#Get Gpu memory object
glimg = img.uniforms[:image]
#Asynchronous updating with React:
lift(Timing.fpswhen(window.inputs[:open], 30.0)) do x
newframe = VideoIO.read(camera)
update!(glimg, mapslices(reverse, newframe, 3)) # needs to be mirrored :(
end
renderloop(window)
@jakebolewski
Copy link

Cool! The image only fills up the lower left 1/4 of the window for me. Also, you really need to at least register all of your packages 😉

@maxruby
Copy link

maxruby commented Sep 13, 2014

Thanks for the code. I tried it and found it works on my Mac OSX. However, for those new to ffmpeg, I should note that at least on my laptop (Norwegian), the VideoIO.DEFAULT_CAMERA_DEVICE is not properly set by the VideoIO routine from Tim.

First, after installing ffmpeg I checked the following in the bash console
ffmpeg -f avfoundation -list_devices true -i ""

This showed that the "Innebygd iSight" (built-in iSight) was the camera available.
Second, I tested that this device can indeed acquire a stream directly via ffmpeg:
ffmpeg -f avfoundation -i "Integrated" out.mpg

With this information, I changed line 5 of your code to ensure that it works.
device = "Innebygd iSight"

I noticed that the color and image are not what I normally see with the iSight camera. I assume that this is because the format is not set right, but I am not sure what I should change there?

@maxruby
Copy link

maxruby commented Sep 13, 2014

In case it was not clear, the image looked strange before the Laplacian was applied in your code (during testing). I will try again and see whether it is something in my setup.

@SimonDanisch
Copy link
Author

Interesting..
Did you try VideoIO.viewcam(), to verify if its my opengl code, or VideoIO ?
@jakebolewski can you post your specs, settings, and the way you execute the code to:
SimonDanisch/GLPlot#8
This issue gets on my nerve, but I can't reproduce it neither on windows nor ubuntu, so it's a little bit like a ghost hunt to me...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment