We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
Page Index Toggle Pages: 1
Draw on top of a captured video (Read 699 times)
Draw on top of a captured video
Oct 5th, 2007, 6:20pm
 
Hi,
I trying to write a script to draw on top of a caputured video. I'm totaly new in processing. Every help would be great.

Thanks
Felix

Thats how far I got

import processing.video.*;

Capture video;

int[] xHist;
int[] yHist;
int zahl=0;

void setup() {
 size(640, 480);
 video = new Capture(this, width, height, 30);
 smooth();
 stroke(0, 0, 0, 255);
 strokeWeight(8);
}

void draw() {
 // Draw if mouse is pressed
 if (mousePressed) {
   xHist[zahl]=pmouseX;
   yHist[zahl]=pmouseY;
   zahl++;
   if (zahl>2){
    for(int i=0; i<zahl-1; i++) {
         line(xHist[i], yHist[i], xHist[i+1], yHist[i+1]);
    }
   }
 }

if (video.available()) {
  video.read();
  image(video, 0, 0, width, height);
}
}
Re: Draw on top of a captured video
Reply #1 - Oct 6th, 2007, 4:41am
 
hi felix,

to draw on top of a video, simply draw the video first (image()), and then draw the things that should appear on top.  youre code raws the lines, and overpaints it with the video image, so no lines are visible.

Your history line code seems to be buggy though. Consider that an array [] has a fixed size. you must create a list like this befor you can access the list elements:
int[] histX = new int[4];
You could use mousePressed() and mouseReleased() events to hanlde the filling/reseting of your history arrays. Also have a look at expand() or append() which will let you enlarge the history arrays when needed.
here is a basic example of drawing over video.

Quote:


import processing.video.*;

Capture video;

void setup() {
 size(640, 480);  
 video = new Capture(this, width, height, 30);
 smooth();
 stroke(0, 0, 0, 255);
 strokeWeight(8);
}

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

 // image must come first, so it does not overpaint the stuff you draw.
 image(video, 0, 0, width, height);  

 // draw stuff on top
 for(int i=0; i<10; i++) {
   line(random(width), random(height), mouseX, mouseY);
 }
}



Page Index Toggle Pages: 1