Created
September 16, 2021 09:00
-
-
Save AdroitAnandAI/ccde7d738a6fe5f69ef54ec3987ccb6a to your computer and use it in GitHub Desktop.
To send object detection result to LIDAR node for Sensor Fusion
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
for detection in detections: | |
if detection.score > threshold: | |
class_id = int(detection.id)-1 | |
# Potential Objects: person, bicycle, car, bus, | |
# truck, traffic light, street sign, stop sign | |
if class_id not in [0, 1, 2, 3, 5, 7, 9, 11, 12]: | |
continue | |
det_label = labels[class_id] if labels and | |
len(labels) >= class_id else '#{}'.format(class_id) | |
xmin = max(int(detection.xmin), 0) | |
ymin = max(int(detection.ymin), 0) | |
xmax = min(int(detection.xmax), x_width) | |
ymax = min(int(detection.ymax), y_height) | |
x_mid = np.mean([xmin, xmax]) | |
y_mid = np.mean([ymin, ymax]) | |
if not isAnnounced(det_label, x_mid, y_mid): | |
# theta min and max corresponds to Pi cam FoV angle | |
# Picam has 62 degrees horizontal FoV. Need to | |
# convert to LIDAR angles at LIDAR node. | |
theta_min = xmin / (x_width / 62) + 59 | |
theta_max = xmax / (x_width / 62) + 59 | |
now = time.localtime() | |
client.publish("object/getdistance", str(det_label) + '|' + | |
str(theta_min) + '|' + str(theta_max) + '|' + | |
str(now.tm_min * 60 + now.tm_sec)) | |
objectsInFrame.append(det_label) | |
objectMidPts.append((x_mid, y_mid)) | |
# List of objects and its mid points in last 30 frames will be stored in dqueue | |
if len(objectsInFrame) > 0: | |
objLastFrames.extend([objectsInFrame]) | |
objMidsLastFrames.extend([objectMidPts]) | |
noObjFrames = 0 | |
else: | |
noObjFrames += 1 | |
# If no objects found in last 30 frames, reset the queue | |
if noObjFrames >= 30: | |
objMidsLastFrames.clear() | |
objLastFrames.clear() | |
noObjFrames = 0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment