I wrote a sketch to find the motion outlines using opencv. I then use the getPoints function to find the PVectors to use for placing particles. It works quite well but I'm worried about performance when I try to upscale this to hd video stream. I'm fairly new to Processing so can anyone tell me if there is a more efficient way of doing this? TIA My code (not including the Particle class but that just a simple class): ` import gab.opencv.*; import processing.video.*; import java.awt.*;
Capture video; OpenCV opencv; ArrayList contourPoints = new ArrayList (); ArrayList particles; PVector loc = new PVector (0,0);
void setup() { size(640, 480, P2D); video = new Capture(this, 640, 480); opencv = new OpenCV(this, 640, 480); particles = new ArrayList();
opencv.startBackgroundSubtraction(5, 3, 0.5);
video.start(); }
void draw() { background(255); opencv.loadImage(video);
opencv.updateBackground();
opencv.dilate(); opencv.erode();
for (Contour contour : opencv.findContours()) { contourPoints = contour.getPoints(); for (int i = 0; i < contourPoints.size()-10; i=i+10) { loc = contourPoints.get(i); particles.add(new Particle(new PVector(loc.x,loc.y))); } } // Looping through backwards to delete for (int i = particles.size()-1; i >= 0; i--) { Particle p = particles.get(i); p.run(); if (p.isDead()) { particles.remove(i); } } // println(frameRate); }
void captureEvent(Capture c) { c.read(); }`