flip video capture horizontally

edited November 2017 in Library Questions

Hello! I have been trying to solve this but I haven´t been able. That has discouraged me and I haven´t done so much in the last months because of that. Can someone help me? this I guess shouldn´t be difficult. I want to flip the image capture horizontally.

THanks!

import processing.video.*;

import ddf.minim.*;

Capture video;

float boxSize = 80; float boxSize2 = 40; float boxX, boxY; float boxX1, boxY1; float boxX2, boxY2; float boxX3, boxY3; float boxX4, boxY4; float boxX5, boxY5; float boxX6, boxY6; float boxX7, boxY7; float boxX8, boxY8; float boxX9, boxY9;

void setup() { size(1024, 768);

boxX = width/2;

boxY = height/2; boxX1 = 230; boxY1 = 300; boxX2= 220; boxY2= 500; boxX3= 600; boxY3= 50; boxX4 = 700; boxY4 = 600; boxX5 = 900; boxY5 = 200; boxX6 = 170; boxY6 = 120; boxX7 = 280; boxY7 = 120; boxX8 = 700; boxY8 =400; boxX9 = 700; boxY9 = 300; rectMode(RADIUS); video = new Capture(this, width, height);

video.start();
noStroke(); smooth(); minim = new Minim(this);

kick = minim.loadSample( "notes 1.wav", // filename 512 // buffer size );

snare = minim.loadSample("notes 2.wav", 512); if ( snare == null ) println("Didn't get snare!");

chick = minim.loadSample("notes 3.wav", 512); if ( chick == null ) println("Didn't get chick!");

chack = minim.loadSample("notes 4.wav", 512); if ( chack == null ) println("Didn't get chack!");

chuck = minim.loadSample("notes 5.wav", 512); if ( chuck == null ) println("Didn't get chuck!");

check = minim.loadSample("notes 6.wav", 512); if ( check == null ) println("Didn't get check!");

tac = minim.loadSample("notes 7.wav", 512);

if ( tac == null ) println("Didn't get tac!");

 tuc = minim.loadSample("notes 8.wav", 512);

if ( tuc == null ) println("Didn't get tuc!");

tic = minim.loadSample("notes 9.wav", 512);

if ( tic == null ) println("Didn't get tic!");

 toc = minim.loadSample("notes 10.wav", 512);

if ( toc == null ) println("Didn't get toc!"); }

// Uses the default video input, see the reference if this causes an error

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

image(video, 0, 0, width, height); // Draw the webcam video onto the screen
int brightestX = 0; // X-coordinate of the brightest video pixel
int brightestY = 0; // Y-coordinate of the brightest video pixel
float brightestValue = 0; // Brightness of the brightest video pixel
// Search for the brightest pixel: For each row of pixels in the video image and
// for each pixel in the yth row, compute each pixel's index in the video
video.loadPixels();
int index = 0;
for (int y = 0; y < video.height; y++) {

  for (int x = 0; x < video.width; x++) {
    // Get the color stored in the pixel
    int pixelValue = video.pixels[index];
    // Determine the brightness of the pixel
    float pixelBrightness = brightness(pixelValue);
    // If that value is brighter than any previous, then store the
    // brightness of that pixel, as well as its (x,y) location
    if (pixelBrightness > brightestValue) {
      brightestValue = pixelBrightness;
      brightestY = y;
      brightestX = x;

    }
    index++;
  }
}
// Draw a large, yellow circle at the brightest pixel

if(brightestX>boxX-boxSize && brightestX<boxX+boxSize && brightestY>boxY-boxSize && brightestY<boxY+boxSize) snare.trigger();

if(brightestX>boxX-boxSize && brightestX<boxX+boxSize && brightestY>boxY-boxSize && brightestY<boxY+boxSize){ fill(200,200); } else { noFill(); } rect(boxX, boxY, boxSize, boxSize);

noFill();

if(brightestX>boxX1-boxSize && brightestX<boxX1+boxSize && brightestY>boxY1-boxSize && brightestY<boxY1+boxSize) kick.trigger();

if(brightestX>boxX1-boxSize && brightestX<boxX1+boxSize && brightestY>boxY1-boxSize && brightestY<boxY1+boxSize){ fill(200,200); } else { noFill(); }

rect(boxX1, boxY1, boxSize, boxSize);

noFill(); if(brightestX>boxX2-boxSize && brightestX<boxX2+boxSize && brightestY>boxY2-boxSize && brightestY<boxY2+boxSize) chick.trigger();

if(brightestX>boxX2-boxSize && brightestX<boxX2+boxSize && brightestY>boxY2-boxSize && brightestY<boxY2+boxSize) { fill(200,200); } else { noFill(); } rect(boxX2,boxY2, boxSize, boxSize);

noFill(); if(brightestX>boxX3-boxSize && brightestX<boxX3+boxSize && brightestY>boxY3-boxSize && brightestY<boxY3+boxSize) chack.trigger();

     if(brightestX>boxX3-boxSize && brightestX<boxX3+boxSize &&

brightestY>boxY3-boxSize && brightestY<boxY3+boxSize) { fill(200,200); } else { noFill(); } rect(boxX3, boxY3, boxSize, boxSize);

noFill();
     if(brightestX>boxX4-boxSize && brightestX<boxX4+boxSize &&

brightestY>boxY4-boxSize && brightestY<boxY4+boxSize) chuck.trigger();

     if(brightestX>boxX4-boxSize && brightestX<boxX4+boxSize &&

brightestY>boxY4-boxSize && brightestY<boxY4+boxSize) { fill(200,200); } else { noFill(); } rect(boxX4, boxY4, boxSize, boxSize);

 noFill();
     if(brightestX>boxX5-boxSize && brightestX<boxX5+boxSize &&

brightestY>boxY5-boxSize && brightestY<boxY5+boxSize) check.trigger();

     if(brightestX>boxX5-boxSize && brightestX<boxX5+boxSize &&

brightestY>boxY5-boxSize && brightestY<boxY5+boxSize) { fill(200,200); } else { noFill(); } rect(boxX5, boxY5, boxSize, boxSize);

 noFill();
     if(brightestX>boxX6-boxSize && brightestX<boxX6+boxSize &&

brightestY>boxY6-boxSize && brightestY<boxY6+boxSize) tac.trigger();

     if(brightestX>boxX6-boxSize && brightestX<boxX6+boxSize &&

brightestY>boxY6-boxSize && brightestY<boxY6+boxSize) { fill(200,200); } else { noFill(); } rect(boxX6, boxY6, boxSize2, boxSize2);

 noFill();
     if(brightestX>boxX7-boxSize && brightestX<boxX7+boxSize &&

brightestY>boxY7-boxSize && brightestY<boxY7+boxSize) tuc.trigger();

     if(brightestX>boxX7-boxSize && brightestX<boxX7+boxSize &&

brightestY>boxY7-boxSize && brightestY<boxY7+boxSize) { fill(200,200); } else { noFill(); } rect(boxX7, boxY7, boxSize2, boxSize2);

 noFill();
     if(brightestX>boxX8-boxSize && brightestX<boxX8+boxSize &&

brightestY>boxY8-boxSize && brightestY<boxY8+boxSize) tic.trigger();

     if(brightestX>boxX8-boxSize && brightestX<boxX8+boxSize &&

brightestY>boxY8-boxSize && brightestY<boxY8+boxSize) { fill(200,200); } else { noFill(); } rect(boxX8, boxY8, boxSize2, boxSize2);

 noFill();
     if(brightestX>boxX9-boxSize && brightestX<boxX9+boxSize &&

brightestY>boxY9-boxSize && brightestY<boxY9+boxSize) toc.trigger();

     if(brightestX>boxX9-boxSize && brightestX<boxX9+boxSize &&

brightestY>boxY9-boxSize && brightestY<boxY9+boxSize) { fill(200,200); } else { noFill(); } rect(boxX9, boxY9, boxSize2, boxSize2);

ellipse(brightestX, brightestY, 20, 30);
              stroke(100);
              noFill();

}

}

Tagged:

Answers

  • Normally this line draws the frame of video:

    image(video, 0, 0, width, height)
    

    Consider this:

    pushMatrix();
    translate(width,0);
    scale(-1,1);
    image(video, 0, 0, width, height)
    popMatrix();
    
Sign In or Register to comment.