0

目前我将我的风格转移存储在一个名为 Temp 的临时变量中,从那里我想在圆形掩码中掩盖我的风格转移,使其成为像 Myimage 一样的圆形图像。但是问题是,当我尝试更改与 Temp 变量相关的任何内容时,我收到此错误: Uncaught (in promise) TypeError: Cannot read property 'src' of undefined。问题是变量在未更改时已定义,但如果发生任何更改,它将变为未定义。

任何帮助将不胜感激。

function setup() {
 
     
  canvas = createCanvas(500, 500);

  circleMask = createGraphics(128, 128);
    
  // load two style transfer models from the models folder
  style1 = ml5.styleTransfer("models/mathura", modelLoaded);
  style2 = ml5.styleTransfer("models/udnie", modelLoaded);
  style3 = ml5.styleTransfer("models/OversoulSpellModel", modelLoaded);
  style4  = ml5.styleTransfer("models/OilPainting", modelLoaded);
    
     circleMask.fill('rgba(0, 0, 0, 1)');

  circleMask.circle(64, 64, 128); //creating a circle mask

  myImage.mask(circleMask._renderer); //using . renderer apperantly fixes the issue of mask not being a function
}


function keyPressed() {
  if (key == 'a') {
   console.log("A");
   // myImage  = originalImg; // switch back to original so we can prevent recursive application
    style1.transfer(canvas, function(err, result) {
      
         tempDOMImage = createImg(result.src).hide();
        
      myImage  = tempDOMImage;
          
    });
    
  }else if (key == 'b') {
   
   // myImage  = originalImg; // switch back to original so we can prevent recursive application
    style2.transfer(canvas, function(err, result) {
       tempDOMImage = createImg(result.src).hide();
        
      myImage  = tempDOMImage;
    });}
      else if (key == 'c') {
    
   // myImage  = originalImg; // switch back to original so we can prevent recursive application
    style3.transfer(canvas, function(err, result) {
       tempDOMImage = createImg(result.src).hide();
      myImage  = tempDOMImage;
    });}
          else if (key == 'd') {
    
   // myImage  = originalImg; // switch back to original so we can prevent recursive application
    style4.transfer(canvas, function(err, result) {
       tempDOMImage = createImg(result.src).hide();
      myImage  = tempDOMImage;
    });
    
  }else {
    // we should transfer back
    myImage  = originalImg;
  }
}
4

0 回答 0