You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

plot.py 2.1 kB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. import os
  2. from typing import Callable
  3. import cv2
  4. import numpy as np
  5. from utils import LABELS
  6. from dora import DoraStatus
  7. CI = os.environ.get("CI")
  8. font = cv2.FONT_HERSHEY_SIMPLEX
  9. class Operator:
  10. """
  11. Plot image and bounding box
  12. """
  13. def __init__(self):
  14. self.image = []
  15. self.bboxs = []
  16. def on_input(
  17. self,
  18. dora_input: dict,
  19. send_output: Callable[[str, bytes], None],
  20. ) -> DoraStatus:
  21. """
  22. Put image and bounding box on cv2 window.
  23. Args:
  24. dora_input["id"] (str): Id of the dora_input declared in the yaml configuration
  25. dora_input["data"] (bytes): Bytes message of the dora_input
  26. send_output (Callable[[str, bytes]]): Function enabling sending output back to dora.
  27. """
  28. if dora_input["id"] == "image":
  29. frame = np.frombuffer(dora_input["data"], dtype="uint8")
  30. frame = cv2.imdecode(frame, -1)
  31. self.image = frame
  32. elif dora_input["id"] == "bbox" and len(self.image) != 0:
  33. bboxs = np.frombuffer(dora_input["data"], dtype="float32")
  34. self.bboxs = np.reshape(bboxs, (-1, 6))
  35. for bbox in self.bboxs:
  36. [
  37. min_x,
  38. min_y,
  39. max_x,
  40. max_y,
  41. confidence,
  42. label,
  43. ] = bbox
  44. cv2.rectangle(
  45. self.image,
  46. (int(min_x), int(min_y)),
  47. (int(max_x), int(max_y)),
  48. (0, 255, 0),
  49. 2,
  50. )
  51. cv2.putText(
  52. self.image,
  53. LABELS[int(label)] + f", {confidence:0.2f}",
  54. (int(max_x), int(max_y)),
  55. font,
  56. 0.75,
  57. (0, 255, 0),
  58. 2,
  59. 1,
  60. )
  61. if CI != "true":
  62. cv2.imshow("frame", self.image)
  63. if cv2.waitKey(1) & 0xFF == ord("q"):
  64. return DoraStatus.STOP
  65. return DoraStatus.CONTINUE

DORA (Dataflow-Oriented Robotic Architecture) is middleware designed to streamline and simplify the creation of AI-based robotic applications. It offers low latency, composable, and distributed datafl