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.3 kB

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

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