-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathtest_camera_2cams.py
More file actions
executable file
·62 lines (56 loc) · 1.98 KB
/
test_camera_2cams.py
File metadata and controls
executable file
·62 lines (56 loc) · 1.98 KB
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
from interface import IDSCamera
import pygame
pygame.init()
""" Do NOT USE this. It is old and it still under update. """
def main():
# Obrim la llibreria
camera = IDSCamera()
# Busquem dispositius disponibles
devs = camera.get_devices()
for i, device in enumerate(devs):
print(i, device.ModelName())
# En seleccionem el primer
camera.select_device(1)
camera.select_device(0)
#camera.select_device(1)
# Seleccionem els fps
camera.set_fps(20)
#camera.set_fps(20, idx=1)
print(f"Capturing at {camera.get_fps(idx=0):.4g} fps")
# Seleccionem el temps d'exposició, en us
camera.set_exposure_time(1/25*1e6)
#camera.set_exposure_time(1/25*1e6, idx=1)
print(f"Exposure: {camera.get_exposure_time():.4g} us")
# Seleccionem la imatge de sortida
camera.set_pixel_format("BGR8")
# En mirem la resolució
width0, height0 = camera.get_resolution()
width1, height1 = camera.get_resolution(idx=1)
width = [width0, width1]
height = [height0, height1]
print(f"Resoltion: {width}x{height}")
# Comencem l'adquisició, que bloqueja canvis "crítics" en la càmera
camera.start_acquisition()
camera.start_acquisition(1)
# Capturem imatges
display = pygame.display.set_mode((1200, 900))
disp_array = pygame.surfarray.pixels3d(display)
running = True
clock = pygame.time.Clock()
idx = 0
while running:
clock.tick()
image = camera.capture(idx)
reshapen = image.reshape((height[idx], width[idx], 3))
disp_array[:, :, 0] = reshapen[:900, :1200, 2].T
disp_array[:, :, 1] = reshapen[:900, :1200, 1].T
disp_array[:, :, 2] = reshapen[:900, :1200, 0].T
events = pygame.event.get()
for event in events:
if event.type == pygame.QUIT:
running = False
pygame.display.flip()
pygame.display.set_caption(f"FPS = {clock.get_fps():.4g}")
idx = (idx + 1) % 2
if __name__ == "__main__":
main()