Quantcast
Channel: Processing Forum
Viewing all articles
Browse latest Browse all 1768

need help with debugging

$
0
0
 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();
}

Viewing all articles
Browse latest Browse all 1768

Trending Articles