summaryrefslogtreecommitdiff
path: root/test/lua/capture.lua
blob: 491518adaa40b6fb42ff909e4926104680cb712a (plain)
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
57
58
59
60
61
62
63
require"imlua"
require"imlua_capture"

im.VideoCaptureReloadDevices()

print("--- Devices ---")
local n = im.VideoCaptureDeviceCount()

for i = 0, n - 1 do
	desc = im.VideoCaptureDeviceDesc(i)
	print(desc)
end

local vc = im.VideoCaptureCreate()
print("connect: ", vc:Connect(0))
print()

print("--- Dialogs ---")

local dc = vc:DialogCount()
for i = 0, dc - 1 do
	desc = vc:DialogDesc(i)
	print(i, desc)
	vc:ShowDialog(i)
end
print()


print("--- Formats ---")

local fc = vc:FormatCount()
for i = 0, fc - 1 do
	local success, width, height, desc = vc:GetFormat(i)
	print(i, string.format("%dx%d", width, height), desc)
end
print()

print("--- Image Size ---")
local width, height = vc:GetImageSize()
print(width, height)
print()

print("--- Attributes ---")
attribs = vc:GetAttributeList()
for i, name in ipairs(attribs) do
	 local error, percent = vc:GetAttribute(name)
	 if error == 0 then percent = "get error" end
	 print(i, name, percent)
end
--vc:SetAttribute("FlipVertical", 1)
--vc:SetAttribute("FlipHorizontal", 1)
print()

print("--- Capture ---")
local image = im.ImageCreate(width, height, im.RGB, im.BYTE)
local res = vc:Live(1)
if (res > 0) then
	print("grabbing frame")
	print(vc:Frame(image, 3000))
end
image:Save("capture.jpg", "JPEG")

vc:Disconnect()