api.py 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. from models import *
  2. import datetime
  3. from services.SegmentService import SegmentService
  4. from services.deal_cutout import DealCutout,DealCloths
  5. @app.get("/")
  6. async def index():
  7. """入口文件"""
  8. return {
  9. "message": "请求成功",
  10. "data": f"Hello, World!",
  11. }
  12. @app.post("/api/check_select_images", description="检查目录或文件")
  13. async def checkSelect(params: CheckSelectImages):
  14. service = SegmentService()
  15. file_path = params.path
  16. path_type = params.path_type
  17. image_list = params.image_list
  18. if path_type == 0:
  19. need_cutout_images = service.initImages(image_list=image_list)
  20. else:
  21. need_cutout_images = service.check_need_cutout_images(file_path)
  22. if len([x for x in need_cutout_images if x["need_cutout"]]) == 0:
  23. raise UnicornException("您所选文件夹下没有jpg图片,或对应图片已扣图")
  24. return success(need_cutout_images)
  25. @app.post("/api/segment_images", description="检查目录或文件")
  26. async def segmentImages(params: SegmentImages):
  27. image_type = params.image_type
  28. segment_type = params.segment_type
  29. need_cutout_images = params.need_cutout_images
  30. if len([x for x in need_cutout_images if x["need_cutout"]]) == 0:
  31. raise UnicornException("您所选文件夹下没有jpg图片,或对应图片已扣图")
  32. if image_type == 1 and segment_type == 1:
  33. raise UnicornException("服装暂不支持精细化抠图")
  34. elif image_type == 1 and segment_type == 0:
  35. deal_cutout_cloth = DealCloths()
  36. # 服装抠图
  37. # need_cutout_images = service.check_need_cutout_images(file_path)
  38. deal_cutout_cloth.need_cutout_images = need_cutout_images
  39. deal_cutout_cloth.startDispose()
  40. elif image_type == 0 and segment_type == 1:
  41. deal_cutout_mode = DealCutout()
  42. # 通用-精细化抠图
  43. deal_cutout_mode.need_cutout_images = need_cutout_images
  44. deal_cutout_mode.startDispose()
  45. elif image_type == 0 and segment_type == 0:
  46. # 通用-普通抠图
  47. # need_cutout_images = service.check_need_cutout_images(file_path)
  48. pass
  49. return success(need_cutout_images)