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.
IndexProgramming Questions & HelpSyntax Questions › update images every minute, but not the video !!!
Page Index Toggle Pages: 1
update images every minute, but not the video !!! (Read 714 times)
update images every minute, but not the video !!!
Jun 21st, 2007, 8:17pm
 
I made a code which display a live video in the letters of a text. It works fine.
I use "delay()" for changing the text every 5 minutes. But the "delay()" modify the live video and update the image every 5 minutes too.
How can I change the text every 5 minutes and continue to have a 25fps live video?
Thanks for your answers !

import processing.video.*;
Capture video;
PImage maskImg;
PImage img;
int num = 1;
int maxImages = 6;


void setup()
{
 size(720,576);
 video = new Capture (this, 750, 600, 30);
}


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


void draw()
{
 img = loadImage ("text"+num+".jpg");
//the text is a .jpg file. this image is a white text with a black background.

 maskImg = loadImage("texto"+num+".jpg");
// this image is the same text but it's black text with a white background.

 img.mask(maskImg);
 image(video, 0, 0);
//The live video is inserted in the letters.


 num++;
 if(num>maxImages){
   num = 1;
 }

 image(img, 0, 0);
 delay(1000*60*5);  
// the text and the video are updated every 5 minutes, but I want to have a 25 fps live video...  
}


Re: update images every minute, but not the video
Reply #1 - Jun 22nd, 2007, 12:14pm
 
float starttime = 0;
float waittime = 0;

void setup()
{
 starttime = millis() * 0.001;
 waittime = starttime;
}


void draw()
{
 // get elapsed time;
 waittime = (millis() * 0.001) - starttime;
 if( waittime > 5*60 )
 {
   //
   // change text image in here
   // and whatever u want to change every 5 minutes


   // reset counter
   starttime = millis() * 0.001;
   waitime -= starttime;
 }
}

that should do
Re: update images every minute, but not the video
Reply #2 - Jun 22nd, 2007, 12:19pm
 
The trick is to still keep running at a normal framerate and keep track of when the text had been updated last... see changes below:

Code:

import processing.video.*;

Capture video;
PImage maskImg;
PImage img;
int num = 1;
int maxImages = 6;

int fps = 25;
int textUpdateDelay = 5*60*1000; // every 5 mins
int lastUpdate;

void setup() {
size(720,576);
frameRate(fps);
video = new Capture (this, 750, 600, 30);
// force text to update at 1st frame
lastUpdate=millis()-textUpdateDelay;
}

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


void draw() {
// only update after the specified interval
if (millis()-lastUpdate>=textUpdateDelay) {
img = loadImage ("text"+num+".jpg");
maskImg = loadImage("texto"+num+".jpg");
img.mask(maskImg);
lastUpdate = millis();
num++;
if(num>maxImages){
num = 1;
}
}
image(video, 0, 0);
image(img, 0, 0);
}


hth!
Re: update images every minute, but not the video
Reply #3 - Jun 25th, 2007, 2:33am
 
Thank you !
Page Index Toggle Pages: 1