<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom">
	<channel>
      <title>Tagged with captureevent() - Processing 2.x and 3.x Forum</title>
      <link>https://forum.processing.org/two/discussions/tagged/p2/feed.rss?Tag=captureevent%28%29</link>
      <pubDate>Sun, 08 Aug 2021 15:45:34 +0000</pubDate>
         <description>Tagged with captureevent() - Processing 2.x and 3.x Forum</description>
   <language>en-CA</language>
   <atom:link href="/two/discussions/taggedcaptureevent%28%29/feed.rss" rel="self" type="application/rss+xml" />
   <item>
      <title>How to distinguish two shapes from another</title>
      <link>https://forum.processing.org/two/discussion/23242/how-to-distinguish-two-shapes-from-another</link>
      <pubDate>Wed, 28 Jun 2017 15:37:48 +0000</pubDate>
      <dc:creator>Lucneedshelp</dc:creator>
      <guid isPermaLink="false">23242@/two/discussions</guid>
      <description><![CDATA[<p>Hello, I'm trying to decide, if an object looks more like a rectangle or a circle!</p>

<p>I already transformed the image into a binary image and am using the OpenCV libary.</p>

<p>I've tried to work with the contour of the object, but didn't find a way to translate it from OpenCV examples like
<a href="http://www.pyimagesearch.com/2016/02/08/opencv-shape-detection/" target="_blank" rel="nofollow">http://www.pyimagesearch.com/2016/02/08/opencv-shape-detection/</a> .</p>

<p>If anybody has an idea on where to start or just some code as an example, that would be great!</p>

<p>My Code so far :</p>

<pre><code>import gab.opencv.*;
import processing.video.*;

Capture webCam;
OpenCV finalImgcv, cv2;
PImage finalImg,  temp;
boolean foreGExists = false;
ArrayList&lt;Contour&gt; contours;
Contour M;

void setup(){
  size(640, 480);
  String[] cams = Capture.list();


  webCam = new Capture(this, width, height, cams[0], 30); // = name=Vimicro USB2.0 Camrera,size=640x480,fps=30
  webCam.start();


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

void draw(){

  image(webCam, 0, 0);
   if(foreGExists){
     set(0, 0, finalImg);
   }else{
     set(0,0, webCam);
   }
}


void keyPressed(){

  if( key == 'b' ){
    PImage temp = new PImage(640, 480);
    temp.loadPixels();
    temp.pixels = webCam.pixels;
    temp.updatePixels();
    finalImgcv = new OpenCV(this, temp);

  }

  if( key == 'f' ){
    finalImgcv.diff(webCam);
    finalImgcv.threshold(10);
    finalImg = finalImgcv.getSnapshot();
    contours = finalImgcv.findContours();
    println("found " + contours.size() + " contours");
    M = contours.get(0);

    foreGExists = true;
  }
}
</code></pre>
]]></description>
   </item>
   <item>
      <title>** (java.exe:9372): WARNING **: gstvideo: failed to get caps of pad nat:sink</title>
      <link>https://forum.processing.org/two/discussion/17777/java-exe-9372-warning-gstvideo-failed-to-get-caps-of-pad-nat-sink</link>
      <pubDate>Sun, 07 Aug 2016 12:44:04 +0000</pubDate>
      <dc:creator>TheTroels</dc:creator>
      <guid isPermaLink="false">17777@/two/discussions</guid>
      <description><![CDATA[<p>Hello there!</p>

<p>I have borrowed this code for a school project. It creates a bouncing ball which you can control with you webcam by movements. Sometimes it works just fine, but there seem to be a bug saying</p>

<p><em>** (java.exe:9372): WARNING **: gstvideo: failed to get caps of pad nat:sink</em></p>

<p>And then the webcam won't stream. I stumbled upon a discussion with a similar problem, saying using loadPixels() and updatePixels - yet it did not remove the warning.</p>

<p>Below is the code</p>

<p>BackgroundBouncer.pde:</p>

<pre><code>import processing.video.*;
import gab.opencv.*;
import java.awt.Rectangle;

Capture video;
OpenCV opencv;
Ball b;

void setup() {
    size(640,480, P3D); //setup screen size and uses OpenGL gfx driver
    frameRate(30);
    ellipseMode(RADIUS); //set ellipse mode to radius (center point)
    video = new Capture(this, width/2, height/2);
    opencv = new OpenCV(this, width/2, height/2);
    b = new Ball();

    video.start();
    video.read();

    opencv.startBackgroundSubtraction(50,3,0.5); //detects moving objects

}

void draw() {
    clear();
    scale(2);
    loadPixels();
    opencv.loadImage(video); //
    opencv.flip(OpenCV.HORIZONTAL);
    opencv.updateBackground();
    opencv.calculateOpticalFlow(); //apparent motion between two frames caused by moving object or camera
    opencv.dilate(); //makes the image wider and look at neighbour pixels shape over which minimum is taken
    opencv.erode(); //erodes image and look at neighbour pixels shape over which minimum is taken
    noFill();stroke(255,0,0);
    strokeWeight(1);
    image(opencv.getOutput(), 0, 0);
    for (Contour c : opencv.findContours()) {
        Contour hull = c.getConvexHull();
        Rectangle box = hull.getBoundingBox();
        b.strike(c, opencv);
    }
    b.move();
    reflect(b);
    drawBall(b);
    updatePixels();

}

void keyPressed() {
    b.position = new PVector(120, 120);
    b.momentum = new PVector(0, 0);
}
void captureEvent(Capture c) {
  c.read();
}
</code></pre>

<p>And the Ball.pde:</p>

<pre><code>float decayRate = 0.9; //how much decay
float scalingFactor = 7; //how big a ball
PVector gravity = new PVector(0, 0.5); //how heavy
class Ball {
  public Ball() {
    size = 25;
    shade = #FF0000; //red ball
    position = new PVector(120, 120); //start position
    momentum = new PVector(0, 0); //a moment of stillness
  }
  public PVector position;
  public PVector momentum;
  public float size;
  public color shade;
  public void move() {
    position.add(momentum);
    momentum.add(gravity);
    momentum.mult(decayRate);
  }
  public void strike(Contour c, OpenCV opencv) {
    for (PVector p : c.getPoints()) {
        if (p.dist(position) &lt;= size) {
            Rectangle box = c.getBoundingBox();
            PVector flow = opencv.getAverageFlowInRegion(box.x, box.y, box.width, box.height);
            flow.mult(scalingFactor);
            momentum.add(flow);
            return;
        }
    }
  }
}

void drawBall(Ball b) {
    fill(b.shade);
    ellipse(b.position.x, b.position.y,
        b.size, b.size);
}

void reflect(Ball b) {
    if (b.position.x - b.size &lt;= 0) {
        b.position.x = b.size;
        b.momentum.x *= -1;
    } else if (b.position.x + b.size &gt; width/2) {
        b.position.x = width/2 - b.size;
        b.momentum.x *= -1;
    }
    if (b.position.y - b.size &lt;= 0) {
        b.position.y = b.size;
        b.momentum.y *= -1;
    } else if (b.position.y + b.size &gt; height/2) {
        b.position.y = height/2 - b.size;
        b.momentum.y *= -1;
    }
}
</code></pre>

<p>Any help or tips is welcomed! Thanks in advance.</p>
]]></description>
   </item>
   <item>
      <title>Problem combine 2 codes...</title>
      <link>https://forum.processing.org/two/discussion/22772/problem-combine-2-codes</link>
      <pubDate>Fri, 26 May 2017 12:03:16 +0000</pubDate>
      <dc:creator>Nicolejansen</dc:creator>
      <guid isPermaLink="false">22772@/two/discussions</guid>
      <description><![CDATA[<p>I got those two, and want to combine them but really, everything is false... Can someone help me out? 
<strong>first</strong></p>

<pre><code>// Click the mouse to memorize a current background image
import processing.video.*;
import gab.opencv.*;

// Variable for capture device
Capture video;
OpenCV opencv;

// Saved background
PImage backgroundImage;

// How different must a pixel be to be a foreground pixel
float threshold = 20;

void setup() {
  String[] cameras = Capture.list();
  //printArray(cameras);
  size(1280, 720);
  //video.width = 1280;
  //video.height = 720;
  video = new Capture(this, 1280, 720, cameras[76]);

  video.start();

  opencv = new OpenCV(this, 1280, 720);
  opencv.startBackgroundSubtraction(5, 3, 0.5);

  // Create an empty image the same size as the video
  backgroundImage = createImage(video.width, video.height, RGB);




}

void captureEvent(Capture video) {
  // Read image from the camera
  video.read();
}

void draw() {
  if (video.available() == true) {
    video.read();
  }
  image(video, random(width),random(height));

  opencv.loadImage(video);

  opencv.updateBackground();

  opencv.dilate();
  opencv.erode();

  noFill();
  stroke(255, 0, 0);
  strokeWeight(3);
  for (Contour contour : opencv.findContours()) {
    contour.draw();

}
}

void mousePressed() {

}
</code></pre>

<p>**
    **second code to combine with first one****
    **</p>

<pre><code>import processing.video.*;

Capture video;
int signal = 0;

//the buffer for storing video frames
ArrayList frames;

//different program modes for recording and playback
int mode = 0;
int MODE_NEWBUFFER = 0;
int MODE_RECORDING = 1;
int MODE_PLAYBACK = 2;

int currentX = 0;

void setup() {
  size(640, 480);

  // This the default video input, see the GettingStartedCapture 
  // example if it creates an error
  video = new Capture(this, width, height);

  // Start capturing the images from the camera
  video.start();  
}

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

  //create a new buffer in case one is needed
  if (mode == MODE_NEWBUFFER) {
    frames = new ArrayList();
    mode = MODE_RECORDING;
  }

  //record into the buffer until there are enough frames
  if (mode == MODE_RECORDING) {
    //copy the current video frame into an image, so it can be stored in the buffer
    PImage img = createImage(width, height, RGB);
    video.loadPixels();
    arrayCopy(video.pixels, img.pixels);

    frames.add(img);

    //in case enough frames have been recorded, switch to playback mode
    if (frames.size() &gt;= width) {
      mode = MODE_PLAYBACK;
    }
  }
}

void draw() { 
  loadPixels();

  //code for the recording mode 
  if (mode == MODE_RECORDING) {
    //set the image counter to 0
    int currentImage = 0;

    //begin a loop for displaying pixel columns
    for (int x = 0; x &lt; video.width; x++) {
      //go through the frame buffer and pick an image using the image counter
      if (currentImage &lt; frames.size()) {
        PImage img = (PImage)frames.get(currentImage);

        //display a pixel column of the current image
        if (img != null) {
          img.loadPixels();

          for (int y = 0; y &lt; video.height; y++) {
            pixels[x + y * width] = img.pixels[x + y * video.width];
          }  
        }

        currentImage++;

      } 
      else {
        break;
      }
    }
  }

  if (mode == MODE_PLAYBACK) {  

    for (int x = 0; x &lt; video.width; x++) {
      PImage img = (PImage)frames.get(x);

      if (img != null) {
        img.loadPixels();
        for(int y = 0; y &lt; video.height; y++) {
          pixels[x + y * width] = img.pixels[currentX + y * video.width];
        }  
      }
    } 

    currentX++;

    if(currentX &gt;= video.width) {
      mode = MODE_NEWBUFFER;
      //reset the column counter
      currentX = 0;
    }
  }

  updatePixels();
}
</code></pre>
]]></description>
   </item>
   <item>
      <title>How to replace each pixels from a video feed by an image ?</title>
      <link>https://forum.processing.org/two/discussion/22692/how-to-replace-each-pixels-from-a-video-feed-by-an-image</link>
      <pubDate>Sun, 21 May 2017 07:13:16 +0000</pubDate>
      <dc:creator>aboutband</dc:creator>
      <guid isPermaLink="false">22692@/two/discussions</guid>
      <description><![CDATA[<p>Hello Processing talented &amp; helpful community :)
I am Barbara, I am pretty new to Processing and I am working on a project that is giving me trouble right now.
Figured maybe someone here would hear my call and help out !</p>

<p>So here is the deal :
I have a pretty simple code, that basically displays the video from webcam feed, in pixels form.
What I am trying to do is REPLACE each pixel by an image.
Let's say I have 3 folders called : Blue Folder, Red Folder, Green Folder.
In each folder I have 100 pictures.
I want my code to randomly grab a picture in the folder in order to replace the pixel.
So all red pixels will go grab pictures from the red folder.
The results would look like a collage of hundreds of photos.</p>

<p>Do you think that is possible ?
I have been on this for over 2 weeks and cannot figure it out :(</p>

<p>HERE IS MY BASIC CODE:</p>

<pre><code>import processing.video.*;

int numPixels;
int blockSize = 10 ;
Capture video;
color collageColors[];

void setup() {
  size(displayWidth, displayHeight);
  noStroke();
  background(0);
  video = new Capture(this, displayWidth, displayHeight);
  numPixels = width / blockSize;
  collageColors = new color[numPixels * numPixels];
  video.start();
}

void captureEvent(Capture v) {
  v.read();
  v.loadPixels();

  for (int j = 0; j &lt; numPixels; j++) {
    for (int i = 0; i &lt; numPixels; i++) {
      collageColors[j*numPixels + i] = v.get(i*blockSize, j*blockSize);
    }
  }
}

void draw()  {

 if (video.available() == true) {
 video.read();
 image(video, 0, 0);
}

  for (int j = 0; j &lt; numPixels; j++) {
    for (int i = 0; i &lt; numPixels; i++) {
      fill(collageColors[j*numPixels + i]);
      rect(i*blockSize, j*blockSize, blockSize-1, blockSize-1);


    }
  }
}
</code></pre>
]]></description>
   </item>
   <item>
      <title>how to get better frameRate in motion detection</title>
      <link>https://forum.processing.org/two/discussion/22362/how-to-get-better-framerate-in-motion-detection</link>
      <pubDate>Wed, 03 May 2017 11:57:13 +0000</pubDate>
      <dc:creator>geekself108</dc:creator>
      <guid isPermaLink="false">22362@/two/discussions</guid>
      <description><![CDATA[<p>HI, I'm using following example for motion detection
<a rel="nofollow" href="https://github.com/shiffman/LearningProcessing/blob/master/chp16_video/example_16_13_MotionPixels/example_16_13_MotionPixels.pde">https://github.com/shiffman/LearningProcessing/blob/master/chp16_video/example_16_13_MotionPixels/example_16_13_MotionPixels.pde</a></p>

<p>This example was performed with camera(320,240) and its work nice but my canvas size is (1280,720) so the frameRate is getting very low near by 8 to 10fps and if i use camera with (640,480) then the feed is displaying twice seems like it duplicating.</p>

<p><strong>i want to display my live feed in full resolution which is (1280,720) so how can i scale up my camera which is (640,480) to (1280,720) ? (frameRate can be better with that resolution?)</strong></p>

<pre lang="javascript">


// Learning Processing
// Daniel Shiffman
// <a href="http://www.learningprocessing.com" target="_blank" rel="nofollow">http://www.learningprocessing.com</a>

// Example 16-13: Simple motion detection

import processing.video.*;
// Variable for capture device
Capture video;
// Previous Frame
PImage prevFrame;
// How different must a pixel be to be a "motion" pixel
float threshold = 50;

void setup() {
  size(1280, 720, P3D);
  video = new Capture(this, 640,480, 30);
  video.start();
  // Create an empty image the same size as the video
  prevFrame = createImage(video.width, video.height, RGB);
}

void captureEvent(Capture video) {
  // Save previous frame for motion detection!!
  prevFrame.copy(video, 0, 0, video.width, video.height, 0, 0, video.width, video.height); // Before we read the new frame, we always save the previous frame for comparison!
  prevFrame.updatePixels();  // Read image from the camera
  video.read();
}

void draw() {
  background(255);
  //pushMatrix();
  //scale(2.0);

  loadPixels();
  video.loadPixels();
  prevFrame.loadPixels();

  // Begin loop to walk through every pixel
  for (int x = 0; x &lt; video.width; x ++ ) {
  for (int y = 0; y &lt; video.height; y ++ ) {

//  for (int x = 440; x &lt; 840; x ++ ) {
//   for (int y = 0; y &lt; 400; y ++ ) {

      int loc = x + y*video.width;            // Step 1, what is the 1D pixel location
      color current = video.pixels[loc];      // Step 2, what is the current color
      color previous = prevFrame.pixels[loc]; // Step 3, what is the previous color

      // Step 4, compare colors (previous vs. current)
      float r1 = red(current); 
      float g1 = green(current); 
      float b1 = blue(current);
      float r2 = red(previous); 
      float g2 = green(previous); 
      float b2 = blue(previous);
      float diff = dist(r1, g1, b1, r2, g2, b2);

      // Step 5, How different are the colors?
      // If the color at that pixel has changed, then there is motion at that pixel.
      if (diff &gt; threshold) { 
        // If motion, display black 
        
        pixels[loc] = color(0);
      } else {
        // If not, display white
        pixels[loc] = color(255);
      }
    }
  }
  updatePixels();
  
//popMatrix();

  stroke(255, 0, 0);
  rect(440, 0, 400, 400);
  surface.setTitle((int) frameRate + " motion");
}

</pre>
]]></description>
   </item>
   <item>
      <title>how to remove alpha transparency from video ?</title>
      <link>https://forum.processing.org/two/discussion/22405/how-to-remove-alpha-transparency-from-video</link>
      <pubDate>Fri, 05 May 2017 11:55:12 +0000</pubDate>
      <dc:creator>saurabh</dc:creator>
      <guid isPermaLink="false">22405@/two/discussions</guid>
      <description><![CDATA[<p>Hi,</p>

<p>how can i play alpha transparent video without P3D OR P2D render ?</p>

<p>any help will be good</p>

<p>Thanks.</p>

<p>mycode:</p>

<pre lang="java">
import processing.video.*;
Movie mov;
PImage img;

Capture cam;

void setup() {
  size(640, 480);
  frameRate(30);

  mov = new Movie(this, "../../../files/movie/Final.mov");
  mov.play();

  cam = new Capture(this, 640, 480);
  cam.start();
}

void draw() {

  background(0);
  image(cam, 0, 0);
  image(mov, 0, 0);

}

void movieEvent(Movie m) {
  m.read();
}
void captureEvent(Capture cam) {
  cam.read();
}
</pre>
]]></description>
   </item>
   <item>
      <title>how to draw over a video in P3</title>
      <link>https://forum.processing.org/two/discussion/22183/how-to-draw-over-a-video-in-p3</link>
      <pubDate>Tue, 25 Apr 2017 02:16:00 +0000</pubDate>
      <dc:creator>c_borgs</dc:creator>
      <guid isPermaLink="false">22183@/two/discussions</guid>
      <description><![CDATA[<p>I have been trying to emulate something like this sketch: <span class="VideoWrap"><span class="Video YouTube" id="youtube-z-3ZGrBjQ4g"><span class="VideoPreview"><a href="http://youtube.com/watch?v=z-3ZGrBjQ4g"><img src="http://img.youtube.com/vi/z-3ZGrBjQ4g/0.jpg" width="640" height="385" border="0" /></a></span><span class="VideoPlayer"></span></span></span>
with a few other features as well. 
i've been able to track the color but have not been successful at keeping the trial it creates as a drawing over the video.
I've tried topLayer in P2 without success, and i am now thinking about how i might make the color track a separate object. Below is what I have so far</p>

<p>Any and all insight/ help would be greatly appreciated!!</p>

<p>`
    import processing.video.*;</p>

<pre><code>// Variable for capture device
Capture video;

// A variable for the color we are searching for.
color trackColor; 

float threshold = 25;

void setup() {
  size(640, 360);
  String[] cameras = Capture.list();
  printArray(cameras);
  video = new Capture(this, cameras[3]);
  video.start();
  // Start off tracking for red
  trackColor = color(255, 0, 0);
}

void captureEvent(Capture video) {
  // Read image from the camera
  video.read();
}

void draw() {
  video.loadPixels();
  image(video, 0, 0);

  textSize(12);
  text("pick a tool, click the color, draw yourself a friend", 10, 30); 
  stroke(#FFFFFF);

  textSize(12);
  text("press space to save your sketch", 10, 330); 
  fill(#FFFFFF);  

  // XY coordinate of closest color
  float avgX = 0;
  float avgY = 0;

  int count = 0;

  // Begin loop to walk through every pixel
  for (int x = 0; x &lt; video.width; x++ ) {
    for (int y = 0; y &lt; 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 (d &lt; threshold) {
        avgX += x;
        avgY += y;
        count++;
      }
    }
  }

  // We only consider the color found if its color distance is less than 10. 
  // This threshold of 10 is arbitrary and you can adjust this number depending on how accurate you require the tracking to be.
  if (count &gt; 0) { 
    avgX = avgX / count;
    avgY = avgY / count;

    // Draw a circle at the tracked pixel
    fill(trackColor);
    noStroke();
    ellipse(avgX, avgY, 8, 8);
  }
}

void mousePressed() {
  // Save color where the mouse is clicked in trackColor variable
  int loc = mouseX + mouseY*video.width;
  trackColor = video.pixels[loc];
}

void keyPressed() {
  if (key == ' ') { //space bar
  saveFrame("picture-####.jpg");
  }
}
</code></pre>

<p>`</p>
]]></description>
   </item>
   <item>
      <title>interactive screen using live video, changing letters positions</title>
      <link>https://forum.processing.org/two/discussion/22123/interactive-screen-using-live-video-changing-letters-positions</link>
      <pubDate>Fri, 21 Apr 2017 11:34:54 +0000</pubDate>
      <dc:creator>MilaYume</dc:creator>
      <guid isPermaLink="false">22123@/two/discussions</guid>
      <description><![CDATA[<p>Hello, I'm new to programming with Processing. Trying to make a code for my art bachelor degree. What I want to do: make the interactive screen, filled with letters(text), with a live cam recording what's happening in front, detecting motion. When there is a motion letter that meets motion line(human body contours) flips position with a letter from the side with motion come from. 
for that as a base, I used raindrops sketch and Shiffman's Example 16-13: Simple motion detection.
But now I'm getting a gray screen and letters appear non-stop. Did I mess up something with arrays? should text be put not in a string? I read about Kinect but not sure if it would help at this point. Hope to get hints or something that to do next :]</p>

<pre><code>    import processing.video.*;
    import java.awt.Frame;
    import java.awt.Image;
    import java.text.*;

    Capture cam;
    Letter[][] drops;
    int dropsLength;
    PImage prevFrame;
    int sWidth = 1280;
    int sHeight = 720;

    String inputString = "Įsivaizduokime pasaulį, kur visi viską žino tiksliai, ir niekada neklysta. Niekam nekiltų abejoių, koks bus rytoj oras, kaip išsaugoti tirpstačius ledynus, ar koks visatos dydis. Žvelgiant į krentantį kamuoliuką kiekvienas galėtų pasakyti: -  O šito kamuoliuko kritimo greitis 6,325 m/s. -  Tikrai taip - atsakytų kitas. Ir viskas, daugiau nebebūtų jokių diskusijų, ieškojimų, matavimų. Su absoliučiu žinojimu gyvenimas taptų nebeįdomus, monotoniškas, tokiu atveju net progresas neįmanomas. Kai pradedu taip galvoti, džiaugiuosi nežinojimu, diskusijų galimybe, tiesos ieškojimu. Klaida suvokiama kaip neišvengiamas procesas teisybės ieškojime leidžia drąsiai žengti į praktikos sritį, nebijoti suklysti, o neteisingus procesus paversti progresu, žingsneliu link tikslo. Menininkas nebėra tas genijus, kuris turi sukurti kažką naujo, tarsi nežemiško, keičiančio visą mūsų suvokimą. Jo praktikos esmė eksperimentuoti ir klysti, organizuoti jau esamomis reikšmėmis ir kurti nau";
    char[] inputLetters;
    int dupStrings = 3;   //times to dublicate text
    int k = 800;
    float threshold = 50;

    void settings() {
      size(1280, 720);
    }
    void setup() {
      String[] cameras = Capture.list();

      drops = new Letter[dupStrings][inputString.length()];  //[inputString.length()]; 

      int wspace = 50;
      inputLetters = new char[inputString.length()]; 
      splitString();


      // first row hight
      int addLineHeight = 30;                                                       
      for (int i = 0; i &lt; dupStrings; i++) {     
            for (int j = 0; j &lt; inputLetters.length; j++) {   
                 if  (inputLetters[j] &lt; k + wspace ){
                   Letter testLetter = new Letter(inputLetters[j]);
                   testLetter.x = wspace;
                   testLetter.y = addLineHeight;
                   drops[i][j] = testLetter;
                   wspace += 10;   //spaces between letters

                   // new row
                   if (wspace &gt;= sWidth) {   
                                wspace = 10;
                               addLineHeight += 40; } // space between 

                    }
                           else {
                               addLineHeight += 50;
                                }
                                                                  }
                                               }
    // cam conect//

      if (cameras.length == 0) {
        println("There are no cameras available...");
        size(400, 400);
        exit();
      }
      else {
        cam = new Capture(this, sWidth, sHeight);
        cam.start();
        cam.loadPixels();
        prevFrame = createImage(cam.width, cam.height, RGB);

        size(sWidth, sHeight);
      }
      dropsLength = inputString.length();
    }

    void captureEvent(Capture cam) {
      // Save previous frame for motion detection!!
      prevFrame.copy(cam, 0, 0, cam.width, cam.height, 0, 0, cam.width, cam.height); 
      // Before we read the new frame, we always save the previous frame for comparison!```
      prevFrame.updatePixels();  // Read image from the camera
      cam.read();
    }


    void splitString() { 

      for (int i = 0; i &lt; inputString.length() ; i++) {
        inputLetters[i] = inputString.charAt(i);
      }
    }

    void draw() {

        loadPixels();
      cam.loadPixels();
      prevFrame.loadPixels();
        // Begin loop to walk through every pixel
      for (int x = 0; x &lt; cam.width; x ++ ) {
        for (int y = 0; y &lt; cam.height; y ++ ) {

          int loc = x + y*cam.width;            // Step 1, what is the 1D pixel location
          color current = cam.pixels[loc];      // Step 2, what is the current color
          color previous = prevFrame.pixels[loc]; // Step 3, what is the previous color

          // Step 4, compare colors (previous vs. current)
          float r1 = red(current); 
          float g1 = green(current); 
          float b1 = blue(current);
          float r2 = red(previous); 
          float g2 = green(previous); 
          float b2 = blue(previous);
          float diff = dist(r1, g1, b1, r2, g2, b2);

          // Step 5, How different are the colors?
          // If the color at that pixel has changed, then there is motion at that pixel.
          if (diff &gt; threshold) { 
            // If motion, display black
            pixels[loc] = color(0);
          } else {
            // If not, display white
            pixels[loc] = color(255);
          }
        }
      }

       //Responding to the brightness/color of the screen
       for (int i = 0; i &lt; dupStrings; i++) {
        for (int j = 0; j &lt; dropsLength; j++) {

          if (drops[i][j].y &lt; sHeight &amp;&amp; drops[i][j].y &gt; 0) {   
           int loc = drops[i][j].x + ((drops[i][j].y)-1)*sWidth;                                           
           float bright = brightness(cam.pixels[loc]);                                                                                                                                                          
            if (bright &gt; threshold) {   
              drops[i][j].dropLetter();
              drops[i][j].upSpeed = 1;
            }
            else {                                                                            
              if (drops[i][j].y &gt; threshold) {
                int aboveLoc = loc = drops[i][j].x + ((drops[i][j].y)-1)*sWidth;
                float aboveBright = brightness(cam.pixels[aboveLoc]);
                if (aboveBright &lt; threshold) {                                              
                  drops[i][j].liftLetter();
                  drops[i][j].upSpeed = drops[i][j].upSpeed * 5;                           
                }
              }
            }
          }
          else {
            drops[i][j].dropLetter(); 
          }

          drops[i][j].drawLetter();
          cam.updatePixels();
        }
      }
    }

    class Letter {
      int x;
      int y; 
      int m;
      char textLetter;
      int upSpeed;
      int alpha = 150;
      Letter(char inputText) {
        x = 100;
        y = 100;
        textLetter = inputText;
        textSize(16);
        upSpeed = 1;
      }
      void drawLetter() {
       // if ( m &lt; 1) {
        fill(150, 150, 150 , alpha);                 
        text(textLetter, x, y);

      }

      void letterFade() {
        alpha -= 5;
        if(alpha &lt;= 0) {
          y = int(random(-350, 0));
          alpha = 255; 
        }
      }


      void dropLetter() {
      //  y++;                         
        if (y &gt; 730) {
          letterFade();
        }
      }

      void liftLetter() {
        int newY = y - upSpeed;       
        if (newY &gt;= 0) {
          y = newY;
        }
        else {
          y = 0;
        }
      }
    }
</code></pre>
]]></description>
   </item>
   <item>
      <title>Approach to utilise variable data from Draw</title>
      <link>https://forum.processing.org/two/discussion/21817/approach-to-utilise-variable-data-from-draw</link>
      <pubDate>Wed, 05 Apr 2017 03:03:12 +0000</pubDate>
      <dc:creator>matt82au</dc:creator>
      <guid isPermaLink="false">21817@/two/discussions</guid>
      <description><![CDATA[<p>Hello! New to Processing and have been experimenting with the tutorials and videos a bit, and have a hit a hurdle I am sure someone will have some insight to.</p>

<p>Essentially, I am trying to take the colour tracking algorithm from Tutorial 11.5, and utilise the avgX variable to control the panning of a sine wave. My code is below...</p>

<pre><code>// Daniel Shiffman
// <a href="http://codingtra.in" target="_blank" rel="nofollow">http://codingtra.in</a>
// <a href="http://patreon.com/codingtrain" target="_blank" rel="nofollow">http://patreon.com/codingtrain</a>
// Code for: <span class="VideoWrap"><span class="Video YouTube" id="youtube-nCVZHROb_dE"><span class="VideoPreview"><a href="http://youtube.com/watch?v=nCVZHROb_dE"><img src="http://img.youtube.com/vi/nCVZHROb_dE/0.jpg" width="640" height="385" border="0" /></a></span><span class="VideoPlayer"></span></span></span>

import processing.video.*;
import processing.sound.*;

SinOsc sine;
Capture video;

color trackColor; 
float threshold = 25;

void setup() {
  size(640, 360);
  String[] cameras = Capture.list();
  //printArray(cameras);
  video = new Capture(this, cameras[3]);
  video.start();
  trackColor = color(255, 0, 0);
}

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

void draw() {
  video.loadPixels();
  image(video, 0, 0);

  //threshold = map(mouseX, 0, width, 0, 100);
  threshold = 20;

  float avgX = 0;
  float avgY = 0;

  int count = 0;

  // Begin loop to walk through every pixel
  for (int x = 0; x &lt; video.width; x++ ) {
    for (int y = 0; y &lt; 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);

      float d = distSq(r1, g1, b1, r2, g2, b2); 

      if (d &lt; threshold*threshold) {
        stroke(255);
        strokeWeight(1);
        point(x, y);
        avgX += x;
        avgY += y;
        count++;
      }
    }
  }

  // We only consider the color found if its color distance is less than 10. 
  // This threshold of 10 is arbitrary and you can adjust this number depending on how accurate you require the tracking to be.
  if (count &gt; 0) { 
    avgX = avgX / count;
    avgY = avgY / count;
    // Draw a circle at the tracked pixel
    fill(255);
    strokeWeight(4.0);
    stroke(0);
    ellipse(avgX, avgY, 24, 24);


  }
}

float distSq(float x1, float y1, float z1, float x2, float y2, float z2) {
  float d = (x2-x1)*(x2-x1) + (y2-y1)*(y2-y1) +(z2-z1)*(z2-z1);
  return d;

}

void mousePressed() {
  // Save color where the mouse is clicked in trackColor variable
  int loc = mouseX + mouseY*video.width;
  trackColor = video.pixels[loc];
}
  {
      sine = new SinOsc(this);
      sine.pan(map(avgX, 0, width, -1.0, 1.0));
      sine.play();
}  
</code></pre>

<p>The problem is that the variable avgX cannot exist outside the draw. It works if I place the Oscillator in Draw, but that causes a crash in a hurry!</p>

<p>Any help greatly appreciated!</p>

<p>Best,
Matt</p>
]]></description>
   </item>
   <item>
      <title>Create an Image Mask On Top of a Live Feed</title>
      <link>https://forum.processing.org/two/discussion/18966/create-an-image-mask-on-top-of-a-live-feed</link>
      <pubDate>Thu, 10 Nov 2016 01:06:07 +0000</pubDate>
      <dc:creator>lbrez16</dc:creator>
      <guid isPermaLink="false">18966@/two/discussions</guid>
      <description><![CDATA[<p>Hey all!</p>

<p>So for this code I'm trying to create a code that will use a live webcam feed and face tracking to put an image on top of the tracked face. After this point, I want to press a key ('n' in the code I posted below) and have it switch to a different picture. Right now as a base code I have processing's "LiveFaceTracking" example in my code. Any help you guys could give me would be greatly appreciated!</p>

<pre><code>    import gab.opencv.*;
    import processing.video.*;
    import java.awt.*;
    PImage WD;
    PImage GJ;

    Capture video;
    OpenCV opencv;

    void setup() {
      size(640, 480);
      video = new Capture(this, 640/2, 480/2);
      opencv = new OpenCV(this, 640/2, 480/2);
      opencv.loadCascade(OpenCV.CASCADE_FRONTALFACE);
      video.start();

      loadImage("WD");
      loadImage("GJ");
    }

    void draw() {
      scale(2);
      opencv.loadImage(video);

      image(video, 0, 0 );

      noFill();
      stroke(0, 255, 0);
      strokeWeight(3);
      Rectangle[] faces = opencv.detect();
      println(faces.length);

      for (int i = 0; i &lt; faces.length; i++) {
        println(faces[i].x + "," + faces[i].y);
        rect(faces[i].x, faces[i].y, faces[i].width, faces[i].height);
      }
    }

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

    void keyPressed(){
      if(key = 'n'){
        loadImage = WD;
</code></pre>
]]></description>
   </item>
   <item>
      <title>NullPointer Exception Issue</title>
      <link>https://forum.processing.org/two/discussion/21566/nullpointer-exception-issue</link>
      <pubDate>Thu, 23 Mar 2017 23:09:27 +0000</pubDate>
      <dc:creator>AndresAlejandro</dc:creator>
      <guid isPermaLink="false">21566@/two/discussions</guid>
      <description><![CDATA[<p>I have a code that I need running for several hours. After several minutes it stops responding altogether (and I have to force quit the application) and gives me the error "NullPointer Exception" and highlights line 106. I have not been able to solve this, it may be because it runs out of pixels to grab? I am not sure. Another issue I am having is that it is using both my USB camera and my built-in mac camera. How do I get it to only use the USB camera? 
    final int kTotalGlitches=10;
    int currGlitch=0;
    PImage img;
    ArrayList glitches;</p>

<pre><code>final int kGlitchState=0;
final int kCamState=1;

int state=kCamState;


// ---------------------------------

final int kGlitchTimeLapse=7000;  // 2 secs
final int kCamTimeLapse=5000;    //8 secs
int triggerTime;

// ---------------------------------


import processing.video.*; 
Capture cam; 
Capture video;



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

  glitches = new ArrayList &lt;GlitchClass&gt;();
  for (int i=0; i&lt;kTotalGlitches; i++)
    glitches.add(new GlitchClass());

  cam = new Capture(this);
  cam.start();
  triggerTime=millis()+kCamTimeLapse;
  img = cam;
  video = new Capture(this, width, height);
  video.start();
} 

void draw() { 

  if (millis()&gt;=triggerTime) {

    if (state==kCamState) {
      state=kGlitchState;
      triggerTime+=kGlitchTimeLapse;
      currGlitch=int(random(kTotalGlitches));  //Select new glitch
    } else {
      state=kCamState;
      triggerTime+=kCamTimeLapse;
    }
  }

  if (state==kCamState)
    image(cam, width/2, height/2);
  else {
    background(0);
    glitches.get(currGlitch).display();
  }
} 


void captureEvent(Capture camera) {
  camera.read();

  img = createImage(width, height, RGB);
  video.loadPixels();
  arrayCopy(video.pixels, img.pixels);
}


//A glitch is just two ellipses overlapping on top of each other with different
//colors and one being rotated by 90 degrees.
class GlitchClass {

  void display() {

    loadPixels();

    int randPos = 0;
    if (frameCount  % 100 == 0)
      randPos = (int)random(0, video.height -4);

    int randPosY = 0;

    // if (frameCount  % 100 == 0)
    randPosY = (int)random(20, 50);

    // Begin a loop for displaying pixel rows of 4 pixels height
    for (int y = 0; y &lt; video.height -57; y++) {
      if (img != null) {
        img.loadPixels();

        // Put 4 rows of pixels on the screen
        if (frameCount % 50 == 0)
          randPosY = (int)random(20, 50);
        for (int x = 0; x &lt; video.width; x++) {
          if (frameCount % 100 == 0)
            randPosY = (int)random(20, 50);
          if (y &lt; video.height -4) {
            pixels[x + (y + 0 + randPosY)* width] = img.pixels[  (y + 0 )* video.width + randPos + x];
            pixels[x + (y + 1 + randPosY) * width] = img.pixels[ (y + 1) * video.width + randPos + 1 + x];
            pixels[x + (y + 2 + randPosY) * width] = img.pixels[ (y + 2) * video.width + randPos + 2 + x];
            pixels[x + (y + 3 + randPosY) * width] = img.pixels[ (y + 3) * video.width + randPos + 3 + x];

            pixels[x + (y + 4 + randPosY)* width] = img.pixels[  (y + 4 )* video.width + randPos + 4 + x];
            pixels[x + (y + 5 + randPosY) * width] = img.pixels[ (y + 5) * video.width + randPos + 5 + x];
            pixels[x + (y + 6 + randPosY) * width] = img.pixels[ (y + 6) * video.width + randPos + 6 + x];
            pixels[x + (y + 7 + randPosY) * width] = img.pixels[ (y + 7) * video.width + randPos + 7 + x];
          }
        }
      } else {
        break;
      }
    }

    updatePixels();
  }
}
</code></pre>

<p>Thanks!</p>
]]></description>
   </item>
   <item>
      <title>Draw object on new canvas to hide motion detection</title>
      <link>https://forum.processing.org/two/discussion/21313/draw-object-on-new-canvas-to-hide-motion-detection</link>
      <pubDate>Fri, 10 Mar 2017 16:26:24 +0000</pubDate>
      <dc:creator>selmabrd</dc:creator>
      <guid isPermaLink="false">21313@/two/discussions</guid>
      <description><![CDATA[<p>Hello guys.
I'm trying to achieve a program where ellipse spirals are drawn based on a motion tracking.</p>

<p>I need to use the createGraphics() function in order to hide the result of the captureEvent function and draw my spirals on the top of it, all the previous spirals should be visible.
I can't make createGraphics work properly. Do I need two different objects?</p>

<p>Here's my code :</p>

<pre><code>import processing.video.*;

Capture video;
PImage prev;

float threshold = 25;

float motionX = 0;
float motionY = 0;

float lerpX = 0;
float lerpY = 0;

int cnt = 0;

PGraphics p1;

Spiral spi = new Spiral();

void setup(){
  size(640, 480);

  p1 = createGraphics(width, height);
  p1.beginDraw();
  p1.colorMode(HSB, 360, 100, 100);
  p1.background(255);
  p1.noStroke();
  p1.endDraw();

  String[] cameras = Capture.list();
  printArray(cameras);
  video = new Capture(this, cameras[13]);
  video.start();
  prev = createImage(640, 480, RGB);

}

void draw(){
  video.loadPixels();
  prev.loadPixels();

  threshold = 50;
  int count = 0;
  float avgX = 0;
  float avgY = 0;

   loadPixels();
  // Begin loop to walk through every pixel
  for (int x = 0; x &lt; video.width; x++ ) {
    for (int y = 0; y &lt; 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);
      color prevColor = prev.pixels[loc];
      float r2 = red(prevColor);
      float g2 = green(prevColor);
      float b2 = blue(prevColor);

      float d = distSq(r1, g1, b1, r2, g2, b2); 

      if (d &gt; threshold*threshold) {
        avgX += x;
        avgY += y;
        count++;
        pixels[loc] = color(255);
      } else {
        pixels[loc] = color(0);
      }
    }
  }
  updatePixels();

  if (count &gt; 200) { 
    motionX = avgX / count;
    motionY = avgY / count;
  }

  lerpX = lerp(lerpX, motionX, 0.1); 
  lerpY = lerp(lerpY, motionY, 0.1); 


  spi.update();
  spi.display();

  if (cnt == 50 || cnt == 100) spi.reset();
  cnt += random(5);
  if (cnt &gt;= 200) cnt=0;
}

void captureEvent(Capture video) {
  prev.copy(video, 0, 0, video.width, video.height, 0, 0, prev.width, prev.height);
  prev.updatePixels();
  video.read();
}

float distSq(float x1, float y1, float z1, float x2, float y2, float z2) {
  float d = (x2-x1)*(x2-x1) + (y2-y1)*(y2-y1) +(z2-z1)*(z2-z1);
  return d;
}
</code></pre>

<p>and my class :</p>

<pre><code>class Spiral {
  float ang, radians;
  float x;
  float y;
  float size;
  PVector origin;
  float alpha, hue, sat;

  Spiral(){
    ang=0;
    radians=2;
    size = 10;
    origin = new PVector(width/2, height/2);
    alpha = 255.;
    hue = random(330);
    sat = random(30, 100);
 }

 void reset(){
  ang =0;
  radians =2;
  size = 10;
  alpha = 255;
  hue = random(330);
  sat = random(30, 100);
  origin = new PVector(lerpX, lerpY);
}

 void update(){
   x = origin.x + radians *sin(ang);
   y = origin.y + radians *cos(ang);
   ang += .4;
   alpha -= 1.3;
   radians += 0.5;

   size += 0.08;
   hue += 0.2;
}

  void display(){
    p1.beginDraw();
    p1.fill(hue, sat, 255, alpha);  
    p1.ellipse(x,y,size,size); 
    p1.endDraw();
  }
}
</code></pre>
]]></description>
   </item>
   <item>
      <title>Panorama using a webcam</title>
      <link>https://forum.processing.org/two/discussion/21046/panorama-using-a-webcam</link>
      <pubDate>Tue, 28 Feb 2017 06:34:50 +0000</pubDate>
      <dc:creator>denyszandonadi</dc:creator>
      <guid isPermaLink="false">21046@/two/discussions</guid>
      <description><![CDATA[<p>Hello, first time here!</p>

<p>I'm trying to stitch images from frames of a webcam. Actually, I want to make a mosaic(or panorama) image, like shown on this videos:</p>

<p><a rel="nofollow" href="https://youtu.be/aXYnAfZ4bD4?t=15s">https://youtu.be/aXYnAfZ4bD4?t=15s</a></p>

<p><a rel="nofollow" href="https://www.youtube.com/watch?v=QapSxGnUWtY&amp;t">https://youtube.com/watch?v=QapSxGnUWtY&amp;t</a></p>

<p>I don't need to correct lenses, rotation or perspective. I only need to move the image in XY plane, like de first video. Even if I move only on X is ok for now.</p>

<p>So far, I was able to stitch 2 static images. But when I try to make this with a camera, something goes wrong  :(</p>

<p>This is my code:</p>

<pre><code>    import boofcv.processing.*;
    import boofcv.struct.image.*;
    import boofcv.struct.feature.*;
    import georegression.struct.point.*;
    import java.util.*;
    import processing.video.*;

    Capture video;

    PImage prevFrame;
    PImage current;

    int leu = 0;
    int c = 1;
    float avgX = 0;
    float avgY = 0;

    List&lt;Point2D_F64&gt; locations0, locations1;      // feature locations
    List&lt;AssociatedIndex&gt; matches;      // which features are matched together

    void setup() {

      size(600, 240);
      video = new Capture(this, 320, 240, 30);
      video.start();

      prevFrame = createImage(video.width, video.height, RGB);
      current = createImage(video.width, video.height, RGB);
    }
    void detectar() {
      SimpleDetectDescribePoint ddp = Boof.detectSurf(true, ImageDataType.F32);  //use SURF
      SimpleAssociateDescription assoc = Boof.associateGreedy(ddp, true);  

      // Find the features
      ddp.process(prevFrame);
      locations0 = ddp.getLocations();
      List&lt;TupleDesc&gt; descs0 = ddp.getDescriptions();

      ddp.process(current);
      locations1 = ddp.getLocations();
      List&lt;TupleDesc&gt; descs1 = ddp.getDescriptions();

      // associar os pontos
      assoc.associate(descs0, descs1);
      matches = assoc.getMatches();
    }

    void draw() {

      loadPixels();
      video.loadPixels();
      prevFrame.loadPixels();

      detectar();
      int count = 0;
      for ( AssociatedIndex i : matches ) {     
        if ( count++ % 20 != 0 )
          continue;
        else if ( count &gt; 100)
        {       
          break;
        }

        Point2D_F64 p0 = locations0.get(i.src); 
        Point2D_F64 p1 = locations1.get(i.dst); 
        float diferencaX = abs((float) p0.x - (float)p1.x);
        float diferencaY = abs((float) p0.y - (float)p1.y);    

        if (leu &lt; 30) {

          if (diferencaY &lt; 15) {
            avgX = avgX + (diferencaX - avgX)/c;
            avgY = avgY + (diferencaY - avgY)/c;
            c++;  
          }
        }

        if ( leu == 29) {
          if (avgX &gt; 300) {    
            translacao();
          }
        }
        leu++;
      }
    }

    void translacao() {
      image( prevFrame, 0, 0 );
      image( current, avgX, -avgY);
      updatePixels();
      println(avgX);
      c = leu = 0;
      avgX = avgY = 0;
    }

    void captureEvent(Capture video) {
      // Save previous frame for motion detection!!
      // Before we read the new frame, we always save the previous frame for comparison!
      if (avgX &gt; 300) {
        prevFrame.copy(video, 0, 0, video.width, video.height, 0, 0, video.width, video.height); 
        prevFrame.updatePixels();  // Read image from the camera
      }
      video.read();
      current.copy(video, 0, 0, video.width, video.height, 0, 0, video.width, video.height); 
      current.updatePixels();
    }
</code></pre>

<p>I appreciate any help!
Thank you!</p>
]]></description>
   </item>
   <item>
      <title>problem full screen with color tracking and webcam</title>
      <link>https://forum.processing.org/two/discussion/21053/problem-full-screen-with-color-tracking-and-webcam</link>
      <pubDate>Tue, 28 Feb 2017 11:49:39 +0000</pubDate>
      <dc:creator>pietrondo</dc:creator>
      <guid isPermaLink="false">21053@/two/discussions</guid>
      <description><![CDATA[<p>Hi!
I have a big question, I'm trying to go to full screen with a simple colortracking game but my webcam doesn't support the resolution of my monitor.
(I'm playing with Shiffman code).</p>

<p>How can I do? I have tried with image to resize the output but after how Can i "take" (I'm not english native speaker) the right pixel of the output to use for the color traking (and not the pixel of the low-res camera)?</p>

<p>thx</p>
]]></description>
   </item>
   <item>
      <title>Blur logic but i don't think its working );</title>
      <link>https://forum.processing.org/two/discussion/20838/blur-logic-but-i-don-t-think-its-working</link>
      <pubDate>Fri, 17 Feb 2017 03:33:06 +0000</pubDate>
      <dc:creator>Anupam</dc:creator>
      <guid isPermaLink="false">20838@/two/discussions</guid>
      <description><![CDATA[<pre><code>            import processing.video.*;

            Capture video;
            PImage frog;
            public static final int[][] mask = {{1, 1, 1},
                                                   {1, 1, 1},
                                                   {1, 1, 1} };
            void setup()
            {
            size(640,480);
            video = new Capture(this,640,480);
            video.start();
            frog = loadImage("frog.jpg");

            }

            void captureEvent(Capture video){

              video.read();
            }


            void draw()
            {

              loadPixels();
              video.loadPixels();
              frog.loadPixels();
              for(int x=1;x+1&lt;video.width;x++)
              {
               for(int y=1;y+1&lt;video.height;y++)
               {
                 int loc  =  x+y*video.width;



                 color value  = applyBlur(video,x,y,mask);

                 pixels[loc] = value;


               }
              }
              updatePixels();
              }


              color applyBlur(Capture video,int x,int y,int[][] mask)
              {
                int red=0,green=0,blue=0;
                for(int j=-1;j&lt;=1;j++)
                {
                 for(int k=-1;k&lt;=1;k++)
                 {

                    red  += mask[1+j][1+k]*(red(video.get(x+k,y+j))); 
                    green +=mask[1+j][1+k]*(green(video.get(x+k,y+j)));
                    blue  += mask[1+j][1+k]*(blue(video.get(x+k,y+j)));
                 } 
                }
                   red = red/findSum(mask);
                   green = green/findSum(mask);
                   blue = blue/findSum(mask);

                   color value  = color(red,green,blue);
                   return value;

              }

              int  findSum(int[][] mask)
              {
                int sum=0;
                for(int y=0;y&lt;mask.length;y++)
                {
                   for(int x=0;x&lt;mask[y].length;x++)
                   {
                     sum += mask[y][x];
                   }
                }
                  return sum;

              }
</code></pre>
]]></description>
   </item>
   <item>
      <title>Unexpected token: void()</title>
      <link>https://forum.processing.org/two/discussion/20733/unexpected-token-void</link>
      <pubDate>Fri, 10 Feb 2017 11:19:55 +0000</pubDate>
      <dc:creator>million_of_peaches</dc:creator>
      <guid isPermaLink="false">20733@/two/discussions</guid>
      <description><![CDATA[<p>Hi, I'm (really) new with processing. Can anyone help me with this code? please :)
I cannot find why I get unexpected token: void() in this code:</p>

<p>import processing.video.*;
Capture webcam;
int w=400;
int h=400;
int pixn=w*h;
int keyhits;
PImage img;
int i= 0</p>

<p>void setup() {
  size(w, h);
  webcam = new Capture(this, 400, 400);
  webcam.start();
  loadPixels();
}</p>

<p>void captureEvent(Capture webcam) {
  webcam.read();
}
void draw() {
  image(webcam, 0, 0);
}</p>

<p>void keyPressed() {</p>

<p>if ( key == '1' ) {
    save("capture" + ++keyhits + ".jpg");
  }</p>

<p>img = loadImage("capture"+keyhits+".jpg");
  int x = int(img.width);
  int y = int(img.height);
  float r = red(img.pixels[i]);
  float g = green(img.pixels[i]);
  float b = blue(img.pixels[i]);</p>

<p>for (int i=0; i&lt;pixn; i++) {
    float sumar = sumar + red(img.pixels[i]);
    float sumag = sumag + green(img.pixels[i]);
    float sumab = sumab + blue(img.pixels[i]);
  }</p>

<p>float mediar = sumar / pixn);
  float mediag = sumag / pixn);
  float mediab = sumab / pixn);</p>

<p>if ( key == '2' ) {
    fill(mediar, mediag, mediab, 255);
    rect(0, 0, 400, 400);
    save("average_color"+ keyhits + ".jpg");
  }
}</p>
]]></description>
   </item>
   <item>
      <title>question about what i did wrong</title>
      <link>https://forum.processing.org/two/discussion/20525/question-about-what-i-did-wrong</link>
      <pubDate>Sat, 28 Jan 2017 23:53:11 +0000</pubDate>
      <dc:creator>sLucas</dc:creator>
      <guid isPermaLink="false">20525@/two/discussions</guid>
      <description><![CDATA[<p>my Code:</p>

<pre><code>import processing.video.*;

Capture video;



void setup() {
  size(640, 480);
  pixelDensity(1);
  frameRate(60);
  String[] cameras = Capture.list();
  printArray(cameras);
  video = new Capture(this, cameras[1]);
  video.start();
}

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



void draw() {

  video.loadPixels();
  image(video, 0, 0);
  grid();
}

void grid() {
  int square = 0;
  int nr = 20;
  int[] avg = new int[width * height];
  background(255, 0, 0);
  loadPixels();
  if (width % nr == 0 &amp; height % nr == 0) {
    for (int s1 = 0; s1 &lt; height; s1 += height/nr) {
      for (int s2 = 0; s2 &lt; width; s2 += width/nr) {

        for (int x = 0; x &lt; width/nr; x++) {
          for (int y = 0; y &lt; height/nr; y++) {
            square = (x + y * width) + s1 * width + s2;
            avg[square] = int(brightness(get(x + s2, y + s1 * width)));
            pixels[square] = color(avg[square]);
          }
        }

      }
    }
    updatePixels();
  }
}
</code></pre>

<p>END</p>

<p>when i run this code it only shows me a black screen. I already tried the same code with just slightly changed for() loops</p>

<pre><code>void grid() {
  int[] avg = new int[width*height]; 
  loadPixels();
  for (int x = 0; x &lt; width; x++) {
    for (int y = 0; y &lt; height; y++) {
      avg[x+y*width] = int(brightness(get(x,y)));
      pixels[x+y*width] = color(avg[x+y*width]);
    }
  }
  updatePixels();
}
</code></pre>

<p>and it worked 100% correct, so I assume the problem must be in the for() loops or how i used the variables s1 and s2, but I just can not find the mistake. Thanks in advance.</p>

<p>~sLucas</p>
]]></description>
   </item>
   <item>
      <title>How to track an image moving?</title>
      <link>https://forum.processing.org/two/discussion/20130/how-to-track-an-image-moving</link>
      <pubDate>Sat, 07 Jan 2017 15:45:23 +0000</pubDate>
      <dc:creator>Markx</dc:creator>
      <guid isPermaLink="false">20130@/two/discussions</guid>
      <description><![CDATA[<p>Hello i'm new to processing and i'm working on a little game. But i got a problem:</p>

<p>I don't know how to tell the position (x,y) of my image "train" (in draw section) in order to make my background ("fond"
) move .</p>

<p>Thanks in advance.</p>

<pre><code>import processing.sound.*;
import gab.opencv.*;
import processing.video.*;
import java.awt.*;

Capture video;
OpenCV opencv;
int score = 5;
int temps;//la valeur du chronomètre

boolean depart;//commencer le compte à rebours (au clic)

float cx, cy;
boolean alive = true;
float trainX;
float trainY;


Rectangle[] faces;
Capture cam;

float x;
float y;
float easing = 1;


PImage fond;
PImage train;
PImage smiley;

void setup() {
  size(1000, 1000);

 video = new Capture(this, 640, 480);
  opencv = new OpenCV(this, 640, 480);

  opencv.loadCascade(OpenCV.CASCADE_FRONTALFACE);  
  video.start();
  faces = opencv.detect();

  fond = loadImage("Map.bmp");
  train = loadImage("train.gif");  
  smiley = loadImage("train.gif");

}

void draw() {
  scale (0.5);
  image(fond, x, y);
  scale(0.5);
  opencv.loadImage(video);
    imageMode(CENTER);

  // afficher l'image de la webcam 

  Rectangle[] faces = opencv.detect();
  for (int i = 0; i &lt; faces.length; i++) {
   float x = faces[i].x + faces[i].width / 2;
    float y = faces[i].y + faces[i].height / 2;
    image(smiley, x, y, 300, 300);

}

float targetX = xtrain;
  float dx = targetX - x;
  x += dx * easing;

  float targetY = ytrain;
  float dy = targetY - y;
  y += dy * easing;


  //texte compte à rebours

  fill(#585858);
  text("TEMPS RESTANT :", 1170, 30);
  fill(#FF0000);
  text(temps, 1310, 30);
}



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

//fonction compte à rebours  
void compte_rebours() {
  if (depart ==true) {
    if (temps == 0 ) {
      temps = 0;
    }
    else {
      temps = 60 - millis()/1000; //compte à rebours à partir de 60
    }
  }
}  
</code></pre>
]]></description>
   </item>
   <item>
      <title>Really confused on how to go about this (color tracking again)</title>
      <link>https://forum.processing.org/two/discussion/19737/really-confused-on-how-to-go-about-this-color-tracking-again</link>
      <pubDate>Tue, 13 Dec 2016 23:27:12 +0000</pubDate>
      <dc:creator>Raiz</dc:creator>
      <guid isPermaLink="false">19737@/two/discussions</guid>
      <description><![CDATA[<p>So, for anyone that saw my last post, im using the same code with a bit more added on. I took out anything that had to do with the xbox kinect because it is getting in the way of my finishing this atm but i do plan on using it with the same code in the future. My program now uses a webcam. So, Following Daniel Shiffman's tutorials I got the color tracking and blob detection working (<span class="VideoWrap"><span class="Video YouTube" id="youtube-ce-2l2wRqO8"><span class="VideoPreview"><a href="http://youtube.com/watch?v=ce-2l2wRqO8"><img src="http://img.youtube.com/vi/ce-2l2wRqO8/0.jpg" width="640" height="385" border="0" /></a></span><span class="VideoPlayer"></span></span></span>). What I am trying to do now is to make my program so that a line is drawn following the blobs path. So, a line is drawn on the screen, and every time the blob moves, more of that line is drawn. I was thinking of using some sort of code similar to the code in a processing online book</p>

<pre><code>void draw(){
line(pmouseX,pmouseY,mouseX,mouseY)
}
</code></pre>

<p>to draw the line however i dont know how i would get the blobs previous position. So far under the blob class in its <code>show()</code> function I am putting <code>line(maxx,maxy)</code> to start the line off in the corner of the blob which works (if you are confused I am following the tutorial in the link above) However I do no know what to do with the last coordinates or if I should try to do this in a different way. Any tips?</p>

<pre><code>import processing.video.*;


Capture video;

color trackColor;
float threshold = 25;
float distThresh = 150;
ArrayList&lt;Blob&gt; blobs = new ArrayList&lt;Blob&gt;();

void setup() {
  size(640, 400);
  video = new Capture (this,640,480,30);
  video.start();
  trackColor = color(0,0,255);
}

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


void draw(){
  video.loadPixels();
  image(video, 0, 0);

blobs.clear();


 for (int x=0; x&lt; video.width; x++){
   for (int y =0; y &lt; video.height; y++){
     int loc = x+y * video.width;

     color currentColor = video.pixels[loc];
     float r1 = red(currentColor);
     float g1 = blue(currentColor);
     float b1 = green(currentColor);
     float r2 = red(trackColor);
     float g2 = blue(trackColor);
     float b2 = green(trackColor);

     float d = dist(r1,b1,g1,r2,b2,g2);

     if (d &lt; threshold){

       boolean found = false;
       for (Blob b : blobs){
         if(b.isNear(x,y)){
           b.add (x,y);
           found = true;
           break;

           }
         }

       if (!found){
        Blob b = new Blob(x,y);
        blobs.add(b);


       }
     }
   }
 }
 int i = 0;
 for (Blob b :blobs){
 if (b.size() &gt; 500){ 
   b.show(i);
   i++;
     }
   }  
 }


 float distSq( float x1, float y1, float x2, float y2) {
 float d = (x2-x1)*(x2-y1) + (y2-y1)*(y2-y1); 
 return d;
}



void mousePressed(){
 int loc = mouseX + mouseY*video.width;
 trackColor = video.pixels[loc];
}

class Blob {

  float minx;
  float miny;
  float maxx;
  float maxy;

Blob(float x , float y) {

minx = x;
miny = y;
maxx = x;
miny = y;
}

void show(int num){
  stroke(0);
  fill(255,255,255,150);
  strokeWeight(2);
  rectMode(CORNERS);
  rect (minx,miny, maxx,maxy);

  textAlign (CENTER);
  textSize(64);
  fill(255);
  text(num, minx + (maxx-minx)*0.5, miny + (maxy-miny)*0.5);

}

void add(float x, float y){
  minx = min(minx,x);
  miny = min(miny,y);
  maxx = max(maxx,x);
  maxy = max(maxy,y);

}

 float size() {
    return (maxx-minx)*(maxy-miny); 
  }

boolean isNear(float x, float y){

  float cx =(minx+maxx)/2;
  float cy = (miny+maxy)/2;


  float d = distSq (cx,cy,x,y); 
  if (d&lt; distThresh*distThresh){
   return true;
  } else{
   return false; 
  }
}

}
</code></pre>
]]></description>
   </item>
   <item>
      <title>How can I let my face grow?</title>
      <link>https://forum.processing.org/two/discussion/19452/how-can-i-let-my-face-grow</link>
      <pubDate>Thu, 01 Dec 2016 17:17:30 +0000</pubDate>
      <dc:creator>Adinda123</dc:creator>
      <guid isPermaLink="false">19452@/two/discussions</guid>
      <description><![CDATA[<p><strong>I am doing a project about obesitas.</strong></p>

<p>I am using my webcam, then I used the face tracker. I copied my face into a rectangle.
What I want is my face (rectangle) is getting bigger and bigger within 2/3 minutes.</p>

<p><em>I hope somebody can help me with that! :)</em></p>

<p>Below is my code:</p>

<pre><code>import gab.opencv.*;
import processing.video.*;
import java.awt.*;

Capture video;
OpenCV opencv;
PImage cam;

void setup() {
  size(640, 480);
  video = new Capture(this, 640/2, 480/2);
  opencv = new OpenCV(this, 640/2, 480/2);
  opencv.loadCascade(OpenCV.CASCADE_FRONTALFACE);  

  video.start();
}

void draw() {
  scale(2);
  opencv.loadImage(video);

  image(video, 0, 0 );

  noFill();
  stroke(0, 255, 0);
  strokeWeight(3);
  Rectangle[] faces = opencv.detect();
  println(faces.length);


  for (int i = 0; i &lt; faces.length; i++) {
    println(faces[i].x + "," + faces[i].y);
    //rect(faces[i].x, faces[i].y, faces[i].width, faces[i].height);
    copy(cam, faces[i].x, faces[i].y, faces[i].width, faces[i].height, faces[i].x - faces[i].width/2, faces[i].y, faces[i].width * 2,             
faces[i].height);
  }
}

void captureEvent(Capture c) {
  c.read();
  cam = c.get();
}
</code></pre>
]]></description>
   </item>
   <item>
      <title>Project problems (ParticleSystem / Video)</title>
      <link>https://forum.processing.org/two/discussion/19387/project-problems-particlesystem-video</link>
      <pubDate>Tue, 29 Nov 2016 10:24:45 +0000</pubDate>
      <dc:creator>JamesHewitt</dc:creator>
      <guid isPermaLink="false">19387@/two/discussions</guid>
      <description><![CDATA[<p>Hello all I am new to processing and have a question with regards to how I would fix my code.</p>

<pre><code>import processing.video.*;

Capture video;

PImage prevFrame;

float threshold = 50;

void setup() {
  size(600,400);
  video = new Capture(this, 640, 480,30);
  video.start();
  ps = new ParticleSystem(new PVector(width/2, 50));
  prevFrame = createImage(video.width, video.height, RGB);
}

void captureEvent(Capture video) {
  prevFrame.copy(video, 0, 0, video.width, video.height, 0, 0, video.width, video.height);
  prevFrame.updatePixels();
  video.read();
}

void draw() {
  background(0);
  image(video, 0, 0);
  ps.addParticle();
  ps.run();
  loadPixels();
  video.loadPixels();
  prevFrame.loadPixels();

  float sumX = 0;
  float sumY = 0;
  int motionCount = 0;

  for (int x = 0; x &lt; video.width; x++ ) {
    for (int y = 0; y &lt; video.height; y++ ) {
      color current = video.pixels[x+y*video.width];

      color previous = prevFrame.pixels[x+y*video.width];

      float r1 = red(current);
      float g1 = green(current);
      float b1 = blue(current);
      float r2 = red(previous); 
      float g2 = green(previous);
      float b2 = blue(previous);

      float diff = dist(r1, g1, b1, r2, g2, b2);

      if (diff &gt; threshold){
        sumX += x;
        sumY += y;
        motionCount ++;
      }
    }
  }

  float avgX = sumX / motionCount;
  float avgY = sumY / motionCount;


  smooth();
  noStroke();
  fill(0);
  ellipse(avgX, avgY, 16, 16);
}

  ParticleSystem ps;


class ParticleSystem {
  ArrayList&lt;Particle&gt; particles;
  PVector origin;

  ParticleSystem(PVector position) {
    origin = position.copy();
    particles = new ArrayList&lt;Particle&gt;();
  }

  void addParticle() {
    particles.add(new Particle(origin));
  }

  void run() {
    for (int i = particles.size()-1; i &gt;= 0; i--) {
      Particle p = particles.get(i);
      p.run();
      if (p.isDead()) {
        particles.remove(i);
      }
    }
  }
}

class Particle {
  PVector position;
  PVector velocity;
  PVector acceleration;
  float lifespan;

  Particle(PVector l) {
    acceleration = new PVector(0, 0.05);
    velocity = new PVector(random(-1, 1), random(-2, 0));
    position = l.copy();
    lifespan = 255.0;
  }

  void run() {
    update();
    display();
  }

  void update() {
    velocity.add(acceleration);
    position.add(velocity);
    lifespan -= 1.0;
  }

  void display() {
    stroke(255, lifespan);
    fill(255, lifespan);
    ellipse(avgX, avgY, 8, 8);
  }

  boolean isDead() {
    if (lifespan &lt; 0.0) {
      return true;
    } else {
      return false;
    }
  }
}
</code></pre>

<p>I have two pieces of code with one being able to detect motion and place a dot where it is detected and the other is a particle system and I am trying to place the particle system where movement is detected but I am unsure as to why it is not working, any help is appreciated!</p>
]]></description>
   </item>
   <item>
      <title>Senior Project. Help!! Making Rollovers Stay After being Rolled Over</title>
      <link>https://forum.processing.org/two/discussion/19400/senior-project-help-making-rollovers-stay-after-being-rolled-over</link>
      <pubDate>Tue, 29 Nov 2016 17:59:08 +0000</pubDate>
      <dc:creator>ccastro</dc:creator>
      <guid isPermaLink="false">19400@/two/discussions</guid>
      <description><![CDATA[<p>Hi!</p>

<p>We're working on our senior project and need help making rollovers stay on the screen once they've been rolled over. We're using basic mouseX and mouseY to define where the rollovers appear. The rollovers appear on top of a live camera feed taken from a webcam. We aren't too advanced and aren't using object oriented programming. We're not sure if the answer is a boolean or maybe a function? We just need a small example to put us in the right direction.</p>

<p>If there's any one who can help we'd greatly appreciate it :)</p>

<p>Here's a look at our code if it helps:</p>

<pre><code>//-----------------------------------------------video stuff

import processing.video.*;
Capture video;

//-----------------------------------------------variables
//Instagram
PImage startscreen;
PImage bellatemp;
PImage celestetemp;
//Ccomments
PImage Ccomment1;
PImage Ccomment2;
PImage Ccomment3;
PImage Ccomment4;
PImage Ccomment5;
PImage Ccomment6;
PImage Ccomment7;
PImage Ccomment8;
PImage Ccomment9;
PImage Ccomment10;
PImage Ccomment11;
PImage Ccomment12;
PImage Ccomment13;


//Bcomments
PImage Bcomment1;
PImage Bcomment2;
PImage Bcomment3;
PImage Bcomment4;
PImage Bcomment5;
PImage Bcomment6;
PImage Bcomment7;
PImage Bcomment8;
//Directions
PImage pressB;
PImage pressC;
boolean clicked = false;//mouse clicked
boolean rPressed = false;//r key
PImage restart;
int rollover = 0;


//-----------------------------------------------setup
void setup() {

  size(1152, 864);
  smooth();
  //Video Camera
  video = new Capture (this, Capture.list()[0]);
  video.start();
  printArray(Capture.list());

  //load ALL images in setup
  startscreen = loadImage ("startscreen.png");
  //Templates
  bellatemp = loadImage ("bellatemp.png");
  celestetemp = loadImage ("celestetemp.png");
  //Ccomments
  Ccomment1 = loadImage ("Ccomment1.png");
  Ccomment2 = loadImage ("Ccomment2.png");
  Ccomment3 = loadImage ("Ccomment3.png");
  Ccomment4 = loadImage ("Ccomment4.png");
  Ccomment5 = loadImage ("Ccomment5.png");
  Ccomment6 = loadImage ("Ccomment6.png");
  Ccomment7 = loadImage ("Ccomment7.png");
  Ccomment8 = loadImage ("Ccomment8.png");
  Ccomment9 = loadImage ("Ccomment9.png");
  // Ccomment10 = loadImage ("Ccomment10.png");
  Ccomment11 = loadImage ("Ccomment11.png");
  Ccomment12 = loadImage ("Ccomment12.png");
  Ccomment13 = loadImage ("Ccomment13.png");

  //Bcommnets
  Bcomment1 = loadImage ("Bcomment1.png");
  Bcomment2 = loadImage ("Bcomment2.png");
  Bcomment3 = loadImage ("Bcomment3.png");
  Bcomment4 = loadImage ("Bcomment4.png");
  Bcomment5 = loadImage ("Bcomment5.png");
  Bcomment6 = loadImage ("Bcomment6.png");
  Bcomment7 = loadImage ("Bcomment7.png");
  Bcomment8 = loadImage ("Bcomment8.png");
  pressC = loadImage ("pressC.png");
  pressB = loadImage ("pressB.png");
  restart = loadImage ("restart.png");
}

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


//-----------------------------------------------draw
void draw() {

  image(bellatemp, 0, 0);
  image(celestetemp, 0, 0);
  image(restart, 0, 0);

  //Instagram
  image(pressC, 90, 750);
  image(pressB, 600, 750);
  image(video, 0, 0);
  image(startscreen, 0, 0);

  //boolean



  if (clicked)//bella or celeste
  {
    //background rect
    image(video, 0, 0);
    image(pressC, 90, 750);
    image(pressB, 600, 750);

    //line
    strokeWeight(15);
    stroke(#325d80);
    line(width/2, 0, width/2, height);
  }

  if (rPressed)
  {  
    image(startscreen, 0, 0);
  }
  if (key == 'c') 
  {
    //CAMERA
    image(video, 0, 0);
    image(celestetemp, 0, 0);
    image(restart, 0, 0);

    //ROLLOVERS

    if (mouseY&gt;620 &amp;&amp; mouseY&lt;680)
    {
      image(Ccomment2, 0, 0);
    }
    if (mouseY&gt;600 &amp;&amp; mouseY&lt;630)
    {
      image(Ccomment1, 0, 0);
    }
    if (mouseY&gt;500 &amp;&amp; mouseY&lt;520)
    {
      image(Ccomment4, 0, 0);
    }
    if (mouseY&gt;183 &amp;&amp; mouseY&lt;210)
    {
      image(Ccomment6, 0, 0);
    }
    if (mouseY&gt;352 &amp;&amp; mouseY&lt;390)
    {
      image(Ccomment7, 0, 0);
    }
    if (mouseY&gt;407 &amp;&amp; mouseY&lt;430)
    {
      image(Ccomment8, 0, 0);
    }
    if (mouseY&gt;275 &amp;&amp; mouseY&lt;330)
    {
      image(Ccomment9, 0, 0);
    }
    if (mouseY&gt;370 &amp;&amp; mouseY&lt;390)
    {
      image(Ccomment11, 0, 0);
    }
  }

  if (key == 'b')
  {
    image(video, 0, 0);
    image(bellatemp, 0, 0);
    image(restart, 0, 0);

    if (mouseY&gt;250 &amp;&amp; mouseY&lt;275)

    {
      image(Bcomment1, 0, 0);
    }
    if (mouseY&gt;285 &amp;&amp; mouseY&lt;340)
    {
      image(Bcomment2, 0, 0);
    }
    if (mouseY&gt;426 &amp;&amp; mouseY&lt;460)
    {
      image(Bcomment4, 0, 0);
    }
    if (mouseY&gt;480 &amp;&amp; mouseY&lt;510)
    {
      image(Bcomment5, 0, 0);
    }
    if (mouseY&gt;500 &amp;&amp; mouseY&lt;525)
    {
      image(Bcomment6, 0, 0);
    }
    if (mouseY&gt;550 &amp;&amp; mouseY&lt;578)
    {
      image(Bcomment7, 0, 0);
    }
    if (mouseY&gt;618 &amp;&amp; mouseY&lt;655)
    {
      image(Bcomment8, 0, 0);
    }
  }
}


//-----------------------------------------------mouse pressed
void mousePressed()
{
  if (clicked==false) {
    clicked=true;
  }
  else
  {
    clicked = false;
    rPressed = false;
  }
}
//-----------------------------------------------key pressed

void keyPressed()
{

  if (key=='r') {
    rPressed=true;
  }
}
</code></pre>
]]></description>
   </item>
   <item>
      <title>How to use ultrasonic sensor to trigger a video ? (Arduino+processing)</title>
      <link>https://forum.processing.org/two/discussion/19293/how-to-use-ultrasonic-sensor-to-trigger-a-video-arduino-processing</link>
      <pubDate>Fri, 25 Nov 2016 18:17:22 +0000</pubDate>
      <dc:creator>eliseber</dc:creator>
      <guid isPermaLink="false">19293@/two/discussions</guid>
      <description><![CDATA[<p>Hey ! 
First time I'm using Arduino and Processing at the same time and I'm completely lost ! 
I'm designing an interactive installation, and I need the trigger the position in a video with the distance : as we get closer to the sensor, the video will move. 
I've set up a code for Arduino which gives the distance. 
For processing, I found a code which triggers the position with the webcam (and the size of the head of the spectator, as he gets closer, his head become bigger, and the position moves forward). Do you have any idea/ thoughts about how I can modify this code ? It's the same idea, with arduino instead of the webcam but I don't know where to start...</p>

<h2>Thank you very much !</h2>

<p>Arduino :</p>

<pre><code>#include &lt;NewPing.h&gt;
#include &lt;Servo.h&gt;


#define TRIGGER_PIN  12  // Arduino pin tied to trigger pin on the ultrasonic sensor.
#define ECHO_PIN     11  // Arduino pin tied to echo pin on the ultrasonic sensor.
#define MAX_DISTANCE 200 // Maximum distance we want to ping for (in centimeters). Maximum sensor distance is rated at 400-500cm.

int LEDpin = 13;
Servo myservo;
int val;

NewPing sonar(TRIGGER_PIN, ECHO_PIN, MAX_DISTANCE); // NewPing setup of pins and maximum distance.

void setup() {
  Serial.begin(9600); // Open serial monitor at 115200 baud to see ping results.
  pinMode(LEDpin, OUTPUT);
  myservo.attach(9);// attaches servo to pin 9

}

void loop() {
  delay(400);                      // Wait 50ms between pings (about 20 pings/sec). 29ms should be the shortest delay between pings.
  unsigned int uS = sonar.ping(); // Send ping, get ping time in microseconds (uS).
  //Serial.print("Ping: ");
  Serial.println(uS / US_ROUNDTRIP_CM); // Convert ping time to distance in cm and print result (0 = outside set distance range)
  //Serial.println("cm");
  //if(uS / US_ROUNDTRIP_CM &lt; 100) {digitalWrite(LEDpin, HIGH);}
  //else if (uS / US_ROUNDTRIP_CM &gt; 100) {digitalWrite(LEDpin, LOW);}
 // else if (uS / US_ROUNDTRIP_CM &gt; 100) {digitalWrite(LEDpin, LOW);}
  //delay (200);

  val = (uS / US_ROUNDTRIP_CM);
  val = map(val, 0, 172, 15, 180);
  myservo.write(val);
  delay (150);


}
</code></pre>

<hr />

<p>PROCESSING</p>

<pre><code>import gab.opencv.*;
import processing.video.*;
import java.awt.*;
//-------------------------------------------------
/*


*/
//-------------------------------------------------
Capture video;
OpenCV opencv;
//---
Movie monSuperFilm;// déclaration du film
float positionDuFilmEnSecondes;//position ds le film
Integer surfaceVisages,surfaceMin,surfaceMax;
//-------------------------------------------------
/*


*/
//-------------------------------------------------
void setup() {
  //----------------
  size(1080, 720);//dimensions de votre film en pixels; mettre la définition de votre film
  //-----------------
  // partie video cam
  //-----------------
  video = new Capture(this, 640/2, 480/2);
  opencv = new OpenCV(this, 640/2, 480/2);
  opencv.loadCascade(OpenCV.CASCADE_FRONTALFACE);  
  video.start();
  //-----------------
  // partie film
  //-----------------
    monSuperFilm = new Movie(this,"pattern1080-6low-1.mov");// chargement du film ; mettre le nom de votre film qui est dans le dossier data
    monSuperFilm.loop();
  //-----------------
  // partie visages
  //-----------------
  // plus la surface du visage est grande dans l'image retournée par la caméra du mac et plus on est près
  // le programme cumule les surfaces de tous les visages capturés par la caméra; à essayer à plusieurs devant le mac !
    surfaceMin=400;// min 0 //surface du visage sur la camera qui correspond au début du film
    surfaceMax=1500;// max 640x480=307200 //surface du visage sur la camera qui correspond à la fin du film
}
//-------------------------------------------------
/*


*/
//-------------------------------------------------
void draw() {
  //background(255);
  //scale(2);
  opencv.loadImage(video);

  //image(video, 0, 0 );

  //noFill();
  stroke(0, 255, 0);
  strokeWeight(3);
  Rectangle[] faces = opencv.detect();
  println(faces.length);
//---------------------------------------------
// calcul de la surface occupée par les visages
//---------------------------------------------
surfaceVisages=0;
  for (int i = 0; i &lt; faces.length; i++) {
    //println(faces[i].x + "," + faces[i].y);
    //rect(faces[i].x, faces[i].y, faces[i].width, faces[i].height);
    surfaceVisages=surfaceVisages+faces[i].width*faces[i].height;
  }
  fill(0);
  text(str(surfaceMin)+" / "+str(surfaceVisages)+" / "+str(surfaceMax),10,50);
   monSuperFilm.read();//on lit l'image du film 
  positionDuFilmEnSecondes=map(surfaceVisages,surfaceMin,surfaceMax,0,monSuperFilm.duration()); 
  monSuperFilm.jump(positionDuFilmEnSecondes);// on se déplace dans le film
  image(monSuperFilm, 0, 0);//on affiche l'image courante du film

}
//-------------------------------------------------
/*


*/
//-------------------------------------------------
void captureEvent(Capture c) {
  c.read();
}
</code></pre>
]]></description>
   </item>
   <item>
      <title>pass a global variable to a class</title>
      <link>https://forum.processing.org/two/discussion/19187/pass-a-global-variable-to-a-class</link>
      <pubDate>Mon, 21 Nov 2016 11:30:28 +0000</pubDate>
      <dc:creator>digitalmartyn</dc:creator>
      <guid isPermaLink="false">19187@/two/discussions</guid>
      <description><![CDATA[<p>I have a particle system over a live video feed with an implementation of OpenCV OpticalFlow.</p>

<p>I need the particles to be affected by opticalflow values - i.e. move left and a right with the person in the video.</p>

<p>I can get the variable aveFlow.x each frame but can't run it through to each particle and change the vector x</p>

<p>full code:</p>

<pre><code>import gab.opencv.*;
import processing.video.*;
import java.awt.*;

//Movie video;
Capture video;
OpenCV opencv;

// DECLARE
ArrayList ballCollection;

float numBalls = 2;

void setup() {
  size(640, 480);
  video = new Capture(this, width/4, height/4);
  opencv = new OpenCV(this, width/4, height/4);
  opencv.loadCascade(OpenCV.CASCADE_FRONTALFACE);  

  //INITIALIZE
  ballCollection = new ArrayList();

  video.start();
}

void draw() {
  //background(0);
  //scale(2);
  opencv.loadImage(video);
  opencv.calculateOpticalFlow();

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

  //translate(video.width, 0);
  stroke(255, 0, 0);
  //opencv.drawOpticalFlow();

  PVector aveFlow = opencv.getAverageFlow();
  int flowScale = 100;
  //float optX = aveFlow.x;

  stroke(255);
  strokeWeight(2);
  //line(video.width/2, video.height/2, video.width/2 + aveFlow.x*flowScale, video.height/2 + aveFlow.y*flowScale);
  line(width/2, height/2, width/2 + aveFlow.x*flowScale, height/2 + aveFlow.y*flowScale);

  //numberofballs
  if (ballCollection.size()&lt;numBalls) {
    Ball myBall = new Ball(random(width), 0);
    ballCollection.add(myBall);
  }  

  //CALL FUNCTIONALITY
  for (int i = 0; i &lt; ballCollection.size(); i++) {
    Ball mb = (Ball) ballCollection.get(i);
    mb.run();
  }
}

//void movieEvent(Movie m) {
//  m.read();
//}

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

class Ball {

  //global variables
  float x=0;
  float y=0;
  //float speedX = random(-2, 2);
  float speedX = 0;

  float speedY = random(-2, 2);

  //float optY = 0;

  //constructor
  Ball(float _x, float _y) {
    x= _x;
    y= _y;
    //optX = _optX*50;
  }

  //functions
  void run() {
    if (y&lt;height) {
      display();
      move();
      //bounce();
      gravity();
      opticalFlow();
    }
  }

  void opticalFlow() {
    //speedX += aveFlow.x*flowScale;
  }

  void gravity() {
    speedY += 0.01;
  }

  void bounce() {
    if (x &gt; width ) {
      speedX *= -1;
    }
    if (x &lt; 0 ) {
      speedX *= -1;
    }
    if (y &gt; height ) {
      speedY *= -1;
    }
    if (y &lt; 0 ) {
      speedY *= -1;
    }
  }

  void move() {
    x += speedX;
    y += speedY;
  }

  void display() {
    ellipse (x, y, 20, 20);
  }
}
</code></pre>
]]></description>
   </item>
   <item>
      <title>Live Video Streaming</title>
      <link>https://forum.processing.org/two/discussion/19161/live-video-streaming</link>
      <pubDate>Sat, 19 Nov 2016 16:01:30 +0000</pubDate>
      <dc:creator>James_Anderson</dc:creator>
      <guid isPermaLink="false">19161@/two/discussions</guid>
      <description><![CDATA[<p>i have a problem, when i live stream my video ,it will record  but when i make it stop . it will make all my program hang and then i need to reset . can anyone of you let  me know how i can overcome with this issue and it will not disturbed my other code and work perfectly</p>

<p>void keyPressed() {</p>

<p>if (keyCode == 32) {</p>

<pre><code>try {

  enc.finish();
} 
catch (IOException e) {

  e.printStackTrace();
}
</code></pre>

<p>}</p>

<p>}</p>
]]></description>
   </item>
   <item>
      <title>BackgroundRemove + Blobdetection (or a similiar solution?)</title>
      <link>https://forum.processing.org/two/discussion/18983/backgroundremove-blobdetection-or-a-similiar-solution</link>
      <pubDate>Fri, 11 Nov 2016 11:58:07 +0000</pubDate>
      <dc:creator>Aldun</dc:creator>
      <guid isPermaLink="false">18983@/two/discussions</guid>
      <description><![CDATA[<p>Hi,</p>

<p>I'm currently trying to combine two processing sketches (BackgroundRemove and Blobdetection) to do the following with a webcam aimed at a street:</p>

<ol>
<li>Get videocapture and turn the original image fully green</li>
<li>Compare every new frame with the original background image</li>
<li><p>Only show the changed pixels (as a result the canvas is fully green but only moving objects are shown).</p></li>
<li><p>Use blobdetection to draw rectangles around each moving object.</p></li>
</ol>

<p>For this I'm trying to combine the two scripts listed at the end of this post.
The BackgroundRemove comes from <a href="http://learningprocessing.com/examples/chp16/example-16-12-BackgroundRemove" target="_blank" rel="nofollow">http://learningprocessing.com/examples/chp16/example-16-12-BackgroundRemove</a>
The Blobdetection comes from <a href="http://www.v3ga.net/processing/BlobDetection/index-page-home.html" target="_blank" rel="nofollow">http://www.v3ga.net/processing/BlobDetection/index-page-home.html</a></p>

<p>Both scripts seperately work fine, but I've been working for days to combine them and I can't seem to get it working. I think the solution would be to replace the video input in the Blob detection with the canvas input, but I can't figure out how to do that (or how to fix this otherwise).</p>

<p>Would anyone be able to help me here? Thanks!</p>

<blockquote class="Quote">
  <p>sorry, the Code tags don't seem to work correctly.
  For a better view, here are the code Gists: 
  <a href="https://gist.github.com/Thomvdm/fd4c412b6bb66a264728b1816c9b5a10" target="_blank" rel="nofollow">https://gist.github.com/Thomvdm/fd4c412b6bb66a264728b1816c9b5a10</a>
  <a href="https://gist.github.com/Thomvdm/21d6e9d3df86e288cb8e36fd41bcaf29" target="_blank" rel="nofollow">https://gist.github.com/Thomvdm/21d6e9d3df86e288cb8e36fd41bcaf29</a></p>
</blockquote>

<p>|
|
|
|
|
|
|</p>

<pre><code>// Example 16-12: Simple background removal

// Click the mouse to memorize a current background image
import processing.video.*;

// Variable for capture device
Capture video;

// Saved background
PImage backgroundImage;

// How different must a pixel be to be a foreground pixel
float threshold = 30;

void setup() {
  size(640, 480);

  video = new Capture(this, width, height);


  video.start();
  // Create an empty image the same size as the video
  backgroundImage = createImage(video.width, video.height, RGB);
}

void captureEvent(Capture video) {
  // Read image from the camera
  video.read();
}

void draw() {
  // We are looking at the video's pixels, the memorized backgroundImage's pixels, as well as accessing the display pixels. 
  // So we must loadPixels() for all!
  loadPixels();
  video.loadPixels(); 
  backgroundImage.loadPixels();

  // Begin loop to walk through every pixel
  for (int x = 0; x &lt; video.width; x ++ ) {
    for (int y = 0; y &lt; video.height; y ++ ) {
      int loc = x + y*video.width; // Step 1, what is the 1D pixel location
      color fgColor = video.pixels[loc]; // Step 2, what is the foreground color

      // Step 3, what is the background color
      color bgColor = backgroundImage.pixels[loc];

      // Step 4, compare the foreground and background color
      float r1 = red(fgColor);
      float g1 = green(fgColor);
      float b1 = blue(fgColor);
      float r2 = red(bgColor);
      float g2 = green(bgColor);
      float b2 = blue(bgColor);
      float diff = dist(r1, g1, b1, r2, g2, b2);

      // Step 5, Is the foreground color different from the background color
      if (diff &gt; threshold) {
        // If so, display the foreground color
        pixels[loc] = fgColor;
      } else {
        // If not, display green
        pixels[loc] = color(0, 255, 0); // We could choose to replace the background pixels with something other than the color green!
      }
    }
  }
  updatePixels();
}

void mousePressed() {
  // Copying the current frame of video into the backgroundImage object
  // Note copy takes 5 arguments:
  // The source image
  // x, y, width, and height of region to be copied from the source
  // x, y, width, and height of copy destination
  backgroundImage.copy(video, 0, 0, video.width, video.height, 0, 0, video.width, video.height);
  backgroundImage.updatePixels();
}














// - Super Fast Blur v1.1 by Mario Klingemann &lt;<a href="http://incubator.quasimondo.com&gt" target="_blank" rel="nofollow">http://incubator.quasimondo.com&gt</a>;
// - BlobDetection library

import processing.video.*;
import blobDetection.*;

Capture cam;
BlobDetection theBlobDetection;
PImage img;
boolean newFrame=false;

// ==================================================
// setup()
// ==================================================
void setup()
{
    // Size of applet
    size(640, 480);
    // Capture
    cam = new Capture(this, 640, 480, 30);
        // Comment the following line if you use Processing 1.5
        cam.start();

    // BlobDetection
    // img which will be sent to detection (a smaller copy of the cam frame);
    img = new PImage(80,60); 
    theBlobDetection = new BlobDetection(img.width, img.height);
    theBlobDetection.setPosDiscrimination(true);
    theBlobDetection.setThreshold(0.2f); // will detect bright areas whose luminosity &gt; 0.2f;
}

// ==================================================
// captureEvent()
// ==================================================
void captureEvent(Capture cam)
{
    cam.read();
    newFrame = true;
}

// ==================================================
// draw()
// ==================================================
void draw()
{
    if (newFrame)
    {
        newFrame=false;
        image(cam,0,0,width,height);
        img.copy(cam, 0, 0, cam.width, cam.height, 
                0, 0, img.width, img.height);
        fastblur(img, 2);
        theBlobDetection.computeBlobs(img.pixels);
        drawBlobsAndEdges(true,true);
    }
}

// ==================================================
// drawBlobsAndEdges()
// ==================================================
void drawBlobsAndEdges(boolean drawBlobs, boolean drawEdges)
{
    noFill();
    Blob b;
    EdgeVertex eA,eB;
    for (int n=0 ; n&lt;theBlobDetection.getBlobNb() ; n++)
    {
        b=theBlobDetection.getBlob(n);
        if (b!=null)
        {
    print("Blob #: ");
    println(n);
    print("X Coord of center: ");
    println(b.x);
print("Y Coord of center: ");
println(b.y);
            // Edges
            if (drawEdges)
            {
                strokeWeight(3);
                stroke(0,255,0);
                for (int m=0;m&lt;b.getEdgeNb();m++)
                {
                    eA = b.getEdgeVertexA(m);
                    eB = b.getEdgeVertexB(m);
                    if (eA !=null &amp;&amp; eB !=null)
                        line(
                            eA.x*width, eA.y*height, 
                            eB.x*width, eB.y*height
                            );
                }
            }

            // Blobs
            if (drawBlobs)
            {
                strokeWeight(1);
                stroke(255,0,0);
                rect(
                    b.xMin*width,b.yMin*height,
                    b.w*width,b.h*height
                    );

            }

        }

      }
}

// ==================================================
// Super Fast Blur v1.1
// by Mario Klingemann 
// &lt;<a href="http://incubator.quasimondo.com&gt" target="_blank" rel="nofollow">http://incubator.quasimondo.com&gt</a>;
// ==================================================
void fastblur(PImage img,int radius)
{
 if (radius&lt;1){
    return;
  }
  int w=img.width;
  int h=img.height;
  int wm=w-1;
  int hm=h-1;
  int wh=w*h;
  int div=radius+radius+1;
  int r[]=new int[wh];
  int g[]=new int[wh];
  int b[]=new int[wh];
  int rsum,gsum,bsum,x,y,i,p,p1,p2,yp,yi,yw;
  int vmin[] = new int[max(w,h)];
  int vmax[] = new int[max(w,h)];
  int[] pix=img.pixels;
  int dv[]=new int[256*div];
  for (i=0;i&lt;256*div;i++){
    dv[i]=(i/div);
  }

  yw=yi=0;

  for (y=0;y&lt;h;y++){
    rsum=gsum=bsum=0;
    for(i=-radius;i&lt;=radius;i++){
      p=pix[yi+min(wm,max(i,0))];
      rsum+=(p &amp; 0xff0000)&gt;&gt;16;
      gsum+=(p &amp; 0x00ff00)&gt;&gt;8;
      bsum+= p &amp; 0x0000ff;
    }
    for (x=0;x&lt;w;x++){

      r[yi]=dv[rsum];
      g[yi]=dv[gsum];
      b[yi]=dv[bsum];

      if(y==0){
        vmin[x]=min(x+radius+1,wm);
        vmax[x]=max(x-radius,0);
      }
      p1=pix[yw+vmin[x]];
      p2=pix[yw+vmax[x]];

      rsum+=((p1 &amp; 0xff0000)-(p2 &amp; 0xff0000))&gt;&gt;16;
      gsum+=((p1 &amp; 0x00ff00)-(p2 &amp; 0x00ff00))&gt;&gt;8;
      bsum+= (p1 &amp; 0x0000ff)-(p2 &amp; 0x0000ff);
      yi++;
    }
    yw+=w;
  }

  for (x=0;x&lt;w;x++){
    rsum=gsum=bsum=0;
    yp=-radius*w;
    for(i=-radius;i&lt;=radius;i++){
      yi=max(0,yp)+x;
      rsum+=r[yi];
      gsum+=g[yi];
      bsum+=b[yi];
      yp+=w;
    }
    yi=x;
    for (y=0;y&lt;h;y++){
      pix[yi]=0xff000000 | (dv[rsum]&lt;&lt;16) | (dv[gsum]&lt;&lt;8) | dv[bsum];
      if(x==0){
        vmin[y]=min(y+radius+1,hm)*w;
        vmax[y]=max(y-radius,0)*w;
      }
      p1=x+vmin[y];
      p2=x+vmax[y];

      rsum+=r[p1]-r[p2];
      gsum+=g[p1]-g[p2];
      bsum+=b[p1]-b[p2];

      yi+=w;
    }
  }

}`
</code></pre>
]]></description>
   </item>
   <item>
      <title>why is my program running on the wrong side of screen?</title>
      <link>https://forum.processing.org/two/discussion/18926/why-is-my-program-running-on-the-wrong-side-of-screen</link>
      <pubDate>Mon, 07 Nov 2016 19:02:20 +0000</pubDate>
      <dc:creator>Jai</dc:creator>
      <guid isPermaLink="false">18926@/two/discussions</guid>
      <description><![CDATA[<p>what im looking to do is run face detection on the right side of the window only not display the cam on the right side while processing on the left side which is whats happening.</p>

<pre><code>void setup() {
  size(1280, 480, P3D);

  video2 = new Capture(this, 1280/2, 480, "webcam");

  opencv = new OpenCV(this, 1280/2, 480);
  opencv.loadCascade(OpenCV.CASCADE_FRONTALFACE);  

  video2.start();
}

void R()
{
  scale(1);
  opencv.loadImage(video2);
  image(video2, 1280/2, 0);

  noFill();
  stroke(0, 255, 0);
  strokeWeight(1);
  Rectangle[] faces = opencv.detect();

  for (int i = 0; i &lt; faces.length; i++) {
    rect(faces[i].x, faces[i].y, faces[i].width, faces[i].height);
}
}
</code></pre>
]]></description>
   </item>
   <item>
      <title>OpenCV - How can I ad a different random image on every face?</title>
      <link>https://forum.processing.org/two/discussion/18457/opencv-how-can-i-ad-a-different-random-image-on-every-face</link>
      <pubDate>Sat, 08 Oct 2016 10:06:13 +0000</pubDate>
      <dc:creator>kiwiwi</dc:creator>
      <guid isPermaLink="false">18457@/two/discussions</guid>
      <description><![CDATA[<p>I want to write a Code, where every face gets another random image out of 10 images I have.
I struggle to separate the different faces. Every time I try, the same image appears on all faces.
Would be great, if someone can give me a hint how to separate the faces for the Code.</p>

<p>You will see, I was a bit desperate. I see the mistake, its a big one I know. But I can't see the solution.</p>

<pre><code>import gab.opencv.*;
import processing.video.*;
import java.awt.*;
 int num = 3;
 PImage[] myImageArray = new PImage[num];
 Capture video;
 OpenCV opencv;

 void setup() {

for (int i=0; i&lt;myImageArray.length; i++){             
   myImageArray[i] = loadImage( str(i) + ".png");
 }

  size(800, 600);
   video = new Capture(this, 800/2, 600/2);
   opencv = new OpenCV(this, 800/2, 600/2);
   opencv.loadCascade(OpenCV.CASCADE_FRONTALFACE);  

   video.start();
 }

 void draw() {
   scale(2);
  opencv.loadImage(video);
   image(video, 0, 0 );

  Rectangle[] faces = opencv.detect();
   println(faces.length);                    //print number of faces
   for (int i = 0; i &lt; faces.length; i++) {
     println(faces[i].x + "," + faces[i].y); //print position(x/y) of faces 
  image(myImageArray[(int)random(num)], faces[i].x-70, faces[i].y-60, faces[i].width+80, faces[i].height+80);
 }
}

 void captureEvent(Capture c) {
   c.read();
 }
</code></pre>
]]></description>
   </item>
   <item>
      <title>Minim Ugens AudioOutput, playNote only once</title>
      <link>https://forum.processing.org/two/discussion/18486/minim-ugens-audiooutput-playnote-only-once</link>
      <pubDate>Mon, 10 Oct 2016 17:04:24 +0000</pubDate>
      <dc:creator>AlfieChillar</dc:creator>
      <guid isPermaLink="false">18486@/two/discussions</guid>
      <description><![CDATA[<p>Hi, I am working on a sketch that recognises faces and plays notes depending on the location/size of said faces. However, currently the playNote function just repeatedly plays the same note over and over, as opposed to just once.</p>

<p>I realise that the problem currently is that the only way I could find to use the parameters of the face detection rects is to put the playNote in the same brackets as them. Meaning that of course, as the rects are being permanently drawn, so are the notes being permanently created.</p>

<p>How can I have a playNote function that runs on the faces[i] parameters but doesn't have to be in the same 'for' brackets?</p>

<p>All help is greatly appreciated, here is my code currently</p>

<pre><code>import gab.opencv.*;
import processing.video.*;
import java.awt.*;

// audio bits
import ddf.minim.*;
import ddf.minim.ugens.*;
AudioOutput out;

Capture video;
OpenCV opencv;

void setup() {
  size(640, 480);
  video = new Capture(this, 640/2, 480/2);
  opencv = new OpenCV(this, 640/2, 480/2);
  opencv.loadCascade(OpenCV.CASCADE_FRONTALFACE);  

  video.start();

  Minim minim = new Minim(this);
  out = minim.getLineOut();
}

void draw() {
  scale(2);
  opencv.loadImage(video);

  image(video, 0, 0 );

  noFill();
  stroke(0, 255, 0);
  strokeWeight(3);
  Rectangle[] faces = opencv.detect();
  println(faces.length);

  for (int i = 0; i &lt; faces.length; i++) {
    println(faces[i].x + "," + faces[i].y);
    out.playNote(0, 1, (faces[i].width*2));
    rect(faces[i].x, faces[i].y, faces[i].width, faces[i].height);     
  }
}

void captureEvent(Capture c) {
  c.read();
}
</code></pre>
]]></description>
   </item>
   <item>
      <title>How to change position of "Contour" OpenCV</title>
      <link>https://forum.processing.org/two/discussion/18103/how-to-change-position-of-contour-opencv</link>
      <pubDate>Wed, 07 Sep 2016 14:38:14 +0000</pubDate>
      <dc:creator>lxnr_p</dc:creator>
      <guid isPermaLink="false">18103@/two/discussions</guid>
      <description><![CDATA[<p>Hi everybody, 
I'm using the opencv findcontour library that I modified to use with the webcam, that works great, but I would the webcam be in the center of my window. When I change the values of : image(video, x, y); it only move the video of the webcam, and not the contours. It stay on the top left. Here my code :</p>

<p>Thanks for your help :)</p>

<pre><code>////////////////////////////////////////////
////////////////////////////////// LIBRARIES
////////////////////////////////////////////

import processing.serial.*;
import gab.opencv.*;
import processing.video.*;




/////////////////////////////////////////////////
////////////////////////////////// INITIALIZATION
/////////////////////////////////////////////////

Movie mymovie;
Capture video;
OpenCV opencv;
Contour contour;




////////////////////////////////////////////
////////////////////////////////// VARIABLES
////////////////////////////////////////////

int lf = 10;    // Linefeed in ASCII
String myString = null;
Serial myPort;  // The serial port
int sensorValue = 0;
int x = 300;




/////////////////////////////////////////////
////////////////////////////////// VOID SETUP
/////////////////////////////////////////////


void setup() {
  size(1280, 1024);
  // List all the available serial ports
  printArray(Serial.list());
  // Open the port you are using at the rate you want:
  myPort = new Serial(this, Serial.list()[1], 9600);
  myPort.clear();
  // Throw out the first reading, in case we started reading 
  // in the middle of a string from the sender.
  myString = myPort.readStringUntil(lf);
  myString = null;
  opencv = new OpenCV(this, 720, 480);
  video = new Capture(this, 720, 480);
  mymovie = new Movie(this, "visage.mov");
  opencv.startBackgroundSubtraction(5, 3, 0.5);
  mymovie.loop();
}




////////////////////////////////////////////
////////////////////////////////// VOID DRAW
////////////////////////////////////////////


void draw() { 
  image(mymovie, 0, 0);
  image(video, 20, 20);
  //tint(150, 20);
  noFill();
  stroke(255, 0, 0);
  strokeWeight(1);



  // check if there is something new on the serial port
  while (myPort.available() &gt; 0) {
    // store the data in myString 
    myString = myPort.readStringUntil(lf);
    // check if we really have something
    if (myString != null) {
      myString = myString.trim(); // let's remove whitespace characters
      // if we have at least one character...
      if (myString.length() &gt; 0) {
        println(myString); // print out the data we just received
        // if we received a number (e.g. 123) store it in sensorValue, we sill use this to change the background color. 
        try {
          sensorValue = Integer.parseInt(myString);
        } 
        catch(Exception e) {
        }
      }
    }
  }
  if (x &lt; sensorValue) {
    video.start();
    opencv.loadImage(video);

  }

  if (x &gt; sensorValue) {
    image(mymovie, 0, 0);
  }

  opencv.updateBackground();
  opencv.dilate();
  opencv.erode();

  for (Contour contour : opencv.findContours()) {
    contour.draw();
  }

}




//////////////////////////////////////////////
////////////////////////////////// VOID CUSTOM
//////////////////////////////////////////////


void captureEvent(Capture video) {
  video.read(); // affiche l'image de la webcam
}

void movieEvent(Movie myMovie) {
  myMovie.read();
}
</code></pre>
]]></description>
   </item>
   </channel>
</rss>