Skip to content

Commit

Permalink
initial oakd classification checkin
Browse files Browse the repository at this point in the history
  • Loading branch information
supertick committed May 15, 2024
1 parent 697b909 commit 546a70c
Show file tree
Hide file tree
Showing 3 changed files with 90 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/main/java/org/myrobotlab/service/InMoov2.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
import org.myrobotlab.service.config.InMoov2Config;
import org.myrobotlab.service.config.OpenCVConfig;
import org.myrobotlab.service.config.SpeechSynthesisConfig;
import org.myrobotlab.service.data.Classification;
import org.myrobotlab.service.data.JoystickData;
import org.myrobotlab.service.data.Locale;
import org.myrobotlab.service.interfaces.IKJointAngleListener;
Expand Down Expand Up @@ -2294,5 +2295,10 @@ public void waitTargetPos() {
sendToPeer("leftArm", "waitTargetPos");
sendToPeer("torso", "waitTargetPos");
}

public Map publishClassification(Map<String, Object> c) {
// log.info(c);
return c;
}

}
13 changes: 13 additions & 0 deletions src/main/resources/resource/OakD/classification.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# new awesome robot script
# new awesome robot script
python = runtime.getService("python")
if python:
python.subscribe("i01","publishClassification")

def onClassification(c):
print("label ", c.get("label"))
print("confidence ", c.get("confidence"))
print("bounding box", c.get("xmin"), c.get("xmax"), c.get("ymin"), c.get("ymax"))
print("position ", c.get("x"), c.get("y"), c.get("z"))

print("loaded classifications.py")
71 changes: 71 additions & 0 deletions src/main/resources/resource/OakD/mrl_callbacks.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
import requests
import json

def onNewFrame(frame, source):
pass


def onShowFrame(frame, source):
pass

# found in config.json in the model directory
# e.g. resources/nn/mobilenet-ssd/mobilenet-ssd.json
labels = ["background", "aeroplane", "bicycle", "bird", "boat", "bottle", "bus", "car", "cat", "chair", "cow", "diningtable", "dog", "horse", "motorbike", "person", "pottedplant", "sheep", "sofa", "train", "tvmonitor"]
# TODO - debounce the detections

def onNn(nn_packet, decoded_data):
# print(dir(nn_packet))
# print(dir(decoded_data))
# print(json.dumps(decoded_data))
for detection in decoded_data:
print(detection.spatialCoordinates.x)
print(detection.spatialCoordinates.y)
print(detection.spatialCoordinates.z)
# print(detection.boundingBoxMapping)
# print(dir(detection.boundingBoxMapping))
print(labels[detection.label])
print(detection.confidence)
print(f'xmin {detection.xmin}')
print(f'xmax {detection.xmin}')
print(f'ymin {detection.ymin}')
print(f'ymax {detection.xmin}')
# Add detections to visualizer
url = 'http://localhost:8888/api/service/i01/publishClassification' # Replace with your URL
data = {
"xmin": detection.xmin,
"xmax": detection.xmax,
"ymin": detection.xmin,
"ymax": detection.ymax,
"label": labels[detection.label],
"confidence": detection.confidence,
"x": detection.spatialCoordinates.x,
"y": detection.spatialCoordinates.y,
"z": detection.spatialCoordinates.z
}

# Make the POST request with JSON data
try:
response = requests.post(url, json=[data])
except requests.exceptions.HTTPError as http_err:
print(f'HTTP error occurred: {http_err}') # HTTP error
except requests.exceptions.ConnectionError as conn_err:
print(f'Connection error occurred: {conn_err}') # Connection error
except requests.exceptions.Timeout as timeout_err:
print(f'Timeout error occurred: {timeout_err}') # Timeout error
except requests.exceptions.RequestException as req_err:
print(f'An error occurred: {req_err}') # Other errors

def onReport(report):
pass


def onSetup(*args, **kwargs):
pass


def onTeardown(*args, **kwargs):
pass


def onIter(*args, **kwargs):
pass

0 comments on commit 546a70c

Please sign in to comment.