script_task.py 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. # This Python file uses the following encoding: utf-8
  2. # @author runhey
  3. # github https://github.com/runhey
  4. import cv2
  5. import numpy as np
  6. from datetime import datetime
  7. from numpy import uint8, fromfile
  8. from cached_property import cached_property
  9. # Use cmd to install: ./toolkit/python.exe -m pip install -i https://pypi.org/simple/ oashya --trusted-host pypi.org
  10. from oashya.tracker import Tracker
  11. from module.exception import TaskEnd
  12. from tasks.GameUi.game_ui import GameUi
  13. from tasks.GameUi.page import page_hyakkiyakou
  14. from tasks.Hyakkiyakou.config import Hyakkiyakou as HyakkiyakouConfig
  15. from tasks.Hyakkiyakou.assets import HyakkiyakouAssets
  16. from tasks.Hyakkiyakou.agent.agent import Agent
  17. from tasks.Hyakkiyakou.slave.hya_slave import HyaSlave
  18. from tasks.Hyakkiyakou.debugger import Debugger
  19. def plot_save(image, boxes):
  20. color_palette = np.random.uniform(0, 255, size=(226, 3))
  21. for box in boxes:
  22. _cls = box[0]
  23. _scores = box[1]
  24. _x, _y, _w, _h = box[2]
  25. x1 = int(_x - _w / 2)
  26. y1 = int(_y - _h / 2)
  27. x2 = int(_x + _w / 2)
  28. y2 = int(_y + _h / 2)
  29. cv2.rectangle(image, (x1, y1), (x2, y2), color_palette[_cls], 2)
  30. #
  31. cv2.putText(image, f'{_cls} {_scores:.2f}', (x1, y1 - 10), cv2.FONT_HERSHEY_SIMPLEX, 0.5, color_palette[_cls],
  32. 2)
  33. save_file = './tasks/Hyakkiyakou/temp/image.png'
  34. cv2.imwrite(save_file, image)
  35. class ScriptTask(GameUi, HyaSlave):
  36. @cached_property
  37. def tracker(self) -> Tracker:
  38. args = {}
  39. return Tracker(args=args)
  40. @cached_property
  41. def agent(self) -> Agent:
  42. return Agent()
  43. @cached_property
  44. def debugger(self) -> Debugger:
  45. return Debugger()
  46. def run(self):
  47. self.ui_get_current_page()
  48. self.ui_goto(page_hyakkiyakou)
  49. self.one()
  50. self.ui_click_until_disappear(self.I_UI_BACK_RED)
  51. self.set_next_run(task='Hyakkiyakou', success=True, finish=False)
  52. raise TaskEnd
  53. def one(self):
  54. pass
  55. if __name__ == '__main__':
  56. # from module.config.config import Config
  57. # from module.device.device import Device
  58. from debugger import test_track
  59. # c = Config('oas1')
  60. # d = Device(c)
  61. # t = ScriptTask(c, d)
  62. # t.run()
  63. test_track(show=True)