|
29 | 29 |
|
30 | 30 | xlinkOut = pipeline.create(dai.node.XLinkOut) |
31 | 31 | trackerOut = pipeline.create(dai.node.XLinkOut) |
| 32 | +xinTrackerConfig = pipeline.create(dai.node.XLinkIn) |
32 | 33 |
|
33 | 34 | xlinkOut.setStreamName("preview") |
34 | 35 | trackerOut.setStreamName("tracklets") |
| 36 | +xinTrackerConfig.setStreamName("trackerConfig") |
35 | 37 |
|
36 | 38 | # Properties |
37 | 39 | camRgb.setPreviewSize(300, 300) |
|
64 | 66 | detectionNetwork.out.link(objectTracker.inputDetections) |
65 | 67 | objectTracker.out.link(trackerOut.input) |
66 | 68 |
|
| 69 | +# set tracking parameters |
| 70 | +objectTracker.setOcclusionRatioThreshold(0.4) |
| 71 | +objectTracker.setTrackletMaxLifespan(120) |
| 72 | +objectTracker.setTrackletBirthThreshold(3) |
| 73 | + |
| 74 | +xinTrackerConfig.out.link(objectTracker.inputConfig) |
| 75 | + |
67 | 76 | # Connect to device and start pipeline |
68 | 77 | with dai.Device(pipeline) as device: |
69 | 78 |
|
70 | 79 | preview = device.getOutputQueue("preview", 4, False) |
71 | 80 | tracklets = device.getOutputQueue("tracklets", 4, False) |
| 81 | + trackerConfigQueue = device.getInputQueue("trackerConfig") |
72 | 82 |
|
73 | 83 | startTime = time.monotonic() |
74 | 84 | counter = 0 |
75 | 85 | fps = 0 |
76 | 86 | frame = None |
77 | 87 |
|
78 | 88 | while(True): |
| 89 | + latestTrackedIds = [] |
79 | 90 | imgFrame = preview.get() |
80 | 91 | track = tracklets.get() |
81 | 92 |
|
|
106 | 117 | cv2.putText(frame, t.status.name, (x1 + 10, y1 + 50), cv2.FONT_HERSHEY_TRIPLEX, 0.5, 255) |
107 | 118 | cv2.rectangle(frame, (x1, y1), (x2, y2), color, cv2.FONT_HERSHEY_SIMPLEX) |
108 | 119 |
|
| 120 | + if t.status == dai.Tracklet.TrackingStatus.TRACKED: |
| 121 | + latestTrackedIds.append(t.id) |
| 122 | + |
109 | 123 | cv2.putText(frame, "NN fps: {:.2f}".format(fps), (2, frame.shape[0] - 4), cv2.FONT_HERSHEY_TRIPLEX, 0.4, color) |
110 | 124 |
|
111 | 125 | cv2.imshow("tracker", frame) |
112 | 126 |
|
113 | | - if cv2.waitKey(1) == ord('q'): |
| 127 | + key = cv2.waitKey(1) |
| 128 | + if key == ord('q'): |
114 | 129 | break |
| 130 | + elif key == ord('g'): |
| 131 | + # send tracker config to device |
| 132 | + config = dai.ObjectTrackerConfig() |
| 133 | + |
| 134 | + # take a random ID from the latest tracked IDs |
| 135 | + if len(latestTrackedIds) > 0: |
| 136 | + idToRemove = (np.random.choice(latestTrackedIds)) |
| 137 | + print(f"Force removing ID: {idToRemove}") |
| 138 | + config.forceRemoveID(idToRemove) |
| 139 | + trackerConfigQueue.send(config) |
| 140 | + else: |
| 141 | + print("No tracked IDs available to force remove") |
| 142 | + |
0 commit comments