| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354 |
- from models import *
- import datetime
- from services.SegmentService import SegmentService
- from services.deal_cutout import DealCutout,DealCloths
- @app.get("/")
- async def index():
- """入口文件"""
- return {
- "message": "请求成功",
- "data": f"Hello, World!",
- }
- @app.post("/api/check_select_images", description="检查目录或文件")
- async def checkSelect(params: CheckSelectImages):
- service = SegmentService()
- file_path = params.path
- path_type = params.path_type
- image_list = params.image_list
- if path_type == 0:
- need_cutout_images = service.initImages(image_list=image_list)
- else:
- need_cutout_images = service.check_need_cutout_images(file_path)
- if len([x for x in need_cutout_images if x["need_cutout"]]) == 0:
- raise UnicornException("您所选文件夹下没有jpg图片,或对应图片已扣图")
- return success(need_cutout_images)
- @app.post("/api/segment_images", description="检查目录或文件")
- async def segmentImages(params: SegmentImages):
- image_type = params.image_type
- segment_type = params.segment_type
- need_cutout_images = params.need_cutout_images
- if len([x for x in need_cutout_images if x["need_cutout"]]) == 0:
- raise UnicornException("您所选文件夹下没有jpg图片,或对应图片已扣图")
- if image_type == 1 and segment_type == 1:
- raise UnicornException("服装暂不支持精细化抠图")
- elif image_type == 1 and segment_type == 0:
- deal_cutout_cloth = DealCloths()
- # 服装抠图
- # need_cutout_images = service.check_need_cutout_images(file_path)
- deal_cutout_cloth.need_cutout_images = need_cutout_images
- deal_cutout_cloth.startDispose()
- elif image_type == 0 and segment_type == 1:
- deal_cutout_mode = DealCutout()
- # 通用-精细化抠图
- deal_cutout_mode.need_cutout_images = need_cutout_images
- deal_cutout_mode.startDispose()
- elif image_type == 0 and segment_type == 0:
- # 通用-普通抠图
- # need_cutout_images = service.check_need_cutout_images(file_path)
- pass
- return success(need_cutout_images)
|