get_images.py 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. # This Python file uses the following encoding: utf-8
  2. # @author runhey
  3. # github https://github.com/runhey
  4. import cv2
  5. import time
  6. from datetime import timedelta, datetime
  7. from cached_property import cached_property
  8. from random import choice
  9. from pathlib import Path
  10. from module.exception import TaskEnd
  11. from module.logger import logger
  12. from module.base.timer import Timer
  13. from tasks.Script.config_device import ScreenshotMethod, ControlMethod
  14. from tasks.base_task import BaseTask
  15. from tasks.Exploration.version import highlight
  16. class GetAnimation(BaseTask):
  17. @cached_property
  18. def save_folder(self) -> Path:
  19. save_time = datetime.now().strftime('%Y%m%dT%H%M%S')
  20. save_folder = Path(f'./log/temp/{save_time}')
  21. save_folder.mkdir(parents=True, exist_ok=True)
  22. return save_folder
  23. def run_screenshot(self):
  24. self.config.model.script.device.screenshot_method = ScreenshotMethod.WINDOW_BACKGROUND
  25. run_timer = Timer(3)
  26. sho_timer = Timer(0.1)
  27. run_timer.start()
  28. sho_timer.start()
  29. save_images = {}
  30. while 1:
  31. if run_timer.reached():
  32. break
  33. if sho_timer.reached():
  34. sho_timer.reset()
  35. image = self.device.screenshot_window_background()
  36. # image = cv2.cvtColor(image, cv2.COLOR_BGR2RGB)
  37. image = highlight(image)
  38. time_now1 = int(time.time() * 1000)
  39. save_images[time_now1] = image
  40. for time_now, image in save_images.items():
  41. cv2.imwrite(str(self.save_folder / f'all{time_now}.png'), image)