We are about to switch to a new forum software. Until then we have removed the registration on this forum.
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();
}
Answers
I am not sure why the OpenCV part is not working. Maybe you could check the documentation or more recent examples. I notice you are not doing any processing using OpenCV. I would replace all your OpenCV calls with a Capture object and it should work. For more information, go to the Processing Foundation's webapge and check the page libraries >> Video and any Capture entry. Or install the video library and then explore the capture examples provided.
Kf
Thanks @kfrajer!
I managed to turn it into all capture.. I have it working except when I want to change
cam = new Capture(this, width, height/grid);into
cam = new Capture(this, width/grid, height/grid);It is just displaying black??
full code:
Thanks @kfrajer!
I managed to turn it into all capture.. I have it working except when I want to change
cam = new Capture(this, width, height/grid);into
cam = new Capture(this, width/grid, height/grid);It is just displaying black??
full code:
@scttee -- if the sketch is doing this:
...then it resolves to:
This doesn't work on my laptop cam. However, these work:
I'm not sure, but I believe that
Capture()cannot specify an arbitrary requestWidth and requestHeight.Instead, these must be values from a list of frame modes supported by the camera -- and cameras often support values like 160,320,640 but seldom 213.
@scttee
Use this line
String[] cameras = Capture.list();to get access to the resolution available (and fps) for your cameras detected in your system. Just follow th example here:https://processing.org/reference/libraries/video/Capture.html
Kf