处理:如何将音频添加到网络摄像头效果中?

时间:2018-02-18 05:12:42

标签: processing

如何使用处理将歌曲添加到此代码中?并将其与Arduino中的PIR传感器同步?

import processing.video.*;
import ddf.minim.*;
import ddf.minim.AudioPlayer;

// Size of each cell in the grid
int cellSize = 20;
// Number of columns and rows in our system
int cols, rows;
// Variable for capture device
Capture video;
Minim minim;
AudioPlayer song;

void setup() {
size(1280, 720);
frameRate(30);
cols = width / cellSize;
rows = height / cellSize;
colorMode(RGB, 255, 255, 255, 100);

// This the default video input, see the GettingStartedCapture 
// example if it creates an error
video = new Capture(this, width, height);

// Start capturing the images from the camera
video.start();  

background(0);
}

{
// we pass this to Minim so that it can load files from the data directory
minim = new Minim(this);

// loadFile will look in all the same places as loadImage does.
// this means you can find files that are in the data folder and the 
// sketch folder. you can also pass an absolute path, or a URL.
song = minim.loadFile("untitled.wav");
}


void draw() { 
if (video.available()) {
video.read();
video.loadPixels();

// Begin loop for columns
for (int i = 0; i < cols; i++) {
  // Begin loop for rows
  for (int j = 0; j < rows; j++) {

    // Where are we, pixel-wise?
    int x = i*cellSize;
    int y = j*cellSize;
    int loc = (video.width - x - 1) + y*video.width; // Reversing x to mirror       the image

    float r = red(video.pixels[loc]);
    float g = green(video.pixels[loc]);
    float b = blue(video.pixels[loc]);
    // Make a new color with an alpha component
    color c = color(r, g, b, 75);

    // Code for drawing a single rect
    // Using translate in order for rotation to work properly
    pushMatrix();
    translate(x+cellSize/2, y+cellSize/2);
    // Rotation formula based on brightness
    rotate((2 * PI * brightness(c) / 255.0));
    rectMode(CENTER);
    fill(c);
    noStroke();
    // Rects are larger than the cell for some overlap
    rect(0, 0, cellSize+6, cellSize+6);
    popMatrix();
  }
  }
  }
  }

我有兴趣检测激活或停用此功能的动作。 拜托,你能帮助我。

这是我得到的错误:

未设置草图路径。 ==== JavaSound最小错误==== ==== java.lang.reflect.InvocationTargetException

===最小错误=== ===无法加载文件untitled.wav

1 个答案:

答案 0 :(得分:0)

Stack Overflow并非真正针对一般&#34;我如何做到这一点&#34;输入问题。这是特定的&#34;我试过X,期望Y,但得到了Z而不是#34;输入问题。但我会在一般意义上尝试提供帮助:

您需要break your problem down into smaller pieces,然后一次一张。得到一个简单的例子。如果您要询问有关音频的信息,请暂时忘掉网络摄像头。创建一个只播放声音的简单草图。与此分开,创建一个简单的草图,只是让网络摄像头工作。如果你有完美的工作,那么你可以考虑将它们结合起来。但是要小步前进。用英语写下你想要发生的事情,这将是一个你可以考虑用代码实现的算法。

然后,如果您遇到问题,可以发布更具体的问题以及MCVE。祝你好运。