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_dynamic.py 1.9 kB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. import os
  2. from dataclasses import dataclass
  3. import cv2
  4. import numpy as np
  5. from dora import Node
  6. CI = os.environ.get("CI")
  7. IMAGE_WIDTH = int(os.getenv("IMAGE_WIDTH", "640"))
  8. IMAGE_HEIGHT = int(os.getenv("IMAGE_HEIGHT", "480"))
  9. FONT = cv2.FONT_HERSHEY_SIMPLEX
  10. @dataclass
  11. class Plotter:
  12. frame: np.array = np.array([])
  13. bboxes: np.array = np.array([])
  14. if __name__ == "__main__":
  15. plotter = Plotter()
  16. node = Node("plot")
  17. for event in node:
  18. event_type = event["type"]
  19. if event_type == "INPUT":
  20. if event["id"] == "image":
  21. frame = event["value"].to_numpy()
  22. frame = (
  23. event["value"].to_numpy().reshape((IMAGE_HEIGHT, IMAGE_WIDTH, 3))
  24. )
  25. plotter.frame = frame
  26. elif event["id"] == "bbox" and len(plotter.frame) != 0:
  27. bboxs = event["value"].to_numpy()
  28. plotter.bboxes = np.reshape(bboxs, (-1, 6))
  29. for bbox in plotter.bboxs:
  30. [
  31. min_x,
  32. min_y,
  33. max_x,
  34. max_y,
  35. confidence,
  36. label,
  37. ] = bbox
  38. cv2.rectangle(
  39. plotter.frame,
  40. (int(min_x), int(min_y)),
  41. (int(max_x), int(max_y)),
  42. (0, 255, 0),
  43. 2,
  44. )
  45. cv2.putText(
  46. plotter.frame,
  47. LABELS[int(label)] + f", {confidence:0.2f}",
  48. (int(max_x), int(max_y)),
  49. FONT,
  50. 0.75,
  51. (0, 255, 0),
  52. 2,
  53. 1,
  54. )
  55. if CI != "true":
  56. cv2.imshow("frame", plotter.frame)
  57. if cv2.waitKey(1) & 0xFF == ord("q"):
  58. break