imageMatting.js 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  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. if(!filePaths[0]){
  40. return false;
  41. }
  42. Log.info(filePaths);
  43. Log.info({
  44. path_type: params.path_type, // path_type 地址类型;0图像;1目录
  45. path: filePaths[0]
  46. }
  47. );
  48. let selectParams = {
  49. path_type:params.path_type , // path_type 地址类型;0图像;1目录
  50. path:filePaths[0]
  51. }
  52. if(params.path_type === 0){
  53. selectParams = {
  54. path_type:params.path_type , // path_type 地址类型;0图像;1目录
  55. image_list:filePaths
  56. }
  57. }
  58. const res = await checkSelectImages(selectParams)
  59. Log.info(res.data);
  60. if( res.data){
  61. if( res.data.code === 0 && res.data.data){
  62. const img = await segmentImages({
  63. "token": params.token,
  64. "image_type": params.image_type, //图像类型;0非服装;1服装
  65. "segment_type": params.segment_type, //抠图精细度;0普通;1精细
  66. "output_type": params.output_type, //出图模式 ;0透明;1白底
  67. "need_cutout_images": res.data.data
  68. })
  69. if(img.data){
  70. return img.data
  71. }
  72. }
  73. return res.data
  74. }
  75. return false;
  76. }
  77. }
  78. ImageMattingController.toString = () => '[class ExampleController]';
  79. module.exports = ImageMattingController;