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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
|
import sys
import sv, SV
import gl, GL, DEVICE
import time
def main():
v = sv.OpenVideo()
# Determine maximum window size based on signal standard
param = [SV.BROADCAST, 0]
v.GetParam(param)
if param[1] == SV.PAL:
width = SV.PAL_XMAX
height = SV.PAL_YMAX
elif param[1] == SV.NTSC:
width = SV.NTSC_XMAX
height = SV.NTSC_YMAX
else:
print 'Unknown video standard', param[1]
sys.exit(1)
# Initially all windows are half size
grabwidth, grabheight = width/2, height/2
# Open still window
gl.foreground()
gl.prefsize(grabwidth, grabheight)
still_win = gl.winopen('Grabbed frame')
gl.keepaspect(width, height)
gl.maxsize(width, height)
gl.winconstraints()
gl.RGBmode()
gl.gconfig()
gl.clear()
gl.pixmode(GL.PM_SIZE, 8)
# Open live window
gl.foreground()
gl.prefsize(grabwidth, grabheight)
live_win = gl.winopen('Live video')
gl.keepaspect(width, height)
gl.maxsize(width, height)
gl.winconstraints()
# Bind live video
v.SetSize(gl.getsize())
v.BindGLWindow(live_win, SV.IN_REPLACE)
print 'Use leftmouse to grab frame'
gl.qdevice(DEVICE.LEFTMOUSE)
gl.qdevice(DEVICE.WINQUIT)
gl.qdevice(DEVICE.WINSHUT)
gl.qdevice(DEVICE.ESCKEY)
frame = None
while 1:
dev, val = gl.qread()
if dev == DEVICE.LEFTMOUSE and val == 0:
w, h, fields = v.CaptureOneFrame(SV.RGB8_FRAMES, \
grabwidth, grabheight)
frame = sv.InterleaveFields(1, fields, w, h)
gl.winset(still_win)
gl.lrectwrite(0, 0, w - 1, h - 1, frame)
gl.winset(live_win)
if dev in (DEVICE.ESCKEY, DEVICE.WINQUIT, DEVICE.WINSHUT):
v.CloseVideo()
gl.winclose(live_win)
gl.winclose(still_win)
break
if dev == DEVICE.REDRAW and val == still_win:
gl.winset(still_win)
gl.reshapeviewport()
gl.clear()
grabwidth, grabheight = gl.getsize()
if frame:
gl.lrectwrite(0, 0, w - 1, h - 1, frame)
gl.winset(live_win)
if dev == DEVICE.REDRAW and val == live_win:
v.SetSize(gl.getsize())
v.BindGLWindow(live_win, SV.IN_REPLACE)
main()
|