Loading...
Logo
Processing Forum
Hi there,
new user here, just wondering if anyone could give me a clue how to either flip the horizontal axis
or flip the video input. here i have colour tracking code to move some snake code i found but its hard to feel it
when the video isnt flipped and ive just come to a block and cant seem to find a simple answer.
thanks if anyone can help me out it would be really appreciated.
-Neil

Copy code
  1. import processing.video.*;

    Capture video;
    color trackColor;
    // Declare two arrays with 50 elements.
    int[] xpos = new int[50];
    int[] ypos = new int[50];





    void setup() {
      size(640,480);
     
      video = new Capture(this,width,height,120);
     


      // Start off tracking for red
      trackColor = color(102,255,255);

      smooth();
     
     
     
     
     
     
      // Initialize all elements of each array to zero.
      for (int i = 0; i < xpos.length; i ++ ) {
        xpos[i] = 0;
        ypos[i] = 0;
      }
    }

    void draw() {
      background(255);
     
     
     
       // Capture and display the video
      if (video.available()) {
        video.read();
       

      }

      // Before we begin searching, the "world record" for closest color is set to a high number that is easy for the first pixel to beat.
      float worldRecord = 110;

      // XY coordinate of closest color
      int closestX = 0;
      int closestY = 0;

      // Begin loop to walk through every pixel
      for (int x = 0; x < video.width; x ++ ) {
        for (int y = 0; y < video.height; y ++ ) {
          int loc = x + y*video.width;
          // What is current color
          color currentColor = video.pixels[loc];
          float r1 = red(currentColor);
          float g1 = green(currentColor);
          float b1 = blue(currentColor);
          float r2 = red(trackColor);
          float g2 = green(trackColor);
          float b2 = blue(trackColor);

          // Using euclidean distance to compare colors
          float d = dist(r1,g1,b1,r2,g2,b2); // We are using the dist( ) function to compare the current color with the color we are tracking.

          // If current color is more similar to tracked color than
          // closest color, save current location and current difference
          if (d < worldRecord) {
            worldRecord = d;
            closestX = x;
            closestY = y;
          }
        }
      }
     
      // Shift array values
      for (int i = 0; i < xpos.length-1; i ++ ) {
        // Shift all elements down one spot.
        // xpos[0] = xpos[1], xpos[1] = xpos = [2], and so on. Stop at the second to last element.
        xpos[i] = xpos[i+1];
        ypos[i] = ypos[i+1];
      }
     
      // New location
      xpos[xpos.length-1] = closestX; // Update the last spot in the array with the mouse location.
      ypos[ypos.length-1] = closestY;
     
      // Draw everything
      for (int i = 0; i < xpos.length; i ++ ) {
         // Draw an ellipse for each element in the arrays.
         // Color and size are tied to the loop's counter: i.
        noStroke();
        fill(trackColor-i*5);
        ellipse(xpos[i],ypos[i],i,i);
       
           
      }
    }

Replies(2)

I would usually use 

    pushMatrix();
      scale(-1,1);
      translate(-video.width, 0);
      image(video, 0, 0); 
    popMatrix();

but since you seem to just be reading pixels, why don't you just go through your for loop of video.width backwards ?
thanks alot

had to change this

int loc = x + y*video.width;

to this

int loc = (video.width - x - 1) + y*video.width;

knew it would be something simple.

thanks for your help.