| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152 |
- 'use strict';
- const { Controller } = require('ee-core');
- const Log = require('ee-core/log');
- const { dialog } = require('electron');
- const { checkSelectImages,segmentImages,modelFormSegment } = require('../api/imageMatting')
- const errData = {
- msg :'请求失败,请联系管理员',
- code:999
- }
- /**
- * 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
- }
- }
- Log.info('selectPara===================ms');
- Log.info(selectParams);
- let res = null;
- let error = false
- res = await checkSelectImages(selectParams).catch(e=>{
- Log.info(e);
- error = errData
- return error;
- })
- if( res.data){
- if( res.data.code === 0 && res.data.data){
- console.log("params.image_type");
- console.log(params.image_type);
- Log.info(res.data.data.length);
- Log.info(res);
- if(params.image_type == 2){
- let modelParams = {
- "token": params.token,
- "image_type": 2, //图像类型;0非服装;1服装 2人台
- "output_mode": params.output_type, //出图模式 ;0透明;1白底
- "size_mode": params.size, // 0=>指定大小;1=>最小边框;2原图尺寸
- "out_width": params.customWidth, // 宽度
- "out_height": params.customHeight, // 高度
- "need_cutout_images": res.data.data
- }
- if(modelParams.size_mode !== 0){
- delete modelParams.out_width
- delete modelParams.out_height
- }
- let error = false
- const img = await modelFormSegment(modelParams).catch(e=>{
- Log.info(e);
- error = errData
- return error;
- })
- if(img.data){
- return img.data
- }
- return error;
- }
- let error = 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
- }).catch(e=>{
- Log.info(e);
- error = errData
- return error;
- })
- if(img.data){
- return img.data
- }
- return error;
- }
- return res.data
- }
- return error;
- }
- }
- ImageMattingController.toString = () => '[class ExampleController]';
- module.exports = ImageMattingController;
|