'use strict'; const { Controller } = require('ee-core'); const Log = require('ee-core/log'); const { dialog } = require('electron'); const { checkSelectImages,segmentImages,modelFormSegment } = require('../api/imageMatting') /** * example * @class */ class ImageMattingController extends Controller { constructor(ctx) { super(ctx); } /** * 所有方法接收两个参数 * @param args 前端传的参数 * @param event - ipc通信时才有值。详情见:控制器文档 */ /** * upload */ async upload (params) { // const result = await Services.get('example').test('electron'); let dialogParams = {} if(params.path_type === 0){ dialogParams = { title:"选择图片", properties: ['openFile'], filters: [ { name: '支持JPG', extensions: ['jpg'] }, ] } }else{ dialogParams = { title:"选择文件夹", properties: ['openDirectory'] } } const filePaths = dialog.showOpenDialogSync(dialogParams) Log.info('filePaths:::::::::'+filePaths); if(!filePaths || !filePaths[0]){ return false; } Log.info(filePaths); Log.info({ path_type: params.path_type, // path_type 地址类型;0图像;1目录 path: filePaths[0] } ); let selectParams = { path_type:params.path_type , // path_type 地址类型;0图像;1目录 path:filePaths[0] } if(params.path_type === 0){ selectParams = { path_type:params.path_type , // path_type 地址类型;0图像;1目录 image_list:filePaths } } const res = await checkSelectImages(selectParams) Log.info(res.data); if( res.data){ if( res.data.code === 0 && res.data.data){ console.log("params.image_type"); console.log(params.image_type); if(params.image_type == 2){ let modelParams = { "token": params.token, "image_type": 2, //图像类型;0非服装;1服装 2人台 "output_mode": params.output_type, //出图模式 ;0透明;1白底 "size_model": params.size, // 0=>指定大小;1=>最小边框;2原图尺寸 "out_width": params.customWidth, // 宽度 "out_height": params.customHeight, // 高度 "need_cutout_images": res.data.data } if(modelParams.size_model !== 0){ delete modelParams.out_width delete modelParams.out_height } const img = await modelFormSegment(modelParams) console.log(img) if(img.data){ return img.data } return false; } const img = await segmentImages({ "token": params.token, "image_type": params.image_type, //图像类型;0非服装;1服装 2人台 "segment_type": params.segment_type, //抠图精细度;0普通;1精细 "output_type": params.output_type, //出图模式 ;0透明;1白底 "need_cutout_images": res.data.data }) if(img.data){ return img.data } return false; } return res.data } return false; } } ImageMattingController.toString = () => '[class ExampleController]'; module.exports = ImageMattingController;