有没有一种方法可以根据3D形状尺寸缩放实时视频?

时间:2020-04-19 08:07:08

标签: 3d width textures scaling p5.js

我正在使用p5.js Web编辑器,并且是编码的新手! 我需要帮助!

我创建了一个将某些效果应用到我的网络摄像头的代码,使其类似于 Coding Trains Brightness Mirror 。一切正常! 现在,我已经采用了这段代码,并将其设为自己的函数“ Video_graphic”。 在绘制部分中,我将其设置为纹理“ texture(Video_graphic);”。 -这似乎有效 但是,我在技术上应该可以使用的“ box(100)”下面放置了一个字,但是它说控制台中的 width不确定。我添加了“ box(100,100)”,两者没有区别。 / p>

我认为这可能是由于扩展问题。我认为应该有一个简单的解决方案,但不知道如何解决!下面的代码是我认为问题正在发生的一些代码,请看一下上下文的链接-感谢ADVANCE 原始镜像-> https://editor.p5js.org/beth_osullivan/sketches/sGpke6LIF 尝试使镜像成为纹理-> https://editor.p5js.org/beth_osullivan/sketches/awvhSwcbt

function draw (){ // start draw

 texture (video_graphic);
  box (200);  // this is where it says the issue is  - with the width of the Box


}// End Draw


/////////////////////////////////////////////////////////////////////////
 // video_graphic Function
/////////////////////////////////////////////////////////

function video_graphic (scale){

  // 5. Use of External Code - Daniel Shiffman (referenced above) 
// 1. Iterations --> nested loop accessing pixels by array


  for(let y = 0; y < cam.height; y++){ 
    for(let x = 0; x < cam.width; x++){
     var index = (cam.width - x +1 + (y * cam.width)) * 4;
      var r = cam.pixels[index+0]; 
      var g = cam.pixels[index+1];
      var b = cam.pixels[index+2];

      var bright = (r+g+b) / 3; // making grayscale by averaging

      var threshold = slider.value();
      //var threshold = 135;

      // changing colours based brightness values
      if (bright > threshold) {
        fill (r1,g1,b1); // this makes the white blocks change colour every click - see mousePressed
        //fill(255)
        } else {
          fill (0);
        } 

      noStroke();
      //stroke ();
      //rectMode(CENTER); // makes the sqaures grow from center rather than top left corner

      rect(x*vScale, y*vScale, vScale, vScale); 


    } // end for loop x
  } // end for loop y

}


0 个答案:

没有答案