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
drawing on video (Read 2364 times)
drawing on video
Apr 10th, 2006, 9:14pm
 
my original plan was to draw a simple black line as in the example ContinuousLines on top a video clip to get in the end a completely black screen. but it doesn't work the line is not really visible and it goes away. then i thought i could use an array as in the example StoringInput. there the circles are perfectly visible but they stay on the screen only the time of the iteration (of course!). does anyone has an idea on how to draw with the mouse something permanent on top of a video?
Re: drawing on video
Reply #1 - Apr 11th, 2006, 12:46am
 
I have a solution....

But you're not going to like it. It runs really slow on my machine (even with the 64bit gubbinz and opengl).

My idea is that you turn the capture into a mask(). Your background then becomes the line. You could speed up the drawing by masking the capture with a PGraphics3 instead of a PImage because you would be able to punch holes in it as opposed to drawing pixels one at a time.
Code:

import processing.video.*;
import processing.opengl.*; //speed this crap code up
Capture capture;
PGraphics3 masking; //make a PImage we can draw on

void setup(){
size(640, 480, OPENGL);
String s = "Creative WebCam Live! Pro-WDM";
capture = new Capture(this, s, width, height, 30);
masking = new PGraphics3(width, height, this);
masking.defaults(); //fix for PGraphics3
masking.background(255);
masking.fill(0);
}
void draw(){
background(0);
capture.updatePixels(); //fix for opengl
image(capture, 0, 0);
if(mousePressed){
masking.ellipse(mouseX, mouseY, 10, 10); // cut a hole
}
}
void captureEvent(Capture capture){
capture.read();
capture.mask(masking); // turn capture into paper we can cut holes in
}

But of course it runs bloody slow. You might be better off doing the StoringInput example with an array so big that no one notices the difference. On the upside, if you use the mask you could do some psychadelic drawing by doing a background(pimage) at the beginning of draw() instead of background(0).
Re: drawing on video
Reply #2 - Apr 11th, 2006, 1:16am
 
This is another solution.
You create a transparent canvas that you'll be using for drawing and then paint it on top of the main canvas.

The example uses a movie clip, because I don't have a webcam, but the changes should be easy.

Quote:


import processing.video.*;

// Variable for capture device or movie clip
Movie myMovie;

// The drawing canvas
PGraphics drawing;

void setup()
{
 size(200, 200, P3D);
 framerate(30);

 // Load and play the video in a loop
 myMovie = new Movie(this, "station.mov");
 myMovie.loop();
 noFill();
 
 // Create the drawing canvas
 drawing = createGraphics(width,height,P3D,null);
 drawing.defaults();
 
 // A temporary masking image that we set to black
 PGraphics drawingMask = createGraphics(width,height,P3D,null);
 drawingMask.defaults();
 drawingMask.background(0);
 
 // Make our canvas completely transparent
 drawing.mask(drawingMask);
 drawing.stroke(255);
}

void movieEvent(Movie myMovie)
{
 myMovie.read();
}

void draw()
{
 // Draw the video image on the background
 background(255);
 image(myMovie,0,0,width,height);
 
 // Draw the drawing canvas over the video
 image(drawing, 0 ,0);
 
}

void mouseDragged() {
 // Draw on the drawing canvas
 drawing.line(pmouseX,pmouseY,mouseX,mouseY);
}



hope it helps
Re: drawing on video
Reply #3 - Apr 11th, 2006, 10:44am
 
i don't know if you drink a lot of pastis (Ricard of course) but your idea is just great!!!!!!!
it works perfectly, it is exactly what i was looking for.
thanks so much......
Re: drawing on video
Reply #4 - Apr 11th, 2006, 10:57am
 
i still have a little problem: i cannot increase the width of the line, strokeWeight has no effect even if i write it drawing.strokeWeight. any idea?
Re: drawing on video
Reply #5 - Apr 12th, 2006, 2:51pm
 
read the reference for strokeWeight:
http://processing.org/reference/strokeWeight_.html
Re: drawing on video
Reply #6 - Apr 12th, 2006, 8:56pm
 
in other words, strokeWeight doesn't work with P3D or OpenGL, so try changing size(200,200,P3D) to size(200,200).
And to add smoothing, just type smooth(); after size()..
but beware, it _will_ run alot slower..

-seltar
Re: drawing on video
Reply #7 - Apr 12th, 2006, 11:10pm
 
The problem with dropping from P3D to JAVA2D renderer is that mask() cannot be used, and P2D is unimplemented.

Re: drawing on video
Reply #8 - Apr 15th, 2006, 8:40pm
 
if i draw ellipse() instead of line() i cannot use fill(), the only ellipse i get have a black perimeter and a white surface. is there some way to get them solid black?
Re: drawing on video
Reply #9 - Apr 15th, 2006, 9:17pm
 
What does the code look like?
Re: drawing on video
Reply #10 - Apr 16th, 2006, 1:58pm
 
import processing.video.*;

// Variable for capture device or movie clip
Movie myMovie;

// The drawing canvas
PGraphics drawing;

void setup()
{
 size(720, 576, P3D);
 framerate(30);

 // Load and play the video in a loop
 myMovie = new Movie(this, "lastjourney_lateral1.mov");
 myMovie.loop();
 //noFill();
 
 // Create the drawing canvas
 drawing = createGraphics(width,height,P3D,null);
 drawing.defaults();
 
 // A temporary masking image that we set to black
 PGraphics drawingMask = createGraphics(width,height,P3D,null);
 drawingMask.defaults();
 drawingMask.background(0);
 
 // Make our canvas completely transparent
 drawing.mask(drawingMask);
 //drawing.stroke(0);
 //drawing.strokeWeight(10);
 stroke(0);
 fill(0);
}

void movieEvent(Movie myMovie)
{
 myMovie.read();
}

void draw()
{
 // Draw the video image on the background
 background(255);
 image(myMovie,0,0,width,height);
 
 // Draw the drawing canvas over the video
 image(drawing, 0 ,0);
 
}

void mouseMoved() {
 // Draw on the drawing canvas

 drawing.ellipse(mouseX,mouseY,20,20);
}
Re: drawing on video
Reply #11 - Nov 13th, 2006, 5:17pm
 
ive made the changes to use a webcam to this code, and the stream comes up, but theres no drawing to be seen.  the code:

Code:


import processing.video.*;

// Variable for capture device or movie clip
Capture myCapture;

// The drawing canvas
PGraphics drawing;

void setup()
{
size(720, 576, P3D);


// Load and play the video in a loop
println(Capture.list());
String s = "";
myCapture = new Capture(this, s, width, height, 30);
//noFill();

// Create the drawing canvas
drawing = createGraphics(width,height,P3D,null);
drawing.defaults();

// A temporary masking image that we set to black
PGraphics drawingMask = createGraphics(width,height,P3D,null);
drawingMask.defaults();
drawingMask.background(0);

// Make our canvas completely transparent
drawing.mask(drawingMask);
//drawing.stroke(0);
//drawing.strokeWeight(10);
stroke(0);
fill(0);
}

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

void draw()
{
// Draw the video image on the background
background(255);
image(myCapture,0,0,width,height);

// Draw the drawing canvas over the video
image(drawing, 0 ,0);

}

void mouseMoved() {
// Draw on the drawing canvas

drawing.line(mouseX,mouseY,pmouseX,pmouseY);
}



thoughts?  im not tremendously familiar with processing and ive been troubleshooting this for almost a week to no avail.
thanks for your time.
Re: drawing on video
Reply #12 - Dec 17th, 2007, 8:13pm
 
I've just picked up on this topic and was wondering if anyone happened to find ou how to remove the stoke from this drawing tool. I'm working on a project where I can draw something totally white on a movie. Its a movie of bugs crawling and I wanted to erase them with the use of ReacTIvision as well. this code here is just my missing piece!!!  But I need to remove the stoke!! Help anyone?
Page Index Toggle Pages: 1