-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathdriver_vision.py
61 lines (43 loc) · 1.72 KB
/
driver_vision.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
from networktables import NetworkTables
import cscore
import time
# tuples are (camera_name, camera_device_id)
cameras = [
('Camera 1', 0),
('Camera 2', 1),
]
def main():
cs_instance = cscore.CameraServer.getInstance()
cs_instance.enableLogging()
table = NetworkTables.getTable("Preferences")
res_w = int(table.getNumber('Camera Res Width', 320))
res_h = int(table.getNumber('Camera Res Height', 200))
fps = int(table.getNumber('Camera FPS', 30))
camera_objects = []
for cam_idx, cam_config in enumerate(cameras):
name, dev_id = cam_config
camera_obj = cscore.UsbCamera(name=name, dev=dev_id)
camera_obj.setResolution(res_w, res_h)
camera_obj.setFPS(fps)
camera_objects.append(camera_obj)
# camera_chooser.addDefault(name, cam_idx)
cam_server = cs_instance.addServer(name='camera_server')
current_selected = int(table.getNumber('Selected Camera', 1))
if current_selected >= len(camera_objects):
current_selected = 1
cam_server.setSource(camera_objects[current_selected])
while True:
selected_camera = int(table.getNumber('Selected Camera', 0))
if (
selected_camera < len(camera_objects)
and selected_camera != current_selected
):
res_w = int(table.getNumber('Camera Res Width', 320))
res_h = int(table.getNumber('Camera Res Height', 200))
fps = int(table.getNumber('Camera FPS', 30))
camera_obj = camera_objects[selected_camera]
camera_obj.setResolution(res_w, res_h)
camera_obj.setFPS(fps)
cam_server.setSource(camera_obj)
current_selected = selected_camera
time.sleep(0.02)