-
Notifications
You must be signed in to change notification settings - Fork 2
/
test_vidcap.py
69 lines (51 loc) · 1.36 KB
/
test_vidcap.py
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
import pygame, os
# /// script
# [project]
# name = "name"
# version = "version"
# description = "description"
# readme = {file = "README.txt", content-type = "text/markdown"}
# requires-python = ">=3.11"
#
# dependencies = [
# "pygame-ce",
# "pygame.base",
# ]
# ///
import platform
pygame.init()
async def main():
global cam, screen
import pygame.vidcap as camera
if pygame.display.get_init():
screen = pygame.display.get_surface()
else:
screen = None
if screen is None:
screen = pygame.display.set_mode([1024, 1024]).subsurface( (100,100,900,900) )
FRAMES = 0
DROPS = 0
cam = camera.Camera( camera.list_cameras()[0], (640, 480), 0 )
await cam.start()
last = 0
cnt = 0
while True:
if cnt==300:
print(f"Frame {DROPS=} {FRAMES=}")
if os.path.isfile(cam.device):
with open(cam.device) as file:
fd = file.fileno()
if last!=fd:
print(fd)
last = fd
cnt = 0
cnt += 1
if cam.query_image():
FRAMES += 1
screen.blit( cam.get_image(), (0, 0))
pygame.display.update()
else:
DROPS +=1
#print(f"Frame {DROPS=} {FRAMES=}")
await asyncio.sleep(0)
asyncio.run(main())