Browse Source

Adding log example

tags/v0.3.3-rc1
haixuanTao 2 years ago
parent
commit
61bdd4b2fe
2 changed files with 25 additions and 0 deletions
  1. +2
    -0
      examples/python-operator-dataflow/dataflow.yml
  2. +23
    -0
      examples/python-operator-dataflow/plot.py

+ 2
- 0
examples/python-operator-dataflow/dataflow.yml View File

@@ -14,6 +14,7 @@ nodes:
image: webcam/image
outputs:
- bbox
- logs

- id: plot
operator:
@@ -21,3 +22,4 @@ nodes:
inputs:
image: webcam/image
bbox: object_detection/bbox
object_detection_logs: object_detection/logs

+ 23
- 0
examples/python-operator-dataflow/plot.py View File

@@ -29,6 +29,7 @@ class Operator:
self.bboxs = []
self.bounding_box_messages = 0
self.image_messages = 0
self.object_detection_logs = []

def on_event(
self,
@@ -69,12 +70,22 @@ class Operator:
self.image_messages += 1
print("received " + str(self.image_messages) + " images")

elif dora_input["id"] == "object_detection_logs":
logs = dora_input["value"][0].as_py()
self.object_detection_logs += [logs]
## Only keep last 10 logs
self.object_detection_logs = self.object_detection_logs[-10:]
return DoraStatus.CONTINUE

elif dora_input["id"] == "bbox" and len(self.image) != 0:
bboxs = dora_input["value"].to_numpy()
self.bboxs = np.reshape(bboxs, (-1, 6))

self.bounding_box_messages += 1
print("received " + str(self.bounding_box_messages) + " bounding boxes")
return DoraStatus.CONTINUE
else:
return DoraStatus.CONTINUE

for bbox in self.bboxs:
[
@@ -104,6 +115,18 @@ class Operator:
1,
)

for i, log in enumerate(self.object_detection_logs):
cv2.putText(
self.image,
log,
(10, 10 + 20 * i),
font,
0.5,
(0, 255, 0),
2,
1,
)

if CI != "true":
cv2.imshow("frame", self.image)
if cv2.waitKey(1) & 0xFF == ord("q"):


Loading…
Cancel
Save