diff --git a/controls.py b/controls.py index 1ed330e..7283908 100644 --- a/controls.py +++ b/controls.py @@ -15,6 +15,7 @@ def __init__(self): self.enable_calibration_feed = False self.enable_processing_feed = True + self.send_tracking_data = True self.camera_mode = CAMERA_MODE_BALL self.enable_feed = True diff --git a/main.py b/main.py index b09cc34..e60cfb8 100644 --- a/main.py +++ b/main.py @@ -108,13 +108,14 @@ def main(): processed_ws = create_connection("ws://localhost:8080/processed/ws") calibration_ws = create_connection("ws://localhost:8080/calibration/ws") tracking_ws = create_connection("ws://localhost:8080/tracking/ws") - controller_listener.start("ws://localhost:8080/dashboard/ws") logger.info('starting main loop ') frame_cnt = 0 while(True): + tracking_data = None + frame_cnt += 1 if main_controller.enable_camera: @@ -159,9 +160,6 @@ def main(): camera, frame_cnt, color_profile) - # print(tracking_data) - dashboard.putStringArray(networktables.keys.vision_target_data, tracking_data) - tracking_ws.send(json.dumps(dict(targets=tracking_data))) elif main_controller.camera_mode == CAMERA_MODE_BALL: @@ -172,7 +170,6 @@ def main(): camera, frame_cnt, color_profile) - tracking_ws.send(json.dumps(dict(targets=tracking_data))) elif main_controller.camera_mode == CAMERA_MODE_HEXAGON: @@ -202,6 +199,12 @@ def main(): # if out is not None: # out.write(frame) + if tracking_data is not None and main_controller.send_tracking_data: + # sort tracking data by closests object + tracking_data = sorted(tracking_data, key = lambda i: i['dist']) + tracking_ws.send(json.dumps(dict(targets=tracking_data))) + # put into networktables + dashboard.putStringArray(networktables.keys.vision_target_data, tracking_data) # cv2.imshow('frame', processed_frame ) # cv2.waitKey(0) @@ -220,7 +223,7 @@ def main(): if __name__ == '__main__': - #p = Process(target=start_web.main) - #p.start() + p = Process(target=start_web.main) + p.start() main() - #p.join() + p.join() diff --git a/processing/ball_tracker2.py b/processing/ball_tracker2.py index ebd4ebf..4acd2f9 100644 --- a/processing/ball_tracker2.py +++ b/processing/ball_tracker2.py @@ -98,14 +98,7 @@ def process(img, camera, frame_cnt, color_profile): ypos=center_mass_y) tracking_data.append(data) - # sorter goes here - # if len(tracking_data) == 0: - # tracking_data.append(data) - # else: - # for target in tracking_data: - # if distance < target["dist"]: - # tracking_data.insert(tracking_data.index(target), data) - # break + #labels image radius_text = 'radius:%s' % (radius) coordinate_text = 'x:%s y:%s ' % (center_mass_x, center_mass_y) @@ -134,5 +127,4 @@ def process(img, camera, frame_cnt, color_profile): bottom_center = (FRAME_WIDTH // 2, 0) cv2.line(original_img, top_center, bottom_center, colors.WHITE, 4) - tracking_data = sorted(tracking_data, key = lambda i: i['dist']) return original_img, tracking_data diff --git a/processing/bay_tracker.py b/processing/bay_tracker.py index ecec5b7..fc6f236 100644 --- a/processing/bay_tracker.py +++ b/processing/bay_tracker.py @@ -81,16 +81,8 @@ def process(img, camera, frame_cnt, color_profile): angle=angle, xpos=center_mass_x, ypos=center_mass_y) - - if len(tracking_data) == 0: - tracking_data.append(data) - else: - for target in tracking_data: - if distance < target["dist"]: - tracking_data.insert(tracking_data.index(target), data) - break - - + + tracking_data.append(data) vertices_text = 'vertices:%s' % (num_vertices) coordinate_text = 'x:%s y:%s ' % (center_mass_x, center_mass_y) diff --git a/processing/port_tracker.py b/processing/port_tracker.py index 94c720d..f107be7 100644 --- a/processing/port_tracker.py +++ b/processing/port_tracker.py @@ -83,14 +83,8 @@ def process(img, camera, frame_cnt, color_profile): xpos=center_mass_x, ypos=center_mass_y) - if(not tracking_data): - tracking_data.append(data) - else: - for target in tracking_data: - if(distance < target["dist"]): - tracking_data.insert(tracking_data.index(target), data) - break - + tracking_data.append(data) + num_vertices = shape_util.find_vertices(contour) vertices_text = 'vertices:%s' % (num_vertices) coordinate_text = 'x:%s y:%s ' % (center_mass_x, center_mass_y)