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 1.8 kB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. import os
  2. from enum import Enum
  3. from typing import Callable
  4. import cv2
  5. import numpy as np
  6. CI = os.environ.get("CI")
  7. class DoraStatus(Enum):
  8. CONTINUE = 0
  9. STOP = 1
  10. class Operator:
  11. """
  12. Plot image and bounding box
  13. """
  14. def __init__(self):
  15. self.image = []
  16. def on_input(
  17. self,
  18. input_id: str,
  19. value: bytes,
  20. send_output: Callable[[str, bytes], None],
  21. ) -> DoraStatus:
  22. """
  23. Put image and bounding box on cv2 window.
  24. Args:
  25. input_id (str): Id of the input declared in the yaml configuration
  26. value (bytes): Bytes message of the input
  27. send_output (Callable[[str, bytes]]): Function enabling sending output back to dora.
  28. """
  29. if input_id == "image":
  30. frame = np.frombuffer(value, dtype="uint8")
  31. frame = cv2.imdecode(frame, -1)
  32. self.image = frame
  33. elif input_id == "bbox" and len(self.image) != 0:
  34. bboxs = np.frombuffer(value, dtype="float32")
  35. bboxs = np.reshape(bboxs, (-1, 6))
  36. for bbox in bboxs:
  37. [
  38. min_x,
  39. min_y,
  40. max_x,
  41. max_y,
  42. _confidence,
  43. _class_label,
  44. ] = bbox
  45. cv2.rectangle(
  46. self.image,
  47. (int(min_x), int(min_y)),
  48. (int(max_x), int(max_y)),
  49. (0, 255, 0),
  50. 2,
  51. )
  52. if CI != "true":
  53. cv2.imshow("frame", self.image)
  54. if cv2.waitKey(1) & 0xFF == ord("q"):
  55. return DoraStatus.STOP
  56. return DoraStatus.CONTINUE
  57. def drop_operator(self):
  58. 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