Skip to content
This repository has been archived by the owner on Jun 19, 2020. It is now read-only.

Commit

Permalink
Moved sorting to main.py
Browse files Browse the repository at this point in the history
  • Loading branch information
Your Name committed Feb 1, 2020
1 parent e9b8d94 commit 5fdd819
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 35 deletions.
1 change: 1 addition & 0 deletions controls.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
19 changes: 11 additions & 8 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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:

Expand All @@ -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:

Expand Down Expand Up @@ -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)
Expand All @@ -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()
10 changes: 1 addition & 9 deletions processing/ball_tracker2.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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
12 changes: 2 additions & 10 deletions processing/bay_tracker.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
10 changes: 2 additions & 8 deletions processing/port_tracker.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 5fdd819

Please sign in to comment.