imageMatting.js 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. 'use strict';
  2. const { Controller } = require('ee-core');
  3. const Log = require('ee-core/log');
  4. const { dialog } = require('electron');
  5. const { checkSelectImages,segmentImages } = require('../api/imageMatting')
  6. /**
  7. * example
  8. * @class
  9. */
  10. class ImageMattingController extends Controller {
  11. constructor(ctx) {
  12. super(ctx);
  13. }
  14. /**
  15. * 所有方法接收两个参数
  16. * @param args 前端传的参数
  17. * @param event - ipc通信时才有值。详情见:控制器文档
  18. */
  19. /**
  20. * upload
  21. */
  22. async upload (params) {
  23. // const result = await Services.get('example').test('electron');
  24. let dialogParams = {}
  25. if(params.path_type === 0){
  26. dialogParams = {
  27. title:"选择图片",
  28. properties: ['openFile'], filters: [
  29. { name: '支持JPG', extensions: ['jpg'] },
  30. ]
  31. }
  32. }else{
  33. dialogParams = {
  34. title:"选择文件夹",
  35. properties: ['openDirectory']
  36. }
  37. }
  38. const filePaths = dialog.showOpenDialogSync(dialogParams)
  39. Log.info('filePaths:::::::::'+filePaths);
  40. if(!filePaths || !filePaths[0]){
  41. return false;
  42. }
  43. Log.info(filePaths);
  44. Log.info({
  45. path_type: params.path_type, // path_type 地址类型;0图像;1目录
  46. path: filePaths[0]
  47. }
  48. );
  49. let selectParams = {
  50. path_type:params.path_type , // path_type 地址类型;0图像;1目录
  51. path:filePaths[0]
  52. }
  53. if(params.path_type === 0){
  54. selectParams = {
  55. path_type:params.path_type , // path_type 地址类型;0图像;1目录
  56. image_list:filePaths
  57. }
  58. }
  59. const res = await checkSelectImages(selectParams)
  60. Log.info(res.data);
  61. if( res.data){
  62. if( res.data.code === 0 && res.data.data){
  63. const img = await segmentImages({
  64. "token": params.token,
  65. "image_type": params.image_type, //图像类型;0非服装;1服装
  66. "segment_type": params.segment_type, //抠图精细度;0普通;1精细
  67. "output_type": params.output_type, //出图模式 ;0透明;1白底
  68. "need_cutout_images": res.data.data
  69. })
  70. if(img.data){
  71. return img.data
  72. }
  73. return false;
  74. }
  75. return res.data
  76. }
  77. return false;
  78. }
  79. }
  80. ImageMattingController.toString = () => '[class ExampleController]';
  81. module.exports = ImageMattingController;