Tips for improving program speed?
in
Contributed Library Questions
•
2 years ago
Hi, I would like to ask if anyone has any tips on how I could improve the speed of this program. The program is for a projection where viewers draw in front of the camera with colored objects and then the colors are projected onto a wall. If there is not movement or colors drawn by the viewers the image fades to white. It is working ok but just a little bit slow so I was wondering if anyone had any suggestions as to how I could improve the speed. Also, does playing the audio through the program slow it down a lot? or not really?
thanks very much.
import ddf.minim.*;
import ddf.minim.signals.*;
import ddf.minim.analysis.*;
import ddf.minim.effects.*;
import hypermedia.video.*;
OpenCV opencv;
PImage trailsImg;
float threshold = 80f;
Minim minim;
AudioPlayer player;
void setup() {
// size(512, 200, P3D);
// minim = new Minim(this);
// load a file, give the AudioPlayer buffers that are 2048 samples long
// player = minim.loadFile("soudofpaint.mp3", 2048);
// play the file
// player.shiftGain(0, 20, 2000);
// player.loop();
size( 800, 600 );
// open video stream
opencv = new OpenCV( this );
opencv.capture( 800, 600 );
trailsImg = new PImage (800, 600);
background(255);
}
void draw() {
opencv.read(); // grab frame from camera
//image( opencv.image(), 0, 0); // show the original image
PImage camImage;
opencv.absDiff();
filter(INVERT);
camImage = opencv.image();
opencv.blur (OpenCV.BLUR, 3 );
// colorMode(HSB);
trailsImg.blend( opencv.image(), 0, 0, 800, 600, 0, 0, 800, 600, SCREEN);
image( trailsImg, 0,0 ); // display the result
filter(INVERT);
opencv.copy (trailsImg);
opencv.blur (OpenCV.BLUR, 4 );
opencv.contrast (0);
opencv.brightness (-10);//how fast image fades, higher number fades faster
trailsImg = opencv.image();
opencv.remember(); // store the actual image in memory
}
void keyPressed() {
}
void stop()
{
// always close Minim audio classes when you are done with them
// player.close();
// always stop Minim before exiting
// minim.stop();
// super.stop();
}
1