You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

utils.py 457B

123456789101112131415161718192021
  1. import itertools
  2. import cv2
  3. def show_and_wait(img, name="img", wait=True, save=False):
  4. cv2.imshow(name, img)
  5. if wait:
  6. while cv2.waitKey() != ord('q'):
  7. continue
  8. cv2.destroyAllWindows()
  9. if save:
  10. cv2.imwrite(f"{name}.jpeg", img)
  11. def check_if_generator_is_empty(generator):
  12. try:
  13. first = next(generator)
  14. except StopIteration:
  15. return None
  16. return itertools.chain([first], generator)