Quantcast
Channel: Kinect - Processing 2.x and 3.x Forum
Viewing all articles
Browse latest Browse all 530

Old Processing 1.0 + OpenCV code...

$
0
0

Hey all,

I wrote this code back in 2011 (So long ago!) and am trying to resurrect it. Essentially it was a video grid that captured 10 frames and constantly looped them. I notice that the old OpenCV library doesn't seem to work anymore, and I can't seem to use it with the new library.

Any ideas?


import hypermedia.video.*;
OpenCV opencv;

int grid = 5; // grid dimensions
int numFrames = 10; // number of frames per loop
boolean randomGrid = false; // consecutive or random grid

PGraphics[] frames = new PGraphics[numFrames];
ArrayList randomNumbers = new ArrayList();
int t;

void setup() {
  size(640,480);
  opencv = new OpenCV(this);
  opencv.capture(width/grid,height/grid);
  for (int i=0; i<frames.length; i++) {
    frames[i] = createGraphics(width,height,P2D);
  }
  fillRandomNumbers();
}

void draw() {
  int currentFrame = frameCount % frames.length;
  opencv.read();
  if (frameCount % numFrames == 0) {
    if (randomGrid) { t = getRandomGrid(); }
    else { t++; }
  }
  int x = t%grid;
  int y = (t/grid)%grid;
  frames[currentFrame].beginDraw();
  frames[currentFrame].image(opencv.image(),x*width/grid,y*height/grid);
  frames[currentFrame].endDraw();
  image(frames[currentFrame],0,0);
}

int getRandomGrid() {
  if (randomNumbers.size() == 0) { fillRandomNumbers(); }
  int selected = int(random(randomNumbers.size()));
  int randomNumber = (Integer) randomNumbers.get(selected);
  randomNumbers.remove(selected);
  return randomNumber;
}

void fillRandomNumbers() {
  for (int i=0; i<grid*grid; i++) {
    randomNumbers.add(i);
  }
}

public void stop() {
  opencv.stop();
  super.stop();
}

Viewing all articles
Browse latest Browse all 530

Trending Articles