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

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  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. input_id: str,
  21. value: bytes,
  22. send_output: Callable[[str, bytes], None],
  23. ) -> DoraStatus:
  24. """
  25. Put image and bounding box on cv2 window.
  26. Args:
  27. input_id (str): Id of the input declared in the yaml configuration
  28. value (bytes): Bytes message of the input
  29. send_output (Callable[[str, bytes]]): Function enabling sending output back to dora.
  30. """
  31. if input_id == "image":
  32. frame = np.frombuffer(value, dtype="uint8")
  33. frame = cv2.imdecode(frame, -1)
  34. self.image = frame
  35. elif input_id == "bbox" and len(self.image) != 0:
  36. bboxs = np.frombuffer(value, dtype="float32")
  37. bboxs = np.reshape(bboxs, (-1, 6))
  38. for bbox in bboxs:
  39. [
  40. min_x,
  41. min_y,
  42. max_x,
  43. max_y,
  44. confidence,
  45. label,
  46. ] = bbox
  47. cv2.rectangle(
  48. self.image,
  49. (int(min_x), int(min_y)),
  50. (int(max_x), int(max_y)),
  51. (0, 255, 0),
  52. 2,
  53. )
  54. cv2.putText(
  55. self.image,
  56. LABELS[int(label)] + f", {confidence:0.2f}",
  57. (int(max_x), int(max_y)),
  58. font,
  59. 0.75,
  60. (0, 255, 0),
  61. 2,
  62. 1,
  63. )
  64. if CI != "true":
  65. cv2.imshow("frame", self.image)
  66. if cv2.waitKey(1) & 0xFF == ord("q"):
  67. return DoraStatus.STOP
  68. return DoraStatus.CONTINUE
  69. def drop_operator(self):
  70. 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