forked from clementfarabet/lua---camera
-
Notifications
You must be signed in to change notification settings - Fork 0
/
init.lua.in
56 lines (51 loc) · 1.95 KB
/
init.lua.in
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
----------------------------------
-- dependencies
----------------------------------
require 'sys'
require 'xlua'
----------------------------------
-- load camera driver based on OS
----------------------------------
useOpenCV = @useOpenCV@
if useOpenCV then
if not xlua.require 'camopencv' then
xlua.error('failed to load camopencv wrapper: verify that camopencv is installed')
end
elseif sys.OS == 'linux' then
if not xlua.require 'v4l' then
xlua.error('failed to load video4linux wrapper: verify that you have v4l2 libs')
end
elseif sys.OS == 'macos' then
if not xlua.require 'cammacos' then
xlua.error('failed to load cammacos wrapper: verify that cammacos is installed')
end
else
xlua.error('no camera driver available for your OS, sorry :-(')
end
----------------------------------
-- package a little demo
----------------------------------
camera = {}
camera.testme = function()
require 'qtwidget'
print '--------------------------------------------------'
print 'grabbing frames from your camera for about 10secs'
local cam = image.Camera{}
local w = camera._w
local fps = 0
for i = 1,200 do -- ~10 seconds
sys.tic()
local frame = cam:forward()
w = image.display{image=frame, win=w, legend='camera capture ['..fps..'fps]'}
w.window:show()
local t = sys.toc()
if fps == 0 then fps = 1/t end
fps = math.ceil((1/t + fps)/2)
end
cam:stop()
print 'done: create your own frame grabber with image.Camera()'
print '--------------------------------------------------'
camera._w = w
w.window:hide()
return w
end