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
Flashing webcam GSVideo problem (Read 724 times)
Flashing webcam GSVideo problem
Oct 2nd, 2009, 8:26pm
 
So, for the past few days this code was working just fine, how I wanted it to. But now the webcam flashes between no camera and the picture every second. I tested the webcam in Cheese on ubuntu and it works fine. This is my code

Code:
import codeanticode.gsvideo.*;
import processing.serial.*;
import processing.opengl.*;
GSCapture cam;
Serial behind;
PFont thefont;
PImage crosshair;
void setup() {
size(600, 400, OPENGL);
cam = new GSCapture(this, 352, 288);
thefont = loadFont("ArialNarrow-48.vlw");
crosshair = loadImage("crosshair.png");
textFont(thefont, 32);
println(Serial.list());
behind = new Serial(this, Serial.list()[0], 9600);
}
void draw() {
background(0);
if (cam.available()) {
cam.read();
image(cam,124,56);
image(crosshair, 275,175);
}else{
fill(0,255,0);
text("No Camera", 230, 200);
}
//Title
fill(0,255,0);
text("Airsoft Robot", 230, 45);

//Video Border
stroke(255);
line(122, 54, 478, 54);
line(122, 54, 122, 346);
line(478, 54, 478, 346);
line(122, 346, 478, 346);

//Behind Sensor
stroke(255);
line(122, 370, 478, 370);
line(122, 370, 122, 395);
line(122, 395, 478, 395);
line(478,395, 478, 370);

//Serial View
while (behind.available() > 0){
fill(255,0,0);
int behindread = behind.read();
rect(124, 372, 352, 21);
}
}
Re: Flashing webcam GSVideo problem
Reply #1 - Oct 8th, 2009, 2:17pm
 
If you put the background(0) after the line  

if (cam.available()) {

then the flickering disappears (because the camera is not available at every frame, so you should set the window to black only when a new video frame is available).
Page Index Toggle Pages: 1