deal_cutout.py 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. import time
  2. from concurrent.futures import as_completed, ThreadPoolExecutor, wait
  3. import threading
  4. from .remove_bg_pixian import RemoveBgPiXian
  5. from .other.module_online_data import GetOnlineData
  6. from .deal_one_image import DealOneImage, DealOneImageBeforehand
  7. from .other.log import MyLogger
  8. class DealCutout:
  9. def __init__(self, token):
  10. super().__init__()
  11. self.lock = threading.Lock()
  12. self.need_cutout_images = {}
  13. self.token = token
  14. self.state = 2 # 1进行中 2停止
  15. self.get_online_data = GetOnlineData(self.token)
  16. self.is_upload_pic_num = 0
  17. self.is_deal_num = 0
  18. self.output_type = 0
  19. # 图片列表
  20. self.upload_pic_dict = {}
  21. self.logger = MyLogger().logger
  22. def startDispose(self):
  23. self.get_online_data.refresh_headers()
  24. num = 0
  25. result_array = []
  26. save_root_path = ""
  27. for image_data in self.need_cutout_images:
  28. num += 1
  29. save_root_path = image_data["root_path"]
  30. upload_pic_dict = {}
  31. upload_pic_dict = DealOneImageBeforehand(
  32. image_data=image_data,
  33. lock=self.lock,
  34. windows=self,
  35. num=num,
  36. token=self.token,
  37. ).run(upload_pic_dict)
  38. result = DealOneImage(
  39. image_data=image_data,
  40. lock=self.lock,
  41. windows=self,
  42. num=num,
  43. token=self.token,
  44. ).run(image_data, upload_pic_dict)
  45. result_array.append(result)
  46. return result_array, save_root_path
  47. def normalMode(self):
  48. """普通模式"""
  49. self.get_online_data.refresh_headers()
  50. num = 0
  51. result_array = []
  52. print("self.need_cutout_images", self.need_cutout_images)
  53. save_root_path = ""
  54. for image_data in self.need_cutout_images:
  55. num += 1
  56. save_root_path = image_data["root_path"]
  57. result = DealOneImageBeforehand(
  58. image_data=image_data,
  59. lock=self.lock,
  60. windows=self,
  61. num=num,
  62. token=self.token,
  63. ).get_image_cut_noraml(image_data)
  64. result_array.append(result)
  65. return result_array, save_root_path
  66. class DealCloths:
  67. def __init__(self, token):
  68. super().__init__()
  69. self.lock = threading.Lock()
  70. self.need_cutout_images = {}
  71. self.token = token
  72. self.output_type = 0
  73. self.state = 2 # 1进行中 2停止
  74. self.get_online_data = GetOnlineData(self.token)
  75. self.is_upload_pic_num = 0
  76. self.is_deal_num = 0
  77. # 图片列表
  78. self.upload_pic_dict = {}
  79. self.logger = MyLogger().logger
  80. def startDispose(self):
  81. self.get_online_data.refresh_headers()
  82. num = 0
  83. result_array = []
  84. save_root_path = ""
  85. for image_data in self.need_cutout_images:
  86. num += 1
  87. save_root_path = image_data["root_path"]
  88. upload_pic_dict = {}
  89. hand = DealOneImageBeforehand(
  90. image_data=image_data,
  91. lock=self.lock,
  92. windows=self,
  93. num=num,
  94. token=self.token,
  95. )
  96. upload_pic_dict = hand.get_image_cut_cloths(image_data)
  97. result_array.append(upload_pic_dict)
  98. return result_array, save_root_path