Hey guys! Need help on my coding project! (webcam amplifier)

edited April 2017 in Library Questions

Delete!

Tagged:

Answers

  • Ok. You need to format your code. Select it hit ctrl-o

    Also what does work with the code and what doesn't. Where are you stuck?

  • @Chrisir

    For project I need to write a Processing sketch that adjusts the volume of an audio track based on the quantity of motion as detected by a web cam.

  • @Chrisir All of these work I did not put the audio code because it keeps giving me error on processing. I am stuck on trying to put an audio track that adjusts the volume of an audio track based on the quantity of motion as detected by a web cam.

  • Please don't delete your posts. Also, you can post your code and provide a description of your problem. Break down your problems in small parts. Divide and conquer!

    Kf

  • edited April 2017

    I am trying to do this project but I am so lost and confused. Here is the things that I need on my project:

    n00b mission:

    Write a sketch that plays an audio track on loop and that detects the quantity of motion seen by a connected web camera and that adjusts the volume (amplitude) of the looping audio track based on the detected motion. The track should get louder when there is more motion, and be silent when there is no motion. Use println() to display the volume in the console.

    Here is my code so far:

    import processing.video.*;
    
    Capture cam;
    PImage lastFrame;
    PImage motion;
    int threshhold = 40;
    
    void setup() {
      size(640, 360);
      cam = new Capture(this, width, height, 30);
      cam.start();
      lastFrame = createImage(width, height, RGB);
      motion = createImage(width, height, RGB);
    }
    
    void draw() {
      if (cam.available() == true) {
        cam.read();
        cam.loadPixels();
        lastFrame.loadPixels();
        motion.loadPixels();
    
        for (int i = 0; i < cam.pixels.length; i++) {
          if (brightness(cam.pixels[i]) + threshhold < brightness(lastFrame.pixels[i])
            || brightness(cam.pixels[i]) - threshhold > brightness(lastFrame.pixels[i])) {
          } else {
            motion.pixels[i] = color(0);
          }
          lastFrame.pixels[i] = cam.pixels[i];
        }
        motion.updatePixels();
        image(motion, 0, 0);
      } else {
      }
    }
    
This discussion has been closed.