script.py 1017 B

12345678910111213141516171819202122232425262728293031323334353637383940
  1. import time
  2. # Correct the bounding box
  3. def correct_bb(bb):
  4. bb.xmin = max(0, bb.xmin)
  5. bb.ymin = max(0, bb.ymin)
  6. bb.xmax = min(bb.xmax, 1)
  7. bb.ymax = min(bb.ymax, 1)
  8. return bb
  9. # Main loop
  10. while True:
  11. time.sleep(0.001)
  12. # Get image frame
  13. img = node.io['frame'].get()
  14. # Get detection output
  15. face_dets = node.io['face_det_in'].tryGet()
  16. if face_dets and img is not None:
  17. # Loop over all detections
  18. for det in face_dets.detections:
  19. # Correct bounding box
  20. correct_bb(det)
  21. node.warn(f"New detection {det.xmin}, {det.ymin}, {det.xmax}, {det.ymax}")
  22. # Set config parameters
  23. cfg = ImageManipConfig()
  24. cfg.setCropRect(det.xmin, det.ymin, det.xmax, det.ymax)
  25. cfg.setResize(96, 112) # Input size of Face Rec model
  26. cfg.setKeepAspectRatio(False)
  27. # Output image and config
  28. node.io['manip_cfg'].send(cfg)
  29. node.io['manip_img'].send(img)