-
Notifications
You must be signed in to change notification settings - Fork 1
/
polaris.py
68 lines (51 loc) · 2.13 KB
/
polaris.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 time
import cv2
import ntcore
from config.config import ConfigStore, LocalConfig, RemoteConfig
from config.ConfigSource import ConfigSource, FileConfigSource, NTConfigSource
from output.OutputPublisher import NT4OutputPublisher, OutputPublisher
from output.overlay_util import *
from output.StreamServer import MjpegServer
from pipeline.CameraPoseEstimator import MultiTargetCameraPoseEstimator
from pipeline.Capture import GStreamerCapture
from pipeline.TagDetector import ArucoTagDetector
def main():
config = ConfigStore(LocalConfig(), RemoteConfig())
local_config_source: ConfigSource = FileConfigSource()
remote_config_source: ConfigSource = NTConfigSource()
capture = GStreamerCapture()
tag_detector = ArucoTagDetector(cv2.aruco.DICT_APRILTAG_36h11)
pose_estimator = MultiTargetCameraPoseEstimator()
output_publisher: OutputPublisher = NT4OutputPublisher()
stream_server = MjpegServer()
local_config_source.update(config)
if not config.local_config.has_calibration:
print('No calibration found')
exit(1)
ntcore.NetworkTableInstance.getDefault().setServer(config.local_config.server_ip)
ntcore.NetworkTableInstance.getDefault().startClient4(config.local_config.device_id)
stream_server.start(config)
frame_count = 0
last_print = 0
while True:
remote_config_source.update(config)
success, image = capture.get_frame(config)
timestamp = time.time()
if not success:
time.sleep(0.5)
continue
fps = None
frame_count += 1
if time.time() - last_print > 1:
last_print = time.time()
fps = frame_count
print('Running at', frame_count, 'fps')
frame_count = 0
image_observations = tag_detector.detect_tags(image, config)
pose_observation = pose_estimator.solve_camera_pose(image_observations, config)
for obs in image_observations:
overlay_image_observation(image, obs)
output_publisher.send(config, timestamp, pose_observation, fps)
stream_server.set_frame(image)
if __name__ == '__main__':
main()