Loading...
Logo
Processing Forum
ahoffma6's Profile
2 Posts
4 Responses
0 Followers

Activity Trend

Last 30 days
Show:
Private Message
     I want is for the still images to run independently through the display code, then when the sensor is triggered the live camera feed will overlap the still images at various transparency based on the sensor reading.

    Right now the still images run in the background but are not visible until the sensor range is tripped. The camera feed performs as desired until you are out of range then the camera feed never turns off. Also the camera feed flickers constantly. I am using a basic logitech webcam.


    I appreciate any help you can provide.

    Cheers,
    Allison

    int imgCount= 9;
    PImage [] imgs = new PImage[imgCount];
    float imgW;
    float offset = 0;
    float easing = 0.05; //using sensor value distance to change its position. this program overlays one image over another by modifying the alpha value of the image with the tint() function.

    int currentImage=0;
    int lastShown=0;
    int interval=3000; // each slide shows for this many millis
    int blendedInterval=9000;

    //keep track of loaded images (true or false)
    boolean[] loadStates = new boolean [imgCount];

    // for loading images
    float loaderX, loaderY, theta;

    import processing.video.*;
    import processing.serial.*;


    Capture video;
    int count;
    int writeRow;
    int maxRows;
    int topRow;
    int buffer[];

    //int rangeAnalogPin= 0; //rangefinder

    boolean showLiveVideo=false;
    Serial serialPort;
    int rangeVal=255;

    void setup() {
      size (displayWidth, displayHeight, P3D);
      background(0);
      smooth();
      imgW= width/imgCount;
      // load images asynchronously
      for (int i = 0; i < imgCount; i++) {
        imgs[i] = requestImage("warhol_img"+nf(
    i, 4)+".jpg");
      }

      // Setup VIDEO Capture

      String[] cameras = Capture.list();

      //if (cameras.length == 0) {
      // println("There are no cameras available for capture.");
      // exit();

      //else {
      //  println("Available cameras:");
      //  for (int i = 0; i < cameras.length; i++) {
      //  println(i+" "+cameras[i]);



      //video = new Capture(this, 640, 480);
      video = new Capture(this, cameras[9]);

      video.start();

      maxRows = height *2;
      buffer = new int[width * maxRows];
      writeRow = height - 1;
      topRow = 0;

      //frameRate(10);
      background(0);
      loadPixels();

      // Setup SERIAL PORT
      println(Serial.list());

      String portName = Serial.list()[0];
      serialPort = new Serial(this, portName, 9600);
    }




    void draw() {
      // check for new range finder data
      while ( serialPort.available () > 0) {  // If data is available,
        rangeVal = serialPort.read();         // read it and store it in val
        //println(rangeVal);
      }

      // draw pollock image
      background(0);
      //tint(255, 255);
      //image(img, 0, 0, displayWidth, displayHeight);
      for (int i = 0; i < imgs.length; i++) {
        // Check if individual images are fully loaded
        if ((imgs[i].width != 0) && (imgs[i].width != -1)) {
          // As images are loaded set true in boolean array
          loadStates[i] = true;
        }
      }
      if (checkLoadStates()) {
        // all the images are loaded
        if (currentImage<imgCount) {
          // we are in the first set of single images
          drawNextImage();
          if (millis()-lastShown>interval) {
            currentImage=currentImage+1;
            lastShown=millis();
          }
        }
        else {
          // we are drawing the blendef image
          drawBlendedImages();

          if (millis()-lastShown> blendedInterval) {
            // if we've shown the blended image for long enough
            // reset the whole system
            currentImage=0; // start at first image;
            lastShown=millis(); // reset the timer
            tint(255);
          }
        }
      }
      // draw video image
      tint(255, rangeVal);  // display at half opacity
      image(video, 0, 0, displayWidth, displayHeight);
    }

    void drawNextImage() {
      int y = (height - imgs[0].height) / 2;
      image(imgs[currentImage], 0, y, imgs[currentImage].height, imgs[currentImage].height);
    }

    void drawBlendedImages() {
      int y = (height - imgs[0].height) / 2;
      for (int i = 0; i < imgs.length; i++) {
        //image(imgs[i], width/imgs.length*i, y, imgs[i].height, imgs[i].height);
        tint(255, 128);
        image(imgs[i], 0, y, imgs[i].height, imgs[i].height);
      }
    }

    // Loading animation
    void runLoaderAni() {
      // Only run when images are loading
      if (!checkLoadStates()) {
        ellipse(loaderX, loaderY, 10, 10);
        loaderX += 2;
        loaderY = height/2 + sin(theta) * (height/8);
        theta += PI/22;
        // Reposition ellipse if it goes off the screen
        if (loaderX > width + 5) {
          loaderX = -5;
        }
      }
    }

    // Return true when all images are loaded - no false values left in array
    boolean checkLoadStates() {
      for (int i = 0; i < imgs.length; i++) {
        if (loadStates[i] == false) {
          return false;
        }
      }
      return true;
    }

    void captureEvent(Capture c) {
      c.read();
    }
    Hi I'm working on writing a code that displays a still image that is disrupted by live video feed when someone gets within a certain distance of the af range finder. As the person gets within maximum closeness of the range finder the still image should be complete replaced with live video.

    For some reason now the image and video play simultaneously, eventually the image is complete replaced by the live video.

    processing code:

    PImage img;
    float offset = 0;
    float easing = 0.05; //using sensor value distance to change its position. this program overlays one image over another by modifying the alpha value of the image with the tint() function.

    import processing.video.*;
    import processing.serial.*;


    Capture video;


    //int rangeAnalogPin= 0; //rangefinder

    boolean showLiveVideo=false;
    Serial serialPort;
    int rangeVal;

    void setup() {
      size (displayWidth, displayHeight, P3D);
      img = loadImage("art1.jpg"); //load image into program


      // Setup VIDEO Capture

        String[] cameras = Capture.list();

      if (cameras.length == 0) {
        println("There are no cameras available for capture.");
        exit();
      }
      else {
        println("Available cameras:");
        for (int i = 0; i < cameras.length; i++) {
          println(i+" "+cameras[i]);
        }
      }

      //video = new Capture(this, 640, 480);
      video = new Capture(this, cameras[9]);

      video.start();


      // Setup SERIAL PORT
      println(Serial.list());

      String portName = Serial.list()[0];
      serialPort = new Serial(this, portName, 9600);
    }


    void draw() {
      // check for new range finder data
      while ( serialPort.available() > 0) {  // If data is available,
        rangeVal = serialPort.read();         // read it and store it in val
        //println(rangeVal);
      }
     
      // draw image
      image(img, 0, 0, displayWidth, displayHeight);
     
      // draw video image
      tint(255, rangeVal);  // display at half opacity
      image(video, offset, 0, displayWidth, displayHeight); 
    }

    void captureEvent(Capture c) {
        c.read();
    }

    arduino code:
    /*
      AnalogReadSerial
      Reads an analog input on pin 0, prints the result to the serial monitor.
      Attach the center pin of a potentiometer to pin A0, and the outside pins to +5V and ground.
     
     This example code is in the public domain.
     */

    // the setup routine runs once when you press reset:
    void setup() {
      // initialize serial communication at 9600 bits per second:
      Serial.begin(9600);
    }

    // the loop routine runs over and over again forever:
    void loop() {
      // read the input on analog pin 0:
      int sensorValue = analogRead(A0);
      // print out the value you read:
      Serial.println(sensorValue);
     // Serial.println(map(sensorValue, 0, 545, 0, 255));
      Serial.write(map(sensorValue, 0,255, 50, 450));
     
      // send sensor value as number between 0 - 255
      //Serial.write(sensorValue/4);
      delay(100);        // delay in between reads for stability
    }